Working shadows, however ugly they are.
This commit is contained in:
@@ -5,6 +5,7 @@ uniform float Gamma;
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D LightingTexture;
|
||||
layout (binding=2) uniform sampler2D ShadowTexture;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
@@ -18,7 +19,11 @@ void main()
|
||||
{
|
||||
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
|
||||
|
||||
|
||||
vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
|
||||
FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
||||
//FragmentColor = ShadowTexel;
|
||||
|
||||
}
|
||||
@@ -1,22 +1,36 @@
|
||||
#version 430
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D ShadowTexture;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec4 ShadowCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
out vec4 frag_Position;
|
||||
out vec4 frag_Normal;
|
||||
|
||||
float Shadow(vec4 ShadowCoord)
|
||||
{
|
||||
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z )
|
||||
{
|
||||
return 0.3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Diffuse Texture
|
||||
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord);
|
||||
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord);
|
||||
|
||||
// G-buffer Position
|
||||
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
@@ -23,8 +23,6 @@ const vec3 kd = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 ka = vec3(1.0, 1.0, 1.0);
|
||||
const float kshine = 1.0;
|
||||
|
||||
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
@@ -73,7 +71,6 @@ vec4 phong(vec3 position, vec3 normal)
|
||||
//float alpha = dist / radius;
|
||||
//float dampingFactor = 1.0 - pow(alpha, 3);
|
||||
|
||||
|
||||
return vec4((Id + Is) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 DepthMVP;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
@@ -14,6 +15,7 @@ out VertexData
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec4 ShadowCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
@@ -23,4 +25,5 @@ void main()
|
||||
Output.Position = vec3(V * M * vec4(Position, 1.0));
|
||||
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ uniform mat4 MVP;
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 2) in vec2 TextureCoord;
|
||||
|
||||
uniform mat4 depthBiasMVP;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
@@ -16,4 +18,5 @@ void main()
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = (vec2(Position) + 1.0) / 2.0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user