• Advertisement
Sign in to follow this  

GLSL shader Specular Highlight problem

This topic is 4719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everyone! My problem is: (see image) http://www.gamedev.ru/images/show.php?id=3709 The highlight has to be in the place where blue arrow points, but it appears in the place, where the red arrow is. I thought that problem might be linear interpolation of Half Angle vector across the vertices causing the problem, but I made HL vector to be calculated per fragment, and that didn't help. Who knows, what the problem can be? spot_bump.vert attribute vec3 tangent, binormal; varying vec3 v_HalfAngleTan, v_Light, v_LightTan, v_EyeTan; void main() { gl_Position = gl_ModelViewMatrix*gl_Vertex; gl_TexCoord[0] = gl_MultiTexCoord0; // diffuse map coord gl_TexCoord[1] = gl_MultiTexCoord0; // normal map coord gl_TexCoord[3] = gl_TextureMatrix[0] * gl_Position; // light spot tex coord vec4 l_pos = gl_LightSource[0].position; vec3 v_Normal = normalize(gl_NormalMatrix*gl_Normal); // normal to eye space vec3 v_Tangent = normalize(gl_NormalMatrix*tangent); // tangent to eye space vec3 v_Binormal = normalize(gl_NormalMatrix*binormal); // binormal to eye space mat3 tangent_bas = mat3( // in column major order v_Tangent.x, v_Binormal.x, v_Normal.x, v_Tangent.y, v_Binormal.y, v_Normal.y, v_Tangent.z, v_Binormal.z, v_Normal.z); v_EyeTan = normalize(tangent_bas * -vec3(gl_Position)); v_Light = l_pos.xyz - gl_Position.xyz; v_LightTan = tangent_bas * v_Light; v_HalfAngleTan = (normalize(v_LightTan) + v_EyeTan) * 0.5; gl_Position = gl_ProjectionMatrix * gl_Position; } spot_bump.frag uniform sampler2D tex_unit_0; uniform sampler2D tex_unit_1; uniform sampler2D tex_unit_3; varying vec3 v_HalfAngleTan, v_Light, v_LightTan; #define LIGHT gl_LightSource[0] void main() { vec3 light_diff = gl_LightSource[0].diffuse.xyz; float len = length(v_Light); vec3 a_coeff = vec3(LIGHT.constantAttenuation, LIGHT.linearAttenuation, LIGHT.quadraticAttenuation); float atten = 1.0/(a_coeff[0]+a_coeff[1]*len + a_coeff[2] *len*len); vec3 v_Light_n = normalize(v_LightTan); vec4 diffuse = texture2D(tex_unit_0, gl_TexCoord[0].xy); vec4 _normal = texture2D(tex_unit_1, gl_TexCoord[1].xy); vec3 normal = normalize(vec3(_normal*2.0 - 1.0)); // unpacking normal bool lit = v_LightTan.z > 0.0; vec2 intens = vec2( dot(normal, v_Light_n), dot(normalize(v_HalfAngleTan), normal) ); intens = float(lit) * max(vec2(0,0), intens); intens[1]=0.6 * pow(intens[1], 100.0); intens = atten * intens; // LIGHT SPOT COLOR vec3 spot_color = vec3(0,0,0); vec3 tex_coord = gl_TexCoord[3].xyz / gl_TexCoord[3].w; vec2 temp = abs(tex_coord.xy); if(temp.x < 1.0 && temp.y <1.0 && gl_TexCoord[3].w > 0.0) { vec2 tex_coord_2D = tex_coord.xy * 0.5 + vec2(0.5); spot_color = texture2D(tex_unit_3, tex_coord_2D ).rgb; } spot_color.rgb *= light_diff; gl_FragColor = vec4(vec3(spot_color)*vec3(intens[0]*vec3(diffuse)+intens[1]) + // DIFFUSE + SPECULAR vec3(diffuse) * 0.2 // ABMIENT ,1.0); }

Share this post


Link to post
Share on other sites
Advertisement
Thanks, Dan. I looked at these articles, but I didn't find anything new there. The code above seems to implement all the stuff mentioned in articles. I don't know what the problem is.

You're right, the highlight looks good in this way either, but I want it to be correct.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement