Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualShawn619

Posted 23 April 2013 - 08:26 PM

My shader program is clearly not computing vectors correctly, because I get these results:

 

NO Shader(fixed-function):

2d27zfn.jpg

 

Shader

2eeii9x.jpg

 

This is a plain diffuse shader that is supposed to create a green diffuse on the object:

.vert

 

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec3 vertex_normal;

varying vec4 color;

varying vec3 N;

varying vec3 v;
 void main(void)

   {

      v = vec3(gl_ModelViewMatrix * gl_Vertex);

      N = normalize(gl_NormalMatrix * gl_Normal);
      color = gl_Color;

      vertex_normal = normalize(gl_NormalMatrix * gl_Normal);

      vertex_light_position = normalize(gl_LightSource[0].position.xyz);

      vertex_light_half_vector = normalize(gl_LightSource[0].halfVector.xyz);

     

      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

   }

 

.frag

 

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec3 vertex_normal;

varying vec4 color;

varying vec3 N;

varying vec3 v;
void main()

{ 

   vec3 L = normalize(gl_LightSource[0].position.xyz - v);

   vec3 E = normalize(-v);

   vec3 R = normalize(reflect(-L,N));

  

   vec4 diffuse_color = vec4(0.0,1.0,0.0,0.0);

   float diffuse_value = max(dot(vertex_normal, vertex_light_position), 0.0);
   if (gl_FrontFacing){

       gl_FragColor = color + ((diffuse_color-color) * (diffuse_value));

   }else{

       gl_FragColor = color;

   }
}

 

Im confused, because I get the correct effect on my shader designer:

zwj6h0.jpg


#1Shawn619

Posted 23 April 2013 - 08:24 PM

My program is clearly not computing vectors correctly, because I get these results:

 

NO Shader(fixed-function):

2d27zfn.jpg

 

Shader

2eeii9x.jpg

 

This is a plain diffuse shader that is supposed to create a green diffuse on the object:

.vert

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec3 vertex_normal;

varying vec4 color;

varying vec3 N;

varying vec3 v;
 void main(void)

   {

      v = vec3(gl_ModelViewMatrix * gl_Vertex);

      N = normalize(gl_NormalMatrix * gl_Normal);
      color = gl_Color;

      vertex_normal = normalize(gl_NormalMatrix * gl_Normal);

      vertex_light_position = normalize(gl_LightSource[0].position.xyz);

      vertex_light_half_vector = normalize(gl_LightSource[0].halfVector.xyz);

     

      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

   }

 

.frag

varying vec3 vertex_light_position;

varying vec3 vertex_light_half_vector;

varying vec3 vertex_normal;

varying vec4 color;

varying vec3 N;

varying vec3 v;
void main()

{ 

   vec3 L = normalize(gl_LightSource[0].position.xyz - v);

   vec3 E = normalize(-v);

   vec3 R = normalize(reflect(-L,N));

  

   vec4 diffuse_color = vec4(0.0,1.0,0.0,0.0);

   float diffuse_value = max(dot(vertex_normal, vertex_light_position), 0.0);
   if (gl_FrontFacing){

       gl_FragColor = color + ((diffuse_color-color) * (diffuse_value));

   }else{

       gl_FragColor = color;

   }
}

 

Im confused, because I get the correct effect on my shader designer:

zwj6h0.jpg


PARTNERS