Sign in to follow this  

Vertex Lighting problem

Recommended Posts

Hi ,Can somebody solve this problem please !


this my vertex shader code :

precision mediump float;attribute vec3 aVertexPosition;attribute vec3 aVertexNormal;attribute vec2 aTextureCoord;uniform mat4 GLTS_VIEW;uniform mat4 GLTS_PROJECTION;uniform mat3 GLTS_NORMAL;uniform mat4 GLTS_WORLD;varying vec2 vTextureCoord;varying vec3 vTransformedNormal;varying vec4 vPosition;///********************struct LIGHT{	vec3 position;	vec3 ambient;	vec3 diffuse;	float range;};uniform LIGHT lightengine[8];varying vec3 lightIntensity;void main(){	vPosition = (GLTS_VIEW * vec4(aVertexPosition, 1.0));	vTransformedNormal = normalize(GLTS_NORMAL * aVertexNormal);	vTextureCoord = aTextureCoord;	gl_Position =  GLTS_PROJECTION * GLTS_VIEW * GLTS_WORLD* vec4(aVertexPosition, 1.0);		for(int i = 0; i < 2; i++)	{		vec3 lightDirection             = normalize(lightengine[i] -;		float directionalLightWeighting = max(dot(vTransformedNormal, lightDirection), 0.0);				float dist = distance(, lightengine[i].position);//length( - lightengine[i].position);		if(dist < lightengine[i].range)		{			lightIntensity     += lightengine[i].ambient + lightengine[i].diffuse * directionalLightWeighting;						}	}}

and this is my fragment shader :

precision mediump float; varying vec3 lightIntensity;varying vec2 vTextureCoord;uniform sampler2D uSampler; void main(){	vec4 fragmentColor;	fragmentColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));		gl_FragColor = vec4(fragmentColor.rgb * lightIntensity, 1.0);}

the problem is the light work only when it move close to world center (0,0,0).




a you can see in image the light work for all models from just position (0,0,0)





Edited by Hodgman
restored deleted post

Share this post

Link to post
Share on other sites

Why? Because no one had nothing better to do on a Sunday night than to keep checking for new posts and telling you within two hours that you have to transform your light coordinates into view space or something? Is this forum some kind of emergency debugging service? Consider restoring your question so others with the same problem may find it and the solution.

Share this post

Link to post
Share on other sites

Haha yes , there is a question in directx forum , 20 days with no answer for simple thing that i figure out myself.
Im not talking about you or someone but what i think this forum haven't active threads like before.

and you re right , the light must transform into vew space . thanks

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this