Commit f5e0c822 authored by Dario Seyb's avatar Dario Seyb

improved shader pipeline flexibility

parent dee8acff
#version 410 core
in vec3 teNormal;
in vec2 teTexCoord;
in vec3 tePosition;
#if LAST_SHADER == VERTEX
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vPosition;
#endif
#if LAST_SHADER == TESSELATION
in vec3 teNormal;
in vec2 teTexCoord;
in vec3 tePosition;
#endif
#if LAST_SHADER == GEOMETRY
in vec3 gNormal;
in vec2 gTexCoord;
in vec3 gPosition;
in vec3 gPatchDistance;
in vec3 gTriDistance;
#endif
uniform sampler2D uTexture;
......@@ -35,25 +51,50 @@ float rand(vec2 co){
vec4 color();
vec4 emissive();
vec3 normal();
vec4 specularSmoothness();
vec3 inNormal;
vec2 inTexCoord;
vec3 inPosition;
vec3 inPatchDistance;
vec3 inTriDistance;
void main()
{
#if LAST_SHADER == VERTEX
inNormal = vNormal;
inTexCoord = vTexCoord;
inPosition =vPosition;
#endif
#if LAST_SHADER == TESSELATION
inNormal = teNormal;
inTexCoord = teTexCoord;
inPosition = tePosition;
#endif
#if LAST_SHADER == GEOMETRY
inNormal = gNormal;
inTexCoord = gTexCoord;
inPosition = gPosition;
inPatchDistance = gPatchDistance;
inTriDistance = gTriDistance;
#endif
vec4 color = color();
float sampl = rand(gl_FragCoord.xy + vec2(mod(uTime,1)));
if(sampl > color.a) discard;
vec4 thisPosition = uViewProjectionMatrix * vec4(tePosition, 1);
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * inverse(uModelMatrix) * vec4(tePosition, 1);
vec4 thisPosition = uViewProjectionMatrix * vec4(inPosition, 1);
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * inverse(uModelMatrix) * vec4(inPosition, 1);
vec3 prevFragCoord = prevPosition.xyz/prevPosition.w;
vec3 thisFragCoord = thisPosition.xyz/thisPosition.w;
vec4 specularSmoothness = vec4(0.5);
if(uHasSpecularSmoothnessMap) {
specularSmoothness = texture(uSpecularSmoothnessMap, teTexCoord);
}
vec4 specularSmoothness = specularSmoothness();
oMotion = (thisFragCoord-prevFragCoord)*0.5;
oMotion.z = thisPosition.z;
......
......@@ -17,6 +17,8 @@ uniform mat4 uLightProjMatrix;
uniform bool uLightIsDirectional;
uniform vec3 uLightDir;
uniform float uOneOverLightCount;
uniform float uNear;
uniform float uFar;
......@@ -100,5 +102,5 @@ void main()
float lightNdotL = max(0, dot(lightDir, normal));
vec4 lighting = BRDF (albedo.rgb, specularSmoothness.rgb, oneMinusReflectivity, specularSmoothness.a, normal, viewDir, lightDir, lightNdotL, uLightColor.rgb * uLightColor.a);
oColor = vec4(lighting.rgb + emissive.rgb, 1);
oColor = vec4(lighting.rgb + emissive.rgb, albedo.a * uOneOverLightCount);
}
#version 410 core
#define LAST_SHADER GEOMETRY
in vec3 gNormal;
in vec2 gTexCoord;
in vec3 gPosition;
in vec3 gPatchDistance;
in vec3 gTriDistance;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uPrevModelMatrix;
uniform mat4 uPrevViewProjectionMatrix;
out vec4 oColor;
out vec4 oEmissive;
out vec3 oNormal;
out vec3 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
#pragma import "CommonDeferredFrag.glsl"
#pragma import "Utils.glsl"
float amplify(float d, float scale, float offset){
d = scale * d + offset;
......@@ -34,10 +10,10 @@ float amplify(float d, float scale, float offset){
return d;
}
vec4 color() {
vec4 color = texture(uTexture, gTexCoord).rgba * uTintColor;
color.rgb *= 0.2;
return color;
float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
color = amplify(d1, 80, -0.5) * amplify(d2, 120, -0.5) * color;
......@@ -53,23 +29,6 @@ vec3 normal() {
return gNormal;
}
void main()
{
vec4 color = color();
float sampl = rand(gl_FragCoord.xy + vec2(mod(uTime,1)));
if(sampl > color.a) discard;
vec4 thisPosition = uViewProjectionMatrix * vec4(gPosition, 1);
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * inverse(uModelMatrix) * vec4(gPosition, 1);
vec3 prevFragCoord = prevPosition.xyz/prevPosition.w;
vec3 thisFragCoord = thisPosition.xyz/thisPosition.w;
oMotion = (thisFragCoord-prevFragCoord)*0.5;
oMotion.z = thisPosition.z;
oColor = color;
oEmissive = emissive();
oNormal = normalize(normal());
}
\ No newline at end of file
vec4 specularSmoothness() {
return vec4(0.2, 0.2, 0.2, 0.5);
}
#define LAST_SHADER TESSELATION
#pragma import "CommonDeferredFrag.glsl"
#pragma import "Utils.glsl"
......@@ -29,3 +31,10 @@ vec3 normal() {
}
return teNormal;
}
vec4 specularSmoothness() {
if(uHasSpecularSmoothnessMap) {
return texture(uSpecularSmoothnessMap, inTexCoord);
}
return vec4(0, 0, 0, 0);
}
#version 410 core
in vec3 gNormal;
in vec2 gTexCoord;
in vec3 gPosition;
in vec3 gPatchDistance;
in vec3 gTriDistance;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uPrevModelMatrix;
uniform mat4 uPrevViewProjectionMatrix;
out vec4 oColor;
out vec4 oEmissive;
out vec3 oNormal;
out vec3 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float amplify(float d, float scale, float offset){
d = scale * d + offset;
d = clamp(d, 0, 1);
d = 1 - exp2(-2*d*d);
return d;
}
#define LAST_SHADER GEOMETRY
#pragma import "CommonDeferredFrag.glsl"
#pragma import "Utils.glsl"
vec4 color() {
vec4 color = texture(uTexture, gTexCoord).rgba * uTintColor;
float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
color = amplify(d1, 80, -0.5) * amplify(d2, 120, -0.5) * color;
color.w = 1.0;
return color;
return texture(uTexture, teTexCoord).rgba * uTintColor;
}
vec4 emissive() {
......@@ -53,23 +15,6 @@ vec3 normal() {
return gNormal;
}
void main()
{
vec4 color = color();
float sampl = rand(gl_FragCoord.xy + vec2(mod(uTime,1)));
if(sampl > color.a) discard;
vec4 thisPosition = uViewProjectionMatrix * vec4(gPosition, 1);
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * inverse(uModelMatrix) * vec4(gPosition, 1);
vec3 prevFragCoord = prevPosition.xyz/prevPosition.w;
vec3 thisFragCoord = thisPosition.xyz/thisPosition.w;
oMotion = (thisFragCoord-prevFragCoord)*0.5;
oMotion.z = thisPosition.z;
oColor = color;
oEmissive = emissive();
oNormal = normalize(normal());
}
\ No newline at end of file
vec4 specularSmoothness() {
return vec4(0.4, 0.4, 0.8, 0.85);
}
#define LAST_SHADER TESSELATION
#pragma import "CommonDeferredFrag.glsl"
vec4 color() {
......@@ -10,4 +12,8 @@ vec4 emissive() {
vec3 normal() {
return teNormal;
}
\ No newline at end of file
}
vec4 specularSmoothness() {
return vec4(0, 0, 0, 0);
}
......@@ -439,6 +439,8 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
m_deferredCombineProgram->setUniform("uNear", cam->near);
m_deferredCombineProgram->setUniform("uFar", cam->far);
m_deferredCombineProgram->setUniform("uOneOverLightCount", 1.0f/pass.submittedLights.size());
m_deferredCombineProgram->setUniform("cameraPosition",
glm::vec3{ camPos.x, camPos.y, camPos.z });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment