Defucked defucked rendering

This commit is contained in:
2014-05-07 22:34:38 +02:00
parent b1b60bce61
commit 62ca923821
13 changed files with 207 additions and 113 deletions
+22
View File
@@ -0,0 +1,22 @@
#version 430
uniform vec3 La;
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D LightingTexture;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 FragmentColor;
void main()
{
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
}
+16
View File
@@ -0,0 +1,16 @@
#version 430
layout(location = 0) in vec3 Position;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1) / 2;
}
+1 -1
View File
@@ -19,7 +19,7 @@ void main()
frag_Diffuse = texture2D(DiffuseTexture, Input.TextureCoord);
// G-buffer Position
frag_Position = vec4(Input.Position.xy, 0.0, 0.0);
frag_Position = vec4(Input.Position.xyz, 0.0);
// G-buffer Normal
frag_Normal = vec4(Input.Normal, 0.0);
+1 -1
View File
@@ -30,7 +30,7 @@ void main()
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
DrawQuadrant(texture2D(DiffuseTexture, Input.TextureCoord * 2), vec2(-1, 1));
DrawQuadrant(texture2D(PositionTexture, Input.TextureCoord * 2), vec2(1, 1));
DrawQuadrant((texture2D(NormalTexture, Input.TextureCoord * 2)+1)/2, vec2(-1, -1));
DrawQuadrant(texture2D(NormalTexture, Input.TextureCoord * 2), vec2(-1, -1));
vec4 AllTexel = texture2D(DiffuseTexture, Input.TextureCoord*2)*texture2D(PositionTexture, Input.TextureCoord*2)*texture2D(NormalTexture, Input.TextureCoord*2);
DrawQuadrant(AllTexel, vec2(1, -1));
+46 -60
View File
@@ -1,94 +1,80 @@
#version 430
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D PositionTexture;
layout (binding=2) uniform sampler2D NormalTexture;
layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture;
uniform vec2 ViewportSize;
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 la;
uniform vec3 ls;
uniform vec3 ld;
uniform vec3 lp;
const float specularExponent = 20.0;
uniform vec3 lp;
uniform float LightRadius;
const float specularExponent = 50.0;
uniform vec3 CameraPosition;
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 ks = vec3(1.0, 0.0, 0.0);
const vec3 kd = vec3(0.8, 0.8, 0.8);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
in VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Input;
out vec4 FragColor;
vec3 phong (vec3 PositionTexel, vec3 NormalTexel)
vec4 phong4(vec3 position, vec3 normal)
{
vec3 lightPosition = vec3( M * vec4( lp, 1.0 ) );
vec3 distToLight = lightPosition - PositionTexel;
vec3 directionToLight = normalize(distToLight);
// Diffuse
vec3 lightPos = vec3(V * vec4(lp, 1.0));
vec3 distanceToLight = lightPos - position;
vec3 directionToLight = normalize(distanceToLight);
float dotProd = dot(directionToLight, normal);
dotProd = max(dotProd, 0.0);
vec3 Id = kd * ld * dotProd;
//Diffuse light
float dotProdDiffuse = max(dot(directionToLight, NormalTexel), 0.0);
vec3 Id = ld * kd * dotProdDiffuse; //Final diffuse intensity
//Specular light
vec3 reflection = reflect(-directionToLight, NormalTexel);
vec3 surfaceToCamera = normalize(PositionTexel);
vec3 HalfWay = normalize(surfaceToCamera + directionToLight);
float dotProdSpecular = dot(HalfWay, NormalTexel);
dotProdSpecular = max(dotProdSpecular, 0.0);
float specularFactor = pow(dotProdSpecular, specularExponent);
vec3 Is = ls * ks * specularFactor; //Final specular intensity
// Specular
//vec3 reflection = reflect(-directionToLight, normal);
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactor = pow(dotSpecular, specularExponent * 2);
vec3 Is = ks * ls * specularFactor;
//Attenuation
float dist2D = distance(lightPosition, PositionTexel);
float attenuationFactor = -log(min(1.0, dist2D / 5.0));
float dist = distance(lightPos, position);
float attenuation = -log(min(1.0, dist / LightRadius));
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
//vec3 FinalOut = (Id + Is) * attenuationFactor;
vec3 FinalOut = Id + Is;
return FinalOut;
}
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
//float att_s = 5;
//float attenuation = pow(dist, 2) / pow(5.0, 2);
//attenuation = 1.0 / (1.0 + attenuation * att_s);
//att_s = 1.0 / (1.0 + att_s);
//attenuation = attenuation / (1.0 - att_s);
float radius = 5.0;
float alpha = dist / radius;
float dampingFactor = 1.0 - pow(alpha, 3);
vec3 phong2 (vec3 PositionTexel, vec3 NormalTexel)
{
vec3 LightVector = lp - PositionTexel;
vec3 ViewVector = normalize(PositionTexel);
//diffuse
vec3 Id = max(0.0, dot(LightVector, NormalTexel)) * ld;
vec3 FinalOut = Id;
return FinalOut;
}
vec3 phong3 (vec3 PositionTexel, vec3 NormalTexel)
{
vec3 lightDir = lp - PositionTexel;
lightDir = normalize(lightDir);
vec3 eyeDir = normalize(CameraPosition-PositionTexel);
vec3 vHalfVector = normalize(lightDir.xyz+eyeDir);
vec3 Id = max(0.0, dot(NormalTexel, lightDir)) * ld;
vec3 Is = pow(max(0.0, dot(NormalTexel, vHalfVector)), 100.0) * ls;
vec3 FinalFrag = Id + Is;
return FinalFrag;
return vec4((Id + Is) * attenuation, 1.0);
}
void main()
{
vec4 DiffuseTexel = texture2D(DiffuseTexture, Input.TextureCoord);
vec4 PositionTexel = texture2D(PositionTexture, Input.TextureCoord);
vec4 NormalTexel = texture2D(NormalTexture, Input.TextureCoord);
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 Frag_color;
Frag_color.rgb = phong((MVP * PositionTexel).rgb, normalize(NormalTexel).rgb);
Frag_color.a = 1.0;
FragColor = Frag_color * DiffuseTexel;
FragColor = phong4(vec3(PositionTexel), vec3(NormalTexel));
}
+5 -3
View File
@@ -1,7 +1,9 @@
#version 430
uniform mat4 MVP;
uniform mat4 ModelMatrix;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
@@ -18,7 +20,7 @@ void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = gl_Position.xyz;
Output.Normal = normalize((ModelMatrix * vec4(Normal, 0.0)).xyz);
Output.Position = vec3(V * M * vec4(Position, 1.0));
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
Output.TextureCoord = TextureCoord;
}
+4 -4
View File
@@ -1,10 +1,10 @@
#version 430
uniform mat4 MVP;
layout (location = 0) in vec3 Position;
layout (location = 2) in vec2 TextureCoord;
out VertexData
{
vec3 Position;
@@ -13,7 +13,7 @@ out VertexData
void main()
{
gl_Position = vec4(Position, 1.0);
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = TextureCoord;
Output.TextureCoord = (vec2(Position) + 1) / 2;
}