Page 1 of 1

[solved] Self-defined material doesn't work

Posted: Fri Nov 07, 2014 10:10 am
by shapeare2014
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.

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

Posted: Fri Nov 07, 2014 3:01 pm
by spacegaier
Did you check in the Ogre.log to see if there were some issues (e. g. compilation errors) with your shaders?

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

Posted: Mon Nov 10, 2014 8:25 am
by shapeare2014
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.

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

Posted: Mon Nov 10, 2014 11:23 am
by Kojack
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.

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

Posted: Wed Nov 12, 2014 7:49 am
by shapeare2014
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.