[solved] Self-defined material doesn't work

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
shapeare2014
Gnoblar
Posts: 7
Joined: Thu Oct 09, 2014 8:26 am

[solved] Self-defined material doesn't work

Post by shapeare2014 » Fri Nov 07, 2014 10:10 am

I followed Ogre's render to texture tutorial and was able to render the scene to a rectangle at the corner. After that, I would like to test my understanding of Ogre's shader material, so I decided to create a material myself, and then do the texture lookup operation within the fragment shader.

IncreateScene(), my material setup code looks like;

Code: Select all

    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("mytest");
    material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    mMiniScreen->setMaterial("mytest");
and then I wrote the following code as mytest.material:

Code: Select all


fragment_program testFragmentProgram glsl
{
	source test.frag
}


material mytest
 {
    technique
    {
       pass
        {
	      fragment_program_ref testFragmentProgram{
		    param_named tex int 0
          }
	      texture_unit {
		    texture BeachStones.jpg 2d
	      }
       }   
    }
 }
and the following code in test.frag:

Code: Select all

varying vec2 texCoord;

uniform sampler2D tex;

void main(){
	gl_FragColor = texture2D(tex, texCoord);
}
However, the result is a blinking rectangle at the corner;
Image

I used a texture that comes with Ogre, named BeachStones.jpg.

The log doesn't show any errors regarding finding the image.
Last edited by shapeare2014 on Mon Nov 10, 2014 8:17 am, edited 1 time in total.
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: GLSL shader doesn't work(Ogre RTT tutorial)

Post by spacegaier » Fri Nov 07, 2014 3:01 pm

Did you check in the Ogre.log to see if there were some issues (e. g. compilation errors) with your shaders?
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

shapeare2014
Gnoblar
Posts: 7
Joined: Thu Oct 09, 2014 8:26 am

Re: GLSL shader doesn't work(Ogre RTT tutorial)

Post by shapeare2014 » Mon Nov 10, 2014 8:25 am

spacegaier wrote:Did you check in the Ogre.log to see if there were some issues (e. g. compilation errors) with your shaders?
Yes, I did find some helpful information in the log. Now I corrected them and also simplified my problem to make it clear.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: Self-defined material doesn't work (question updated!)

Post by Kojack » Mon Nov 10, 2014 11:23 am

There can be issues with mixing fixed function and shaders in one material. I don't know about glsl, but with hlsl and cg it will probably break (especially on AMD gpus) if you have a material with a fragment shader but no vertex shader.
0 x

shapeare2014
Gnoblar
Posts: 7
Joined: Thu Oct 09, 2014 8:26 am

Re: Self-defined material doesn't work (question updated!)

Post by shapeare2014 » Wed Nov 12, 2014 7:49 am

Kojack wrote:There can be issues with mixing fixed function and shaders in one material. I don't know about glsl, but with hlsl and cg it will probably break (especially on AMD gpus) if you have a material with a fragment shader but no vertex shader.
I added a vertex shader and added the texture coordinate declaration:

Code: Select all

attribute vec4 uv0;
in the vertex shader, and then pass it to the fragment shader where the texture lookup is carried out. Now my program works! Thanks for the help.
0 x

Post Reply