1
0
Fork 0

HDR: Use gl_VertexID instead of the MVP matrix in fullscreen passes

This commit is contained in:
Fernando García Liñán 2021-08-31 18:00:36 +02:00
parent 68997879d3
commit 3459e7ddfe
19 changed files with 80 additions and 73 deletions

View file

@ -1301,7 +1301,7 @@
</pass>
<pass include="debug-pass.xml">
<name>debug-depth</name>
<effect>Effects/HDR/visualize-depth</effect>
<effect>Effects/HDR/gbuffer-debug-depth</effect>
<geometry>
<left>0.8</left>
<bottom>0.8</bottom>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/adapt-luminance.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/adapt-luminance.frag</fragment-shader>
</program>
<uniform>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/adapt-luminance.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/copy-prev-luminance.frag</fragment-shader>
</program>
<uniform>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-color.frag</fragment-shader>
</program>
<uniform>

View file

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/HDR/visualize-depth</name>
<name>Effects/HDR/gbuffer-debug-depth</name>
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/visualize-depth.frag</fragment-shader>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-depth.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
</program>
<uniform>
<name>tex</name>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-matid.frag</fragment-shader>
</program>
<uniform>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-normal.frag</fragment-shader>
</program>
<uniform>

View file

@ -4,7 +4,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-orm.frag</fragment-shader>
</program>
<uniform>

View file

@ -89,4 +89,20 @@
</program>
</pass>
</technique>
<technique n="119">
<scheme>hdr-shadow</scheme>
<pass>
<color-mask type="vec4d">0 0 0 0</color-mask>
<cull-face>back</cull-face>
<blend>0</blend>
<polygon-offset>
<factor>1.1</factor>
<units>4.0</units>
</polygon-offset>
<program>
<vertex-shader>Shaders/HDR/geometry-shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-shadow.frag</fragment-shader>
</program>
</pass>
</technique>
</PropertyList>

View file

@ -1,8 +1,5 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec3 cubemapCoord0;
out vec3 cubemapCoord1;
out vec3 cubemapCoord2;
@ -10,20 +7,18 @@ out vec3 cubemapCoord3;
out vec3 cubemapCoord4;
out vec3 cubemapCoord5;
uniform mat4 osg_ModelViewProjectionMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
vec2 texCoord = multiTexCoord0.xy * 2.0 - 1.0;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0);
// Map the quad texture coordinates to a direction vector to sample
// the cubemap. This assumes that we are using the weird left-handed
// orientations given by the OpenGL spec.
// See https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation
cubemapCoord0 = vec3(1.0, -texCoord.y, -texCoord.x);
cubemapCoord1 = vec3(-1.0, -texCoord.y, texCoord.x);
cubemapCoord2 = vec3(texCoord.x, 1.0, texCoord.y);
cubemapCoord3 = vec3(texCoord.x, -1.0, -texCoord.y);
cubemapCoord4 = vec3(texCoord.x, -texCoord.y, 1.0);
cubemapCoord5 = vec3(-texCoord.x, -texCoord.y, -1.0);
cubemapCoord0 = vec3(1.0, -pos.y, -pos.x);
cubemapCoord1 = vec3(-1.0, -pos.y, pos.x);
cubemapCoord2 = vec3(pos.x, 1.0, pos.y);
cubemapCoord3 = vec3(pos.x, -1.0, -pos.y);
cubemapCoord4 = vec3(pos.x, -pos.y, 1.0);
cubemapCoord5 = vec3(-pos.x, -pos.y, -1.0);
}

View file

@ -1,22 +1,20 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
out vec4 posPos;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform sampler2D color_tex;
const float FXAA_SUBPIX_SHIFT = 1.0/4.0;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
vec2 rcpFrame = 1.0 / textureSize(color_tex, 0);
posPos.xy = multiTexCoord0.xy;
posPos.zw = multiTexCoord0.xy - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT));
posPos.xy = texCoord;
posPos.zw = texCoord - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT));
gl_Position = vec4(pos, 0.0, 1.0);
}

View file

@ -0,0 +1,15 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D depth_tex;
float linearizeDepth(float depth);
void main()
{
float depth = texture(depth_tex, texCoord).r;
fragColor = vec4(vec3(linearizeDepth(depth)), 1.0);
}

View file

@ -39,23 +39,19 @@
#define mad(a, b, c) (a * b + c)
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
out vec2 pixCoord;
out vec4 vOffset[3];
uniform mat4 osg_ModelViewProjectionMatrix;
uniform vec4 fg_Viewport;
#define SMAA_RT_METRICS vec4(1.0 / fg_Viewport.z, 1.0 / fg_Viewport.w, fg_Viewport.z, fg_Viewport.w)
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
gl_Position = vec4(pos, 0.0, 1.0);
pixCoord = texCoord * SMAA_RT_METRICS.zw;

View file

@ -37,21 +37,18 @@
#define mad(a, b, c) (a * b + c)
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
out vec4 vOffset[3];
uniform mat4 osg_ModelViewProjectionMatrix;
uniform vec4 fg_Viewport;
#define SMAA_RT_METRICS vec4(1.0 / fg_Viewport.z, 1.0 / fg_Viewport.w, fg_Viewport.z, fg_Viewport.w)
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
gl_Position = vec4(pos, 0.0, 1.0);
vOffset[0] = mad(SMAA_RT_METRICS.xyxy, vec4(-1.0, 0.0, 0.0, -1.0), texCoord.xyxy);
vOffset[1] = mad(SMAA_RT_METRICS.xyxy, vec4( 1.0, 0.0, 0.0, 1.0), texCoord.xyxy);

View file

@ -37,21 +37,18 @@
#define mad(a, b, c) (a * b + c)
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
out vec4 vOffset;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform vec4 fg_Viewport;
#define SMAA_RT_METRICS vec4(1.0 / fg_Viewport.z, 1.0 / fg_Viewport.w, fg_Viewport.z, fg_Viewport.w)
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
gl_Position = vec4(pos, 0.0, 1.0);
vOffset = mad(SMAA_RT_METRICS.xyxy, vec4(1.0, 0.0, 0.0, 1.0), texCoord.xyxy);
}

View file

@ -0,0 +1,7 @@
#version 330 core
void main()
{
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0);
}

View file

@ -1,10 +1,14 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
uniform mat4 osg_ModelViewProjectionMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
}

View file

@ -1,14 +1,10 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 3) in vec4 multiTexCoord0;
out vec2 texCoord;
uniform mat4 osg_ModelViewProjectionMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
gl_Position = vec4(pos, 0.0, 1.0);
}

View file

@ -1,14 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D tex;
float linearizeDepth(float depth);
void main()
{
fragColor = vec4(linearizeDepth(texture(tex, texCoord).r));
}