i guess it is working
This commit is contained in:
parent
4cce33c16b
commit
2a804556db
7 changed files with 165 additions and 50 deletions
|
|
@ -1,20 +1,52 @@
|
|||
#version 110
|
||||
|
||||
uniform sampler2DShadow depth_texture;
|
||||
varying vec4 shadow;
|
||||
varying vec4 color;
|
||||
uniform float solid_color;
|
||||
varying vec4 vPos;
|
||||
varying vec3 vNrm;
|
||||
varying vec4 vShadowCoord;
|
||||
|
||||
uniform sampler2D depth_texture;
|
||||
uniform sampler2D current_texture;
|
||||
|
||||
void main (void){
|
||||
vec4 c;
|
||||
vec4 PhongShading(void)
|
||||
{
|
||||
vec3 N = normalize(vNrm);
|
||||
vec3 L = normalize(gl_LightSource[0].position.xyz-vPos.xyz);
|
||||
|
||||
if(solid_color > 0.5){
|
||||
c = color;
|
||||
}else{
|
||||
c = texture2D(current_texture, gl_TexCoord[0].st);
|
||||
}
|
||||
c = color;
|
||||
vec4 ambient = gl_FrontLightProduct[0].ambient;
|
||||
|
||||
gl_FragColor = (shadow + (gl_Color - shadow) * shadow2DProj(depth_texture, gl_TexCoord[1])) * c;
|
||||
float dcoef = max(dot(L, N), 0.0);
|
||||
vec4 diffuse = gl_FrontLightProduct[0].diffuse*dcoef;
|
||||
|
||||
vec4 specular = vec4(0.0);
|
||||
if(dcoef > 0.0){
|
||||
vec3 V = normalize(-vPos.xyz);
|
||||
|
||||
vec3 R = reflect(-L, N);
|
||||
float specularLight = pow(max(dot(R, V), 0.0), gl_FrontMaterial.shininess);
|
||||
|
||||
specular = gl_FrontLightProduct[0].specular*specularLight;
|
||||
}
|
||||
return ambient+diffuse+specular;
|
||||
}
|
||||
|
||||
float ShadowCoef(void){
|
||||
vec4 shadow_coord = vShadowCoord / vShadowCoord.w;
|
||||
float view = shadow_coord.z;
|
||||
float light = texture2D(depth_texture, shadow_coord.xy).z;
|
||||
float shadow_coef = 1.0;
|
||||
|
||||
if(vShadowCoord.w > 0.0){
|
||||
shadow_coef = light < view ? 0.0 : 1.0;
|
||||
}
|
||||
|
||||
return shadow_coef;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 c = gl_Color;
|
||||
vec4 ambient = gl_LightSource[0].ambient;
|
||||
float shadow_coef = ShadowCoef();
|
||||
|
||||
gl_FragColor = ambient * shadow_coef * c + (1.0 - ambient) * c;
|
||||
gl_FragColor.a = 1.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,15 @@
|
|||
#version 110
|
||||
|
||||
varying vec4 shadow;
|
||||
varying vec4 color;
|
||||
varying vec4 vPos;
|
||||
varying vec3 vNrm;
|
||||
varying vec4 vShadowCoord;
|
||||
|
||||
void main(void){
|
||||
vec3 position = vec3(gl_ModelViewMatrix * gl_Vertex);
|
||||
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
|
||||
vec3 light = normalize(gl_LightSource[0].position.xyz - position);
|
||||
float diffuse = dot(light, normal);
|
||||
vPos = gl_ModelViewMatrix * gl_Vertex;
|
||||
vNrm = normalize(gl_NormalMatrix * gl_Normal);
|
||||
vShadowCoord = gl_TextureMatrix[7] * gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
color = gl_Color;
|
||||
|
||||
gl_FrontColor = gl_LightSource[0].ambient;
|
||||
shadow = gl_FrontColor;
|
||||
if (diffuse > 0.0){
|
||||
vec3 view = normalize(position);
|
||||
vec3 halfway = normalize(light - view);
|
||||
float specular = pow(max(dot(normal, halfway), 0.0), gl_FrontMaterial.shininess);
|
||||
vec4 temp = gl_LightSource[0].diffuse * diffuse;
|
||||
shadow += temp * 0.2;
|
||||
gl_FrontColor += temp + gl_FrontLightProduct[0].specular * specular;
|
||||
}
|
||||
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_ModelViewMatrix * gl_Vertex;
|
||||
gl_Position = ftransform();
|
||||
gl_Position = gl_ProjectionMatrix * vPos;
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_TexCoord[0] * gl_MultiTexCoord0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue