-1
\$\begingroup\$

I'm trying to learn the basic of shaders following basic tutorials in Ogre.

I use GLSL ES 2.0 #version 100

I think I have a basic concept problem. I'm trying to render a model + texture without make modifications to be sure that is working, and then start with modifications.

I have the following material:

fragment_program Basic_ps_glsles glsles
{
    source Basic_ps.glsles
    profiles glsles

    default_params
    {
        param_named tex0 int 0
    }
}

vertex_program Basic_vs_glsles glsles
{
    source Basic_vs.glsles
    profiles glsles

    default_params
    {       
        param_named_auto mvp_matrix viewproj_matrix 
    }
}



material Penguin
{
    technique
    {
        pass
        {
            ambient 0.5 0.5 0.5
            diffuse 0.5 0.5 0.5

            fragment_program_ref Basic_ps_glsles glsles
            {
            }

            vertex_program_ref Basic_vs_glsles glsles
            {
            }

            texture_unit
            {
                texture penguin.jpg
                tex_coord_set 0
            }

        }
    }
}

And I apply the next Vertex shader:

#version 100 

//http://www.widget-101.com/opengl/curso-basico-opengl/opengl-glsl/

precision mediump int;
precision mediump float;

attribute vec4 position;        
attribute vec4 vertex;
attribute vec4 multiTexCoord0;

uniform mat4 mvp_matrix;
uniform mat4 texture_matrix;    

varying vec4 frag_color;
varying vec2 texCoord;          


void main()                    
{
    gl_Position = mvp_matrix*position;
    vec4 transformed_tex_coord = mvp_matrix * multiTexCoord0;   
    texCoord = transformed_tex_coord.st;
}

And then the next Fragment Shader:

#version 100


precision mediump int;
precision mediump float;

uniform sampler2D tex0;

varying vec4 frag_color;
varying vec2 texCoord;

void main()
{
    vec4 color = texture2D(tex0,texCoord);
    gl_FragColor = color;   //vec4(0.0, 1.0, 0.0, 1.0); // frag_color;
}

But The texture is not applied to the pinguin. It appear totally black. I think is a problem with the texture coordinates. What I doing wrong with the texture coordinates?

\$\endgroup\$
  • \$\begingroup\$ There could be two resons. 1 : your texture input is not valid, thus making the texture black. 2 : calculating uv cordinates is not done via multiplying them with model_view_projectionMatrix. you should only pass them on. beacuse they are alredy in the correct space. \$\endgroup\$ – Tordin May 14 '13 at 8:13
  • \$\begingroup\$ 1º The texture works fine if I don't use the shaders. 2º Is then the viewproj_matrix the problem calculating the uv coordinates in my case? How I must calculate the coordinates? \$\endgroup\$ – vgonisanz May 14 '13 at 8:27
  • \$\begingroup\$ often you calculate them like this : vec4 transformed_tex_coord = multiTexCoord0; You dont transform them at all. they are only a value between 0 and 1. 0 beeing the right corner and 1 beeing the left. or viseversa depending on devices. \$\endgroup\$ – Tordin May 14 '13 at 12:06
0
\$\begingroup\$

The problem is the texture coordinates. Ogre store the data in attribute vec4 uv0; So in the vertex shader:

gl_Position = mvp_matrix*position;
texCoord = uv0.st;

Solve the problem

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.