Rewritten OpenGL 2.1 engine's two-sided lighting
parent
32b480b226
commit
b6faadca03
|
@ -388,6 +388,8 @@ bool CGL21Device::Create()
|
|||
for (int i = 0; i < 8; i++)
|
||||
glUniform1i(uni_Light[i].Enabled, 0);
|
||||
|
||||
glEnable(GL_VERTEX_PROGRAM_TWO_SIDE);
|
||||
|
||||
// create default framebuffer object
|
||||
FramebufferParams framebufferParams;
|
||||
|
||||
|
|
|
@ -35,27 +35,36 @@ uniform vec4 uni_FogColor;
|
|||
uniform float uni_ShadowColor;
|
||||
|
||||
varying float pass_Distance;
|
||||
varying vec4 pass_Color;
|
||||
varying vec3 pass_Normal;
|
||||
varying vec2 pass_TexCoord0;
|
||||
varying vec2 pass_TexCoord1;
|
||||
varying vec3 pass_TexCoord2;
|
||||
|
||||
const vec3 const_LightDirection = vec3(1.0f, 2.0f, -1.0f);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = gl_Color;
|
||||
vec4 color = pass_Color;
|
||||
|
||||
if (uni_TextureEnabled[0])
|
||||
{
|
||||
color = color * texture2D(uni_PrimaryTexture, gl_TexCoord[0].st);
|
||||
color = color * texture2D(uni_PrimaryTexture, pass_TexCoord0);
|
||||
}
|
||||
|
||||
if (uni_TextureEnabled[1])
|
||||
{
|
||||
color = color * texture2D(uni_SecondaryTexture, gl_TexCoord[1].st);
|
||||
color = color * texture2D(uni_SecondaryTexture, pass_TexCoord1);
|
||||
}
|
||||
|
||||
if (uni_TextureEnabled[2])
|
||||
{
|
||||
if (gl_FrontFacing)
|
||||
color.rgb *= mix(uni_ShadowColor, 1.0f, shadow2D(uni_ShadowTexture, gl_TexCoord[2].xyz).x);
|
||||
else
|
||||
vec3 normal = pass_Normal * (2.0f * gl_Color.x - 1.0f);
|
||||
|
||||
if (dot(normal, const_LightDirection) < 0.0f)
|
||||
color.rgb *= uni_ShadowColor;
|
||||
else
|
||||
color.rgb *= mix(uni_ShadowColor, 1.0f, shadow2D(uni_ShadowTexture, pass_TexCoord2).x);
|
||||
}
|
||||
|
||||
if (uni_FogEnabled)
|
||||
|
|
|
@ -44,18 +44,21 @@ uniform bool uni_LightingEnabled;
|
|||
uniform LightParams uni_Light[8];
|
||||
|
||||
varying float pass_Distance;
|
||||
varying vec4 pass_Color;
|
||||
varying vec3 pass_Normal;
|
||||
varying vec2 pass_TexCoord0;
|
||||
varying vec2 pass_TexCoord1;
|
||||
varying vec3 pass_TexCoord2;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = uni_ModelMatrix * gl_Vertex;
|
||||
vec4 eyeSpace = uni_ViewMatrix * position;
|
||||
vec4 shadowCoord = uni_ShadowMatrix * position;
|
||||
gl_Position = uni_ProjectionMatrix * eyeSpace;
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_TexCoord[1] = gl_MultiTexCoord1;
|
||||
gl_TexCoord[2] = vec4(shadowCoord.xyz / shadowCoord.w, 1.0f);
|
||||
pass_Distance = abs(eyeSpace.z / eyeSpace.w);
|
||||
|
||||
vec4 color = gl_Color;
|
||||
|
||||
vec3 normal = normalize((uni_NormalMatrix * vec4(gl_Normal, 0.0f)).xyz);
|
||||
|
||||
if (uni_LightingEnabled)
|
||||
{
|
||||
|
@ -63,8 +66,6 @@ void main()
|
|||
vec4 diffuse = vec4(0.0f);
|
||||
vec4 specular = vec4(0.0f);
|
||||
|
||||
vec3 normal = normalize((uni_NormalMatrix * vec4(gl_Normal, 0.0f)).xyz);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (uni_Light[i].Enabled)
|
||||
|
@ -97,6 +98,17 @@ void main()
|
|||
+ uni_DiffuseColor * diffuse
|
||||
+ uni_SpecularColor * specular;
|
||||
|
||||
gl_FrontColor = vec4(min(vec3(1.0f), result.rgb), 1.0f);
|
||||
color = vec4(min(vec3(1.0f), result.rgb), 1.0f);
|
||||
}
|
||||
|
||||
gl_Position = uni_ProjectionMatrix * eyeSpace;
|
||||
gl_FrontColor = vec4(1.0f);
|
||||
gl_BackColor = vec4(0.0f);
|
||||
|
||||
pass_Distance = abs(eyeSpace.z / eyeSpace.w);
|
||||
pass_Color = color;
|
||||
pass_Normal = normal;
|
||||
pass_TexCoord0 = gl_MultiTexCoord0.st;
|
||||
pass_TexCoord1 = gl_MultiTexCoord1.st;
|
||||
pass_TexCoord2 = shadowCoord.xyz / shadowCoord.w;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue