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].position.xyz - vPosition.xyz); float directionalLightWeighting = max(dot(vTransformedNormal, lightDirection), 0.0); float dist = distance(vPosition.xyz, lightengine[i].position);//length(vPosition.xyz - 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).
[attachment=31631:lightproblem.jpg]
a you can see in image the light work for all models from just position (0,0,0)
[attachment=31632:lightproblem.jpg]
Thanks