Setting up a simple GLSL shader

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Setting up a simple GLSL shader

Post by hinashah »

Hello,

I know this is basic, but I have tried several code examples from the forum, and can't figure out what I am doing wrong. I have a skeletal mesh on which I want to apply a custom material handled by glsl. Right now I am trying a very basic glsl program to make sure that everything is okay, but all I get is a black mesh! What am i doing wrong?

My graphics card has opengl 4.4, graphics card: GeForce GTX 745 (If that matters). Here are my code snippets:

XRay.vert:

Code: Select all

#version 400
/* Vertex Shader */
uniform mat4 worldViewProjMatrix;
in vec4 vertex;

void main()
{
   gl_Position    = worldViewProjMatrix *vertex;
}

XRay,frag:

Code: Select all

#version 400
/* Fragment Shader */
 
out vec4 pPixel;
 
void main()
{  
    pPixel = vec4(1.0,0.0,1.0,1.0);
}

XRay.material:

Code: Select all

vertex_program XRayVertexProgram glsl
{
	source XRay.vert
}


fragment_program XRayFragmentProgram glsl
{
	source XRay.frag
}

// This is a comment
material XRay
{
    // first, preferred technique
    technique
    {
        // first pass
        pass
        {
		  lighting on	
		  ambient 0.5 0.3 0.5 1.0
			
		  vertex_program_ref XRayVertexProgram
		  {
			param_named_auto worldViewProjMatrix    worldviewproj_matrix
		  }
		  	
		  fragment_program_ref  XRayFragmentProgram
		  {
			
		  }
		  
        }
    }	
}	

All that I get from the log file is this:

Code: Select all

 GLSL compiling: XRayVertexProgram
15:52:59: GLSL compiled: 
15:52:59: Vertex Program:XRayVertexProgram GLSL link result : 
15:52:59: Font SdkTrays/Caption using texture size 512x256
What is wrong here?

Thanks!
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Setting up a simple GLSL shader

Post by areay »

That looks OK to me. Can you paste in the place in your log where your mesh is created and the material is applied? Also, does the model have it's vertices in the right place?
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Setting up a simple GLSL shader

Post by tod »

You don't return any values from your shaders, so the shaders do nothing I think.
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Re: Setting up a simple GLSL shader

Post by hinashah »

This is all that I have in the log file related to loading the mesh and it's skeleton, and creating the material.
(There were a bunch of missing .jpg images in the default material present in the original mesh, but it is not relevant here)

Code: Select all

Mesh: Loading SkeletonOrient.ma.mesh.
Skeleton: Loading SkeletonOrient.ma.skeleton
WARNING: the mesh 'SkeletonOrient.ma.mesh' includes vertices without bone assignments. Those vertices will transform to wrong position when skeletal animation enabled. To eliminate this, assign at least one bone assignment per vertex on your mesh.
GLSL compiling: XRayVertexProgram
GLSL compiled: 
Vertex Program:XRayVertexProgram GLSL link result :
And yes, the vertices are in the correct position. I was already applying a diffuse material on the mesh. Actually I also have a floor added to the scene. So I can actually see a black mesh in the overlapped region.

Thanks!
Syniurge
Halfling
Posts: 40
Joined: Thu Aug 30, 2012 1:43 pm
Location: France
x 3

Re: Setting up a simple GLSL shader

Post by Syniurge »

Have you tried the GL3+ render system yet?
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Re: Setting up a simple GLSL shader

Post by hinashah »

Is this something different than the Render system that the standard GL Rendering use?
Syniurge
Halfling
Posts: 40
Joined: Thu Aug 30, 2012 1:43 pm
Location: France
x 3

Re: Setting up a simple GLSL shader

Post by Syniurge »

Yes, there are two GL rendersystem plugins: the standard one for GL2 and another experimental one for GL3.x and onwards.

Afaik GLSL 1.50 although introduced by OpenGL 3.3 works with the GL2 plugin but that may not be the case for GLSL 4.x. And from a quick glance at the code of the render systems the parts related to GLSL are pretty different from one plugin to another, so the GL3+ plugin should be worth a try.
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Re: Setting up a simple GLSL shader

Post by hinashah »

I see. Do you know how to set up GL3+ render system with Ogre?

Thanks!
Hina
Syniurge
Halfling
Posts: 40
Joined: Thu Aug 30, 2012 1:43 pm
Location: France
x 3

Re: Setting up a simple GLSL shader

Post by Syniurge »

Do:

Code: Select all

Ogre::Root::getSingletonPtr()->setRenderSystem("OpenGL 3+ Rendering Subsystem (EXPERIMENTAL)");
before calling Ogre::Root::initialize()
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Re: Setting up a simple GLSL shader

Post by hinashah »

Nope, that does not work. I have Ogre1.9, VS2012 prebuilt binaries. Is this something that comes with the source code checkout of Ogre?
Syniurge
Halfling
Posts: 40
Joined: Thu Aug 30, 2012 1:43 pm
Location: France
x 3

Re: Setting up a simple GLSL shader

Post by Syniurge »

Check if you have RenderSystem_GL3Plus.dll in the lib dir of OGRE (I'm on Linux so not sure where the plugins are located).

And yes that comes with the source code of OGRE 1.9 but the render system isn't built by default, so maybe it's not in the SDK binaries.
hinashah
Gnoblar
Posts: 14
Joined: Fri Jul 18, 2014 9:31 pm

Re: Setting up a simple GLSL shader

Post by hinashah »

So the problem was that I was also setting a Shadow technique in the scene manager, which was working against the shader (how?). But the basic shader is now working.

Thanks everyone!
Post Reply