Jump to content
  • Advertisement
Sign in to follow this  

are these shaders correct?

This topic is 4372 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

Hey, Just trying to apply per pixel lighting on a textured sphere. This is what I'm doing: Vertex Shader
#version 110

varying vec3 lightDir,normal, viewVec;
void main()
	vec3 ecPos = vec3(gl_ModelViewMatrix * gl_Vertex);
	viewVec = vec3(normalize(-ecPos));

	normal = normalize(gl_NormalMatrix * gl_Normal);
	lightDir = normalize(vec3(gl_LightSource[0].position));
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();

Fragment Shader
#version 110

varying vec3 lightDir,normal, viewVec;
uniform sampler2D tex;

void main()
	vec3 ct,cf;
	vec4 texel;
	float intensity,at,af;
	vec3 nnormal = normalize(normal);
	intensity = max(dot(lightDir, nnormal),0.0);
	float specValue = clamp(dot(reflect(-normalize(lightDir), nnormal), normalize(viewVec)), 0.0, 1.0);
	specValue = pow(specValue, 6.0);
	cf = intensity * (gl_FrontMaterial.diffuse).rgb + 
					  (gl_FrontMaterial.ambient.rgb*0.5) + specValue;
	af = gl_FrontMaterial.diffuse.a;
	texel = texture2D(tex,gl_TexCoord[0].st);
	ct = texel.rgb;
	at = texel.a;
	gl_FragColor = vec4(ct * cf, at * af);	

this is what I get: are te shaders correct? I think the result is the expected for this kind of lighting, no? Huge thanks

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!