Improved Deferred Shading performances
Former-commit-id: 7251e9f552230c31409f7780929fcc30f2b85bed
This commit is contained in:
parent
9bf66e7e16
commit
b9dca8966d
|
|
@ -24,7 +24,7 @@ namespace
|
|||
"out vec4 RenderTarget0;\n"
|
||||
|
||||
"uniform sampler2D ColorTexture;\n"
|
||||
"uniform sampler2D NormalBuffer;\n"
|
||||
"uniform sampler2D GBuffer2;\n"
|
||||
"uniform mat4 InvViewProjMatrix;\n"
|
||||
"uniform vec2 InvTargetSize;\n"
|
||||
"uniform vec3 EyePosition;\n"
|
||||
|
|
@ -32,12 +32,18 @@ namespace
|
|||
"float n = 0.1;"
|
||||
"float f = 1000.0;"
|
||||
|
||||
"float color_to_float(vec3 color)\n"
|
||||
"{\n"
|
||||
"const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));\n"
|
||||
"return dot(color, byte_to_float);\n"
|
||||
"}\n"
|
||||
|
||||
"void main()\n"
|
||||
"{"
|
||||
"vec2 texCoord = gl_FragCoord.xy * InvTargetSize;\n"
|
||||
"\t" "vec3 color = texture(ColorTexture, texCoord).xyz;\n"
|
||||
"vec4 gVec1 = textureLod(NormalBuffer, texCoord, 0.0);\n"
|
||||
"float depth = gVec1.w*2.0 - 1.0;\n"
|
||||
"vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);\n"
|
||||
"float depth = color_to_float(gVec2.xyz)*2.0 - 1.0;\n"
|
||||
"float linearDepth = (2 * n) / (f + n - depth * (f - n));"
|
||||
|
||||
"vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);\n"
|
||||
|
|
@ -107,7 +113,7 @@ NzDeferredFogPass::NzDeferredFogPass()
|
|||
{
|
||||
m_program = BuildFogProgram();
|
||||
m_program->SendInteger(m_program->GetUniformLocation("ColorTexture"), 0);
|
||||
m_program->SendInteger(m_program->GetUniformLocation("NormalBuffer"), 1);
|
||||
m_program->SendInteger(m_program->GetUniformLocation("GBuffer2"), 1);
|
||||
|
||||
m_pointSampler.SetAnisotropyLevel(1);
|
||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||
|
|
@ -129,7 +135,7 @@ bool NzDeferredFogPass::Process(const NzScene* scene, unsigned int firstWorkText
|
|||
|
||||
NzRenderer::SetRenderStates(m_states);
|
||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||
NzRenderer::SetTexture(1, m_GBuffer[1]);
|
||||
NzRenderer::SetTexture(1, m_GBuffer[2]);
|
||||
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
||||
NzRenderer::SetTextureSampler(1, m_pointSampler);
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
|
|
|
|||
|
|
@ -254,24 +254,19 @@ bool NzDeferredGeometryPass::Resize(const NzVector2ui& dimensions)
|
|||
|
||||
m_depthStencilBuffer->Create(nzPixelFormat_Depth24Stencil8, width, height);
|
||||
|
||||
m_GBuffer[0]->Create(nzImageType_2D, nzPixelFormat_RGBA8, width, height);
|
||||
m_GBuffer[1]->Create(nzImageType_2D, nzPixelFormat_RGBA32F, width, height);
|
||||
m_GBuffer[2]->Create(nzImageType_2D, nzPixelFormat_RGBA8, width, height);
|
||||
m_GBuffer[0]->Create(nzImageType_2D, nzPixelFormat_RGBA8, width, height); // Texture 0 : Diffuse Color + Specular
|
||||
m_GBuffer[1]->Create(nzImageType_2D, nzPixelFormat_RG16F, width, height); // Texture 1 : Encoded normal
|
||||
m_GBuffer[2]->Create(nzImageType_2D, nzPixelFormat_RGBA8, width, height); // Texture 2 : Depth (24bits) + Shininess
|
||||
|
||||
m_GBufferRTT->Create(true);
|
||||
|
||||
// Texture 0 : Diffuse Color + Flags
|
||||
m_GBufferRTT->AttachTexture(nzAttachmentPoint_Color, 0, m_GBuffer[0]);
|
||||
|
||||
// Texture 1 : Normal map + Depth
|
||||
m_GBufferRTT->AttachTexture(nzAttachmentPoint_Color, 1, m_GBuffer[1]);
|
||||
|
||||
// Texture 2 : Specular value + Shininess
|
||||
m_GBufferRTT->AttachTexture(nzAttachmentPoint_Color, 2, m_GBuffer[2]);
|
||||
|
||||
// Texture 3 : Emission map ?
|
||||
|
||||
m_GBufferRTT->AttachBuffer(nzAttachmentPoint_DepthStencil, 0, m_deferredTechnique->GetDepthStencilBuffer());
|
||||
m_GBufferRTT->AttachBuffer(nzAttachmentPoint_DepthStencil, 0, m_depthStencilBuffer);
|
||||
|
||||
m_GBufferRTT->Unlock();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ out vec4 RenderTarget2;
|
|||
void main()
|
||||
{
|
||||
RenderTarget0 = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
RenderTarget1 = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
RenderTarget2 = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
RenderTarget1 = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
RenderTarget2 = vec4(1.0, 0.0, 0.0, 0.0);
|
||||
gl_FragDepth = 1.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,49,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,13,10,125,13,10,
|
||||
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,49,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,13,10,125,13,10,
|
||||
|
|
@ -25,23 +25,35 @@ uniform mat4 InvViewProjMatrix;
|
|||
uniform vec2 InvTargetSize;
|
||||
uniform vec4 SceneAmbient;
|
||||
|
||||
float ColorToFloat(vec3 color)
|
||||
{
|
||||
const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));
|
||||
return dot(color, byte_to_float);
|
||||
}
|
||||
|
||||
#define kPI 3.1415926536
|
||||
|
||||
vec3 DecodeNormal(in vec4 encodedNormal)
|
||||
{
|
||||
//return encodedNormal.xyz*2.0 - 1.0;
|
||||
float a = encodedNormal.x * kPI;
|
||||
vec2 scth = vec2(sin(a), cos(a));
|
||||
|
||||
vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y);
|
||||
return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
|
||||
if (gVec0.w == 0.0)
|
||||
{
|
||||
RenderTarget0 = vec4(gVec0.xyz, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
|
||||
|
||||
vec3 diffuseColor = gVec0.xyz;
|
||||
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||
vec3 specularColor = gVec2.xyz;
|
||||
float depth = gVec1.w*2.0 - 1.0;
|
||||
vec3 normal = DecodeNormal(gVec1);
|
||||
vec3 specularColor = vec3(gVec0.w);
|
||||
float depth = ColorToFloat(gVec2.xyz);
|
||||
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||
|
||||
vec3 lightDir = -Lights[0].parameters1.xyz;
|
||||
|
|
@ -58,7 +70,7 @@ void main()
|
|||
vec3 lightSpecular = vec3(0.0);
|
||||
if (shininess > 0.0)
|
||||
{
|
||||
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0);
|
||||
|
||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||
worldPos.xyz /= worldPos.w;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -28,6 +28,24 @@ uniform vec4 SceneAmbient;
|
|||
uniform bool Discard = false;
|
||||
uniform bool SpotLight;
|
||||
|
||||
float ColorToFloat(vec3 color)
|
||||
{
|
||||
const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));
|
||||
return dot(color, byte_to_float);
|
||||
}
|
||||
|
||||
#define kPI 3.1415926536
|
||||
|
||||
vec3 DecodeNormal(in vec4 encodedNormal)
|
||||
{
|
||||
//return encodedNormal.xyz*2.0 - 1.0;
|
||||
float a = encodedNormal.x * kPI;
|
||||
vec2 scth = vec2(sin(a), cos(a));
|
||||
|
||||
vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y);
|
||||
return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (Discard)
|
||||
|
|
@ -35,22 +53,16 @@ void main()
|
|||
|
||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
|
||||
if (gVec0.w == 0.0)
|
||||
{
|
||||
RenderTarget0 = vec4(gVec0.xyz, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
|
||||
|
||||
vec3 diffuseColor = gVec0.xyz;
|
||||
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||
vec3 specularColor = gVec2.xyz;
|
||||
float depth = gVec1.w*2.0 - 1.0;
|
||||
vec3 normal = DecodeNormal(gVec1);
|
||||
vec3 specularColor = vec3(gVec0.w);
|
||||
float depth = ColorToFloat(gVec2.xyz);
|
||||
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||
|
||||
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0);
|
||||
|
||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||
worldPos.xyz /= worldPos.w;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -46,6 +46,30 @@ uniform float ParallaxScale = 0.02;
|
|||
uniform vec4 SceneAmbient;
|
||||
|
||||
/********************Fonctions********************/
|
||||
vec3 FloatToColor(float f)
|
||||
{
|
||||
vec3 color;
|
||||
|
||||
f *= 256.0;
|
||||
color.x = floor(f);
|
||||
|
||||
f = (f - color.x) * 256.0;
|
||||
color.y = floor(f);
|
||||
|
||||
color.z = f - color.y;
|
||||
color.xy *= 0.00390625; // *= 1.0/256
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#define kPI 3.1415926536
|
||||
|
||||
vec4 EncodeNormal(in vec3 normal)
|
||||
{
|
||||
//return vec4(normal*0.5 + 0.5, 0.0);
|
||||
return vec4(vec2(atan(normal.y, normal.x)/kPI, normal.z), 0.0, 0.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = MaterialDiffuse;
|
||||
|
|
@ -85,13 +109,13 @@ void main()
|
|||
#endif
|
||||
|
||||
/*
|
||||
Texture0: Diffuse Color + Flags
|
||||
Texture1: Normal map + Depth
|
||||
Texture2: Specular color + Shininess
|
||||
Texture0: Diffuse Color + Specular
|
||||
Texture1: Normal + Specular
|
||||
Texture2: Encoded depth + Shininess
|
||||
*/
|
||||
RenderTarget0 = vec4(diffuseColor.rgb, 1.0);
|
||||
RenderTarget1 = vec4(normal*0.5 + 0.5, gl_FragCoord.z);
|
||||
RenderTarget2 = vec4(specularColor, (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
|
||||
RenderTarget0 = vec4(diffuseColor.rgb, dot(specularColor, vec3(0.3, 0.59, 0.11)));
|
||||
RenderTarget1 = vec4(EncodeNormal(normal));
|
||||
RenderTarget2 = vec4(FloatToColor(gl_FragCoord.z), (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
|
||||
#else // LIGHTING
|
||||
RenderTarget0 = vec4(diffuseColor.rgb, 0.0);
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue