I have tried to use the face normal but the result is very bad all the faces are culled.
here is how i use it
#version 100
precision highp int;
precision highp float;
attribute vec4 vertex;
attribute vec3 normal;
uniform mat4 normalMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelView;
uniform vec3 camera_world_position;
varying vec3 ec_pos;
varying vec3 camPos;
void main()
{
gl_Position = modelViewProjectionMatrix * vertex;
vec3 norm = normal;
//norm *=-1.0;
ec_pos = vec3(gl_Position.x, gl_Position.y, gl_Position.z);
camPos = camera_world_position;
//lightDiffuse = dot(normalize(vec3(norm.x, norm.y, norm.z)), normalize(camera_world_position - vec3(gl_Position.x, gl_Position.y, gl_Position.z)));
#version 100
precision highp int;
precision highp float;
uniform float time;
uniform float touchX;
uniform float touchY;
uniform float touchZ;
uniform float line;
varying vec3 ec_pos;
varying vec3 camPos;
void main()
{
vec3 ec_normal = normalize(cross(dFdx(ec_pos), dFdy(ec_pos)));
float lightDiffuse = dot( ec_normal, normalize(camPos));
float rampLight =lightDiffuse;
float light = (1.0 - rampLight) * 1.0;
vec4 lightColor = vec4(1.0,1.0,1.0, 1.0);
vec4 diffuseColor = lightColor * light;
if(rampLight <0.0)
{
discard;
}
diffuseColor = smoothstep(vec4(0.0, 0.0, 0.0, 0.0), vec4(0.7, 0.7, 0.7, 0.7), vec4(diffuseColor));
gl_FragColor = diffuseColor;
}
}
Game Programming is the process of converting dead pictures to live ones .