Deferred rendering base mostly complete.
This commit is contained in:
@@ -1,4 +1,27 @@
|
||||
#version 400
|
||||
#version 130
|
||||
uniform sampler2D firstTexture;
|
||||
in vec3 fragmentNormal;
|
||||
in vec2 fragmentTexCoord;
|
||||
in vec3 position;
|
||||
layout (location = 0) out vec4 diffuseOutput;
|
||||
layout (location = 1) out vec4 posOutput;
|
||||
layout (location = 2) out vec4 normOutput;
|
||||
layout (location = 3) out vec4 blendOutput;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
posOutput.xyz = position;
|
||||
normOutPut = vec4(fragmentNormal, 0);
|
||||
vec4 clr = texture(firstTexture, fragmentTexCoord);
|
||||
float alpha = clr.a;
|
||||
if(alpha < 0.1)
|
||||
discard; //Some optimizing
|
||||
blendOutput.rgb = clr.rgb * clr.a; //Pre multiplied alpha
|
||||
blendOutput.a = clr.a;
|
||||
diffuseOutput = clr;
|
||||
}
|
||||
|
||||
/*#version 400
|
||||
|
||||
in vec3 p_eye;
|
||||
in vec3 n_eye;
|
||||
@@ -9,4 +32,4 @@ layout (location = 1) out vec4 def_n; // "go to GL_COLOR_ATTACHMENT1"
|
||||
void main () {
|
||||
def_p = vec4(p_eye, 1.0);
|
||||
def_n = vec4(n_eye, 1.0);
|
||||
}
|
||||
}*/
|
||||
@@ -1,4 +1,34 @@
|
||||
#version 400
|
||||
#version 130
|
||||
|
||||
precision mediump float;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
|
||||
in vec3 normal;
|
||||
in vec2 texCoord;
|
||||
in vec3 vertex;
|
||||
|
||||
in float intensity;
|
||||
in float ambientLight;
|
||||
|
||||
out vec3 fragmentNormal;
|
||||
out vec2 fragmentTexCoord;
|
||||
out float extIntensity;
|
||||
out float extAmbientLight;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
fragmentTexCoord = texCoord;
|
||||
fragmentNormal = normalize((modelMatrix*vec4(normal, 0.0).xyz);
|
||||
gl_Position = vec3(modelMatrix * vertex); //Copy position to the fragment shader
|
||||
extIntensity = intensity/255.0;
|
||||
extAmbientLight = ambientLight/255.0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*#version 400
|
||||
|
||||
layout(location = 0) in vec3 vp;
|
||||
layout(location = 1) in vec3 vn;
|
||||
@@ -13,4 +43,4 @@ void main () {
|
||||
p_eye = (V * M * vec4 (vp, 1.0)).xyz;
|
||||
n_eye = (V * M * vec4 (vn, 0.0)).xyz;
|
||||
gl_Position = P * vec4 (p_eye, 1.0);
|
||||
}
|
||||
}*/
|
||||
@@ -1,24 +1,32 @@
|
||||
#version 430
|
||||
#version 130
|
||||
|
||||
uniform sampler2D tDiffuse;
|
||||
uniform sampler2D tPosition;
|
||||
uniform sampler2D tNormals;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform sampler2D diffuseTex; // The color information
|
||||
uniform sampler2D posTex; // World position
|
||||
uniform sampler2D normalTex; // Normals
|
||||
uniform sampler2D blendTex; // A bitmap with colors to blend with.
|
||||
uniform vec3 camera; // The coordinate of the camera
|
||||
in vec2 position; // The world position
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
|
||||
void main( void )
|
||||
void main(void)
|
||||
{
|
||||
vec4 image = texture2D( tDiffuse, gl_TexCoord[0].xy );
|
||||
vec4 position = texture2D( tPosition, gl_TexCoord[0].xy );
|
||||
vec4 normal = texture2D( tNormals, gl_TexCoord[0].xy );
|
||||
|
||||
vec3 light = vec3(50,100,50);
|
||||
vec3 lightDir = light - position.xyz ;
|
||||
|
||||
normal = normalize(normal);
|
||||
lightDir = normalize(lightDir);
|
||||
|
||||
vec3 eyeDir = normalize(cameraPosition-position.xyz);
|
||||
vec3 vHalfVector = normalize(lightDir.xyz+eyeDir);
|
||||
|
||||
gl_FragColor = max(dot(normal,lightDir),0) * image + pow(max(dot(normal,vHalfVector),0.0), 100) * 1.5;
|
||||
}
|
||||
// Load data, stored in textures, from the first stage rendering.
|
||||
vec4 diffuse = texture2D(diffuseTex, position.xy);
|
||||
vec4 blend = texture2D(blendTex, position.xy);
|
||||
vec4 worldPos = texture2D(posTex, position.xy);
|
||||
vec4 normal = texture2D(normalTex, position.xy);
|
||||
// Use information about lamp coordinate (not shown here), the pixel
|
||||
// coordinate (worldpos.xyz), the normal of this pixel (normal.xyz)
|
||||
// to compute a lighting effect.
|
||||
// Use this lighting effect to update 'diffuse'
|
||||
vec4 preBlend = diffuse * lamp + specularGlare;
|
||||
// manual blending, using premultiplied alpha.
|
||||
fragColor = blend + preBlend*(1-blend.a);
|
||||
// Some debug features. Enable any of them to get a visual representation
|
||||
// of an internal buffer.
|
||||
// fragColor = (normal+1)/2;
|
||||
// fragColor = diffuse;
|
||||
// fragColor = blend;
|
||||
// fragColor = worldPos; // Scaling may be needed to range [0,1]
|
||||
// fragColor = lamp*vec4(1,1,1,1);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#version 430
|
||||
#version 130
|
||||
in vec4 vertex; out vec2 position;
|
||||
|
||||
void main( void )
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
gl_Position = vertex*2-1;
|
||||
gl_Position.z = 0.0;
|
||||
position = vertex.xy;
|
||||
}
|
||||
Reference in New Issue
Block a user