Moved ViewSpacePosition calculation from fragmenst shader to vertexshader
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec4 Color;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoordinate;
|
||||
vec4 DiffuseColor;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 PVM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -23,6 +24,7 @@ uniform float ColorDistanceScalar;
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -34,6 +36,7 @@ in VertexData{
|
||||
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -101,6 +104,7 @@ void PassThingsThrough(int index)
|
||||
// pass through vertex data
|
||||
Output.Normal = Input[index].Normal;
|
||||
Output.Position = Input[index].Position;
|
||||
Output.ViewSpacePosition = Input[index].ViewSpacePosition;
|
||||
Output.TextureCoordinate = Input[index].TextureCoordinate;
|
||||
Output.Tangent = Input[index].Tangent;
|
||||
Output.BiTangent = Input[index].BiTangent;
|
||||
@@ -175,7 +179,7 @@ void main()
|
||||
}
|
||||
|
||||
// convert to window space
|
||||
gl_Position = P * V * M * vec4(ExplodedPosition, 1.0);
|
||||
gl_Position = PVM * vec4(ExplodedPosition, 1.0);
|
||||
EmitVertex();
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 VM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -65,6 +63,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -302,11 +301,10 @@ void main()
|
||||
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
|
||||
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
|
||||
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec4 viewVec = normalize(-Input.ViewSpacePosition);
|
||||
vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition);
|
||||
vec3 R = reflect(-I, Input.Normal);
|
||||
//R = vec3(P * vec4(R, 1.0));
|
||||
@@ -333,7 +331,7 @@ void main()
|
||||
LightResult light_result;
|
||||
//These if statements should be removed.
|
||||
if(light.Type == 1) { // point
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
|
||||
} else if (light.Type == 2) { //Directional
|
||||
int DepthMapIndex = getShadowIndex(FarDistance);
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#version 430
|
||||
uniform mat4 PVM;
|
||||
uniform mat4 VM;
|
||||
#define MAX_SPLITS 4
|
||||
uniform mat4 TIM;
|
||||
|
||||
@@ -17,6 +18,7 @@ layout(location = 4) in vec2 TextureCoords;
|
||||
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -31,6 +33,7 @@ void main()
|
||||
gl_Position = PVM * vec4(Position, 1.0);
|
||||
//mat4 TIM = transpose(inverse(M));
|
||||
Output.Position = Position;
|
||||
Output.ViewSpacePosition = VM * vec4(Position, 1.0);
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
Output.Normal = vec3(TIM * vec4(Normal, 0.0));
|
||||
Output.Tangent = vec3(TIM * vec4(Tangent, 0.0));
|
||||
|
||||
@@ -65,6 +65,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -141,11 +142,10 @@ void main()
|
||||
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
|
||||
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
|
||||
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec4 viewVec = normalize(-Input.ViewSpacePosition);
|
||||
vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition);
|
||||
vec3 R = reflect(-I, Input.Normal);
|
||||
//R = vec3(P * vec4(R, 1.0));
|
||||
@@ -170,7 +170,7 @@ void main()
|
||||
LightResult light_result;
|
||||
//These if statements should be removed.
|
||||
if(light.Type == 1) { // point
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
|
||||
} else if (light.Type == 2) { //Directional
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 PVM;
|
||||
uniform mat4 VM;
|
||||
uniform mat4 TIM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
@@ -21,6 +22,7 @@ layout(location = 6) in vec4 BoneWeights;
|
||||
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -44,6 +46,7 @@ void main()
|
||||
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.ViewSpacePosition = VM * vec4(Position, 1.0);
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
Output.Normal = vec3(M * boneTransform * vec4(Normal, 0.0));
|
||||
Output.Tangent = vec3(M * vec4(Tangent, 0.0));
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 VM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -82,6 +80,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -362,13 +361,12 @@ void main()
|
||||
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
|
||||
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
|
||||
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
|
||||
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
|
||||
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec4 viewVec = normalize(-Input.ViewSpacePosition);
|
||||
|
||||
vec2 tilePos;
|
||||
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
|
||||
@@ -391,7 +389,7 @@ void main()
|
||||
LightResult light_result;
|
||||
//These if statements should be removed.
|
||||
if(light.Type == 1) { // point
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
|
||||
} else if (light.Type == 2) { //Directional
|
||||
int DepthMapIndex = getShadowIndex(FarDistance);
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 VM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -80,6 +78,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec4 ViewSpacePosition;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
@@ -193,13 +192,12 @@ void main()
|
||||
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
|
||||
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
|
||||
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
|
||||
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
|
||||
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec4 viewVec = normalize(-Input.ViewSpacePosition);
|
||||
|
||||
vec2 tilePos;
|
||||
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
|
||||
@@ -220,7 +218,7 @@ void main()
|
||||
LightResult light_result;
|
||||
//These if statements should be removed.
|
||||
if(light.Type == 1) { // point
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
|
||||
} else if (light.Type == 2) { //Directional
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
}
|
||||
|
||||
@@ -1324,11 +1324,6 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
|
||||
if (lastShader != m_FillDepthStencilBufferSkinnedProgram->GetHandle()) {
|
||||
m_FillDepthStencilBufferSkinnedProgram->Bind();
|
||||
lastShader = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
|
||||
glUniform1i(glGetUniformLocation(shaderSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2f(glGetUniformLocation(shaderSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glUniform4fv(glGetUniformLocation(shaderSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind Uniforms 1");
|
||||
}
|
||||
|
||||
@@ -1347,11 +1342,6 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
|
||||
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
|
||||
m_FillDepthStencilBufferProgram->Bind();
|
||||
lastShader = m_FillDepthStencilBufferProgram->GetHandle();
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind Uniforms 2");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user