gbuffer normal compression
This commit is contained in:
@@ -26,7 +26,7 @@ void DeferredRenderableComponent::Initialize()
|
||||
rtGBuffer.Initialize(
|
||||
wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight()
|
||||
, true, FORMAT_R8G8B8A8_UNORM);
|
||||
rtGBuffer.Add(FORMAT_R11G11B10_FLOAT);
|
||||
rtGBuffer.Add(FORMAT_R16G16_FLOAT);
|
||||
rtGBuffer.Add(FORMAT_R8G8B8A8_UNORM);
|
||||
rtGBuffer.Add(FORMAT_R8G8B8A8_UNORM);
|
||||
|
||||
|
||||
@@ -94,11 +94,11 @@ float GetDiffuse(float NdotV, float NdotL, float LdotH, float linearRoughness)
|
||||
const float LdotH = HdotV; \
|
||||
const float HdotL = LdotH;
|
||||
|
||||
// ROUGHNESS: float surface roughness
|
||||
// ROUGHNESS: float surface roughness
|
||||
// F0: float3 surface specular color (fresnel f0)
|
||||
#define BRDF_SPECULAR( ROUGHNESS, F0 ) \
|
||||
GetSpecular(NdotV, NdotL, LdotH, NdotH, ROUGHNESS, F0)
|
||||
|
||||
|
||||
// ROUGHNESS: float surface roughness
|
||||
#define BRDF_DIFFUSE( ROUGHNESS ) \
|
||||
GetDiffuse(NdotV, NdotL, LdotH, ROUGHNESS)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "reconstructPositionHF.hlsli"
|
||||
#include "tangentComputeHF.hlsli"
|
||||
#include "packHF.hlsli"
|
||||
|
||||
//Texture2D<float> xSceneDepthMap:register(t1);
|
||||
//Texture2D<float4> xTexture:register(t2);
|
||||
@@ -74,7 +75,7 @@ PixelOutputType main(VertexToPixel PSIn)
|
||||
Out.nor.a=Out.col.a;
|
||||
}
|
||||
|
||||
Out.nor = Out.nor * 0.5f + 0.5f;
|
||||
Out.nor = float4(encode(Out.nor.xyz), 0, Out.nor.a);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ inline void dirLight(in float3 P, in float3 N, in float3 V, in float roughness,
|
||||
|
||||
specular += EnvironmentReflection(N, V, P, roughness, f0);
|
||||
|
||||
float sh = 1;
|
||||
float sh = max(NdotL, 0);
|
||||
float4 ShPos[3];
|
||||
ShPos[0] = mul(float4(P,1),g_xDirLight_ShM[0]);
|
||||
ShPos[1] = mul(float4(P,1),g_xDirLight_ShM[1]);
|
||||
|
||||
@@ -35,7 +35,7 @@ struct LightOutputType
|
||||
float4 baseColor = texture_gbuffer0.SampleLevel(sampler_point_clamp,screenPos,0); \
|
||||
float4 g1 = texture_gbuffer1.SampleLevel(sampler_point_clamp,screenPos,0); \
|
||||
float4 g3 = texture_gbuffer3.SampleLevel(sampler_point_clamp,screenPos,0); \
|
||||
float3 N = g1.xyz * 2 - 1; \
|
||||
float3 N = decode(g1.xy); \
|
||||
float roughness = g3.x; \
|
||||
float reflectance = g3.y; \
|
||||
float metalness = g3.z; \
|
||||
|
||||
@@ -91,14 +91,24 @@ inline void Refraction(in float2 ScreenCoord, in float2 normal2D, in float3 bump
|
||||
alpha = 1;
|
||||
}
|
||||
|
||||
inline void DirectionalLight(in float3 N, in float3 V, in float3 f0, in float3 albedo, in float roughness,
|
||||
inline void DirectionalLight(in float3 N, in float3 V, in float3 P, in float3 f0, in float3 albedo, in float roughness,
|
||||
inout float3 diffuse, out float3 specular)
|
||||
{
|
||||
float3 L = GetSunDirection();
|
||||
float3 lightColor = GetSunColor();
|
||||
BRDF_MAKE(N, L, V);
|
||||
specular = lightColor * BRDF_SPECULAR(roughness, f0);
|
||||
diffuse = lightColor * BRDF_DIFFUSE(roughness);
|
||||
diffuse = lightColor * BRDF_DIFFUSE(roughness);
|
||||
|
||||
specular += EnvironmentReflection(N, V, P, roughness, f0);
|
||||
|
||||
float sh = max(NdotL, 0);
|
||||
|
||||
diffuse *= sh;
|
||||
specular *= sh;
|
||||
|
||||
diffuse = max(diffuse, 0);
|
||||
specular = max(specular, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +152,7 @@ inline void DirectionalLight(in float3 N, in float3 V, in float3 f0, in float3 a
|
||||
BRDF_HELPER_MAKEINPUTS( color, reflectance, metalness )
|
||||
|
||||
#define OBJECT_PS_LIGHT_DIRECTIONAL \
|
||||
DirectionalLight(N, V, f0, albedo, roughness, diffuse, specular);
|
||||
DirectionalLight(N, V, P, f0, albedo, roughness, diffuse, specular);
|
||||
|
||||
#define OBJECT_PS_LIGHT_END \
|
||||
color.rgb = (GetAmbientColor() * ao + diffuse) * albedo + specular;
|
||||
@@ -153,9 +163,6 @@ inline void DirectionalLight(in float3 N, in float3 V, in float3 f0, in float3 a
|
||||
#define OBJECT_PS_NORMALMAPPING \
|
||||
NormalMapping(UV, P, N, bumpColor);
|
||||
|
||||
#define OBJECT_PS_ENVIRONMENTMAPPING \
|
||||
specular += EnvironmentReflection(N, V, P, roughness, f0);
|
||||
|
||||
//#define OBJECT_PS_PLANARREFLECTIONS \
|
||||
// PlanarReflection(input.tex, refUV, N, color);
|
||||
|
||||
@@ -173,8 +180,9 @@ inline void DirectionalLight(in float3 N, in float3 V, in float3 f0, in float3 a
|
||||
|
||||
#define OBJECT_PS_OUT_GBUFFER \
|
||||
GBUFFEROutputType Out = (GBUFFEROutputType)0; \
|
||||
/*N = mul(N.xyz, (float3x3)g_xCamera_View);*/ \
|
||||
Out.g0 = float4(color.rgb, 1); /*FORMAT_R8G8B8A8_UNORM*/ \
|
||||
Out.g1 = float4(N.xyz * 0.5f + 0.5f, 0); /*FORMAT_R11G11B10_FLOAT*/ \
|
||||
Out.g1 = float4(encode(N), 0, 0); /*FORMAT_R16G16_FLOAT*/ \
|
||||
Out.g2 = float4(velocity * 0.5f + 0.5f, sss, emissive); /*FORMAT_R8G8B8A8_UNORM*/ \
|
||||
Out.g3 = float4(roughness, reflectance, metalness, ao); /*FORMAT_R8G8B8A8_UNORM*/ \
|
||||
return Out;
|
||||
|
||||
@@ -15,8 +15,6 @@ float4 main(PixelInputType input) : SV_TARGET
|
||||
|
||||
OBJECT_PS_LIGHT_DIRECTIONAL
|
||||
|
||||
OBJECT_PS_ENVIRONMENTMAPPING
|
||||
|
||||
OBJECT_PS_LIGHT_END
|
||||
|
||||
OBJECT_PS_EMISSIVE
|
||||
|
||||
@@ -16,8 +16,6 @@ float4 main( PixelInputType input) : SV_TARGET
|
||||
|
||||
OBJECT_PS_LIGHT_DIRECTIONAL
|
||||
|
||||
OBJECT_PS_ENVIRONMENTMAPPING
|
||||
|
||||
OBJECT_PS_LIGHT_END
|
||||
|
||||
OBJECT_PS_EMISSIVE
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#ifndef _PACK_HF_
|
||||
#define _PACK_HF_
|
||||
#include "globals.hlsli"
|
||||
|
||||
// Helper functions to compress and uncompress two floats
|
||||
|
||||
@@ -22,4 +23,59 @@ float2 Unpack(float input, int precision = 4096)
|
||||
return output / (precision - 1);
|
||||
}
|
||||
|
||||
|
||||
// Normal vector compressors
|
||||
|
||||
#define NORMALMAPCOMPRESSOR 1
|
||||
|
||||
#if NORMALMAPCOMPRESSOR == 0
|
||||
// Reconstruct Z
|
||||
float2 encode(float3 n)
|
||||
{
|
||||
return float2(n.xy*0.5 + 0.5);
|
||||
}
|
||||
float3 decode(float2 enc)
|
||||
{
|
||||
float3 n;
|
||||
n.xy = enc * 2 - 1;
|
||||
n.z = sqrt(1 - dot(n.xy, n.xy));
|
||||
return n;
|
||||
}
|
||||
|
||||
#elif NORMALMAPCOMPRESSOR == 1
|
||||
|
||||
// Spherical coordinates
|
||||
float2 encode(float3 n)
|
||||
{
|
||||
return (float2(atan2(n.y, n.x) / PI, n.z) + 1.0)*0.5;
|
||||
}
|
||||
float3 decode(float2 enc)
|
||||
{
|
||||
float2 ang = enc * 2 - 1;
|
||||
float2 scth;
|
||||
sincos(ang.x * PI, scth.x, scth.y);
|
||||
float2 scphi = float2(sqrt(1.0 - ang.y*ang.y), ang.y);
|
||||
return float3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Spheremap
|
||||
float2 encode(float3 n)
|
||||
{
|
||||
float2 enc = normalize(n.xy) * (sqrt(-n.z*0.5 + 0.5));
|
||||
enc = enc*0.5 + 0.5;
|
||||
return enc;
|
||||
}
|
||||
float3 decode(float2 enc)
|
||||
{
|
||||
float4 nn = float4(enc,0,0)*float4(2, 2, 0, 0) + float4(-1, -1, 1, -1);
|
||||
float l = dot(nn.xyz, -nn.xyw);
|
||||
nn.z = l;
|
||||
nn.xy *= sqrt(l);
|
||||
return nn.xyz * 2 + float3(0, 0, -1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _PACK_HF_
|
||||
@@ -26,7 +26,7 @@ inline void pointLight(in float3 P, in float3 N, in float3 V, in float roughness
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
float sh = 1;
|
||||
float sh = max(NdotL, 0);
|
||||
[branch]if(xLightEnerDis.w){
|
||||
const float3 lv = P - xLightPos.xyz;
|
||||
static const float bias = 0.025;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//#include "ViewProp.h"
|
||||
#ifndef _POSTPROCESS_HF_
|
||||
#define _POSTPROCESS_HF_
|
||||
|
||||
#include "imageHF.hlsli"
|
||||
#include "packHF.hlsli"
|
||||
|
||||
|
||||
|
||||
@@ -42,4 +45,6 @@ float4 loadScene(float2 texCoord)
|
||||
float2 dim;
|
||||
texture_0.GetDimensions(dim.x, dim.y);
|
||||
return texture_0.Load(int3(dim*texCoord, 0));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _POSTPROCESS_HF_
|
||||
|
||||
@@ -56,7 +56,7 @@ inline void spotLight(in float3 P, in float3 N, in float3 V, in float roughness,
|
||||
specular *= xLightEnerDisCone.x;
|
||||
//color.rgb = max(dot(normalize(xLightDir.xyz), normalize(N)), 0)*xLightEnerDisCone.x;
|
||||
|
||||
float sh = 1;
|
||||
float sh = max(NdotL, 0);
|
||||
float4 ShPos = mul(float4(P,1),xShMat);
|
||||
float2 ShTex = ShPos.xy / ShPos.w * float2(0.5f,-0.5f) + float2(0.5f,0.5f);
|
||||
[branch]if((saturate(ShTex.x) == ShTex.x) && (saturate(ShTex.y) == ShTex.y))
|
||||
|
||||
@@ -46,7 +46,7 @@ static const float3 AO_SAMPLES[ NUM_SAMPLES ] =
|
||||
float4 main(VertexToPixelPostProcess input ):SV_Target
|
||||
{
|
||||
|
||||
float3 normal = loadNormal(input.tex.xy).xyz * 2 - 1;
|
||||
float3 normal = decode(loadNormal(input.tex.xy).xy);
|
||||
|
||||
float3 fres = normalize(xMaskTex.Load(int3((64 * input.tex.xy * 400) % 64, 0)).xyz * 2.0 - 1.0);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ float4 main(VertexToPixelPostProcess input) : SV_Target
|
||||
float4 o = 1;
|
||||
|
||||
float4 vNormZ;
|
||||
vNormZ.rgb = texture_gbuffer1.Load(int3(input.pos.xy, 0)).rgb;
|
||||
vNormZ.rgb = decode(texture_gbuffer1.Load(int3(input.pos.xy, 0)).rg);
|
||||
vNormZ.a = texture_depth.Load(int3(input.pos.xy, 0));
|
||||
|
||||
float2 vRougnessSpec = loadVelocity(input.tex).zw; //specular_power,specular intensity
|
||||
|
||||
@@ -43,7 +43,7 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
|
||||
float2 finalStep = colorM.a * step / depthM;
|
||||
|
||||
// Accumulate the other samples:
|
||||
//[unroll]
|
||||
[unroll]
|
||||
for (int i = 1; i < SSSS_N_SAMPLES; i++) {
|
||||
// Fetch color and depth for current sample:
|
||||
float2 offset = PSIn.tex + kernel[i].a * finalStep;
|
||||
|
||||
@@ -4,6 +4,7 @@ static const float strength = 0.85;
|
||||
|
||||
float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
|
||||
{
|
||||
//return texture_gbuffer1.Load(uint3(PSIn.pos.xy,0)).zzzz;
|
||||
float4 hdr = xTexture.Load(uint3(PSIn.pos.xy,0));
|
||||
float average_luminance = xMaskTex.Load(uint3(0,0,0)).r;
|
||||
//return xMaskTex.SampleLevel(sampler_linear_clamp, PSIn.tex, 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace wiVersion
|
||||
// minor features, major bug fixes
|
||||
const int minor = 8;
|
||||
// minor bug fixes, alterations, refactors
|
||||
const int revision = 1;
|
||||
const int revision = 2;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user