further updates in local envprobe system

This commit is contained in:
turanszkij
2018-01-29 15:15:18 +00:00
parent 283169b69e
commit 3663216107
13 changed files with 152 additions and 82 deletions
-1
View File
@@ -26,7 +26,6 @@
#define TEXSLOT_GBUFFER3 5
#define TEXSLOT_GBUFFER4 6
#define TEXSLOT_ENV_GLOBAL 7
#define TEXSLOT_ENVMAPARRAY 8
#define TEXSLOT_DECALATLAS 11
+3 -1
View File
@@ -1,8 +1,10 @@
#include "envMapHF.hlsli"
#include "skyHF.hlsli"
TEXTURECUBE(texture_sky, float4, TEXSLOT_ONDEMAND0)
float4 main(PSIn_Sky input) : SV_TARGET
{
float3 normal = normalize(input.nor);
return float4(DEGAMMA(GetStaticSkyColor(normal)), 1);
return float4(DEGAMMA(texture_sky.SampleLevel(sampler_linear_clamp, normal, 0).rgb), 1);
}
+1 -1
View File
@@ -12,7 +12,7 @@ LightOutputType main(VertexToPixel PSIn)
float3 R = -reflect(V, N);
float f90 = saturate(50.0 * dot(f0, 0.33));
float3 F = F_Schlick(f0, f90, abs(dot(N, V)) + 1e-5f);
specular = max(0, texture_env_global.SampleLevel(sampler_linear_clamp, R, envMapMIP).rgb * F);
specular = max(0, texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(R, 0), envMapMIP).rgb * F);
VoxelRadiance(N, V, P, f0, roughness, diffuse, specular, ao);
DEFERREDLIGHT_RETURN
-1
View File
@@ -9,7 +9,6 @@ TEXTURE2D(texture_gbuffer1, float4, TEXSLOT_GBUFFER1)
TEXTURE2D(texture_gbuffer2, float4, TEXSLOT_GBUFFER2)
TEXTURE2D(texture_gbuffer3, float4, TEXSLOT_GBUFFER3)
TEXTURE2D(texture_gbuffer4, float4, TEXSLOT_GBUFFER4)
TEXTURECUBE(texture_env_global, float4, TEXSLOT_ENV_GLOBAL)
TEXTURECUBEARRAY(texture_envmaparray, float4, TEXSLOT_ENVMAPARRAY)
TEXTURE2D(texture_decalatlas, float4, TEXSLOT_DECALATLAS)
TEXTURE2DARRAY(texture_shadowarray_2d, float, TEXSLOT_SHADOWARRAY_2D)
@@ -1,5 +1,5 @@
#define DISABLE_DECALS
#define DISABLE_ENVPMAPS
#define DISABLE_ENVMAPS
#include "globals.hlsli"
#include "objectHF.hlsli"
#include "hairparticleHF.hlsli"
+1 -1
View File
@@ -481,7 +481,7 @@ void main(ComputeShaderInput IN)
float3 R = -reflect(V, N);
float f90 = saturate(50.0 * dot(f0, 0.33));
float3 F = F_Schlick(f0, f90, abs(dot(N, V)) + 1e-5f);
specular = max(0, texture_env_global.SampleLevel(sampler_linear_clamp, R, envMapMIP).rgb * F);
specular = max(0, texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(R, 0), envMapMIP).rgb * F);
[loop]
for (uint li = 0; li < o_ArrayLength; ++li)
+2 -2
View File
@@ -173,7 +173,7 @@ inline void ForwardLighting(in float3 N, in float3 V, in float3 P, in float3 f0,
float3 R = -reflect(V, N);
float f90 = saturate(50.0 * dot(f0, 0.33));
float3 F = F_Schlick(f0, f90, abs(dot(N, V)) + 1e-5f);
specular = max(0, texture_env_global.SampleLevel(sampler_linear_clamp, R, envMapMIP).rgb * F);
specular = max(0, texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(R, 0), envMapMIP).rgb * F);
#endif // DISABLE_ENVMAPS
[loop]
@@ -335,7 +335,7 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
#endif // DISABLE_LOCALENVPMAPS
// Apply global envmap where there is no local envmap information:
envmapAccumulation.rgb = lerp(texture_env_global.SampleLevel(sampler_linear_clamp, R, envMapMIP).rgb, envmapAccumulation.rgb, envmapAccumulation.a);
envmapAccumulation.rgb = lerp(texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(R, 0), envMapMIP).rgb, envmapAccumulation.rgb, envmapAccumulation.a);
float f90 = saturate(50.0 * dot(f0, 0.33));
float3 F = F_Schlick(f0, f90, abs(dot(N, V)) + 1e-5f);
+1 -1
View File
@@ -1,5 +1,5 @@
#define DISABLE_TRANSPARENT_SHADOWMAP
#define DISABLE_ENVPMAPS
#define DISABLE_ENVMAPS
#include "objectHF.hlsli"
float4 main(PixelInputType input) : SV_TARGET
@@ -1,6 +1,6 @@
#define DISABLE_TRANSPARENT_SHADOWMAP
#define DISABLE_DECALS
#define DISABLE_ENVPMAPS
#define DISABLE_ENVMAPS
#define DISABLE_ALPHATEST
#include "objectHF.hlsli"
+1 -1
View File
@@ -1,6 +1,6 @@
#define DISABLE_ALPHATEST
#define DISABLE_DECALS
#define DISABLE_ENVPMAPS
#define DISABLE_ENVMAPS
#include "globals.hlsli"
#include "oceanSurfaceHF.hlsli"
#include "objectHF.hlsli"
-6
View File
@@ -3,12 +3,6 @@
#include "globals.hlsli"
#include "lightingHF.hlsli"
float3 GetStaticSkyColor(in float3 normal)
{
return texture_env_global.SampleLevel(sampler_linear_clamp, normal, 0).rgb;
}
float3 GetDynamicSkyColor(in float3 normal)
{
float aboveHorizon = saturate(pow(saturate(normal.y), 1.0f / 4.0f + g_xWorld_Fog.z) / (g_xWorld_Fog.z + 1));
+2 -1
View File
@@ -1,6 +1,7 @@
#include "objectHF.hlsli"
#include "skyHF.hlsli"
TEXTURECUBE(texture_sky, float4, TEXSLOT_ONDEMAND0)
struct VSOut {
float4 pos : SV_POSITION;
@@ -13,7 +14,7 @@ GBUFFEROutputType_Thin main(VSOut input)
{
float3 normal = normalize(input.nor);
float4 color = float4(DEGAMMA(texture_env_global.SampleLevel(sampler_linear_clamp, normal, 0).rgb), 1);
float4 color = float4(DEGAMMA(texture_sky.SampleLevel(sampler_linear_clamp, normal, 0).rgb), 1);
float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f);
GBUFFEROutputType_Thin Out = (GBUFFEROutputType_Thin)0;
+139 -64
View File
@@ -5374,7 +5374,7 @@ void wiRenderer::DrawSky(GRAPHICSTHREAD threadID)
if (enviroMap != nullptr)
{
GetDevice()->BindGraphicsPSO(PSO_sky[SKYRENDERING_STATIC], threadID);
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ENV_GLOBAL, threadID);
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ONDEMAND0, threadID);
}
else
{
@@ -5475,6 +5475,131 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
static const UINT envmapCount = 16;
bool envmapTaken[envmapCount] = {};
if (textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] == nullptr)
{
Texture2DDesc desc;
desc.ArraySize = envmapCount * 6;
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.Format = FORMAT_R16G16B16A16_FLOAT;
desc.Height = envmapRes;
desc.Width = envmapRes;
desc.MipLevels = 0;
desc.MiscFlags = RESOURCE_MISC_GENERATE_MIPS | RESOURCE_MISC_TEXTURECUBE;
desc.Usage = USAGE_DEFAULT;
textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] = new Texture2D;
textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->RequestIndepententRenderTargetArraySlices(true);
HRESULT hr = GetDevice()->CreateTexture2D(&desc, nullptr, (Texture2D**)&textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]);
assert(SUCCEEDED(hr));
}
static Texture2D* envrenderingDepthBuffer = nullptr;
if (envrenderingDepthBuffer == nullptr)
{
Texture2DDesc desc;
desc.ArraySize = 6;
desc.BindFlags = BIND_DEPTH_STENCIL;
desc.CPUAccessFlags = 0;
desc.Format = FORMAT_D16_UNORM;
desc.Height = envmapRes;
desc.Width = envmapRes;
desc.MipLevels = 1;
desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE;
desc.Usage = USAGE_DEFAULT;
HRESULT hr = GetDevice()->CreateTexture2D(&desc, nullptr, &envrenderingDepthBuffer);
assert(SUCCEEDED(hr));
}
ViewPort VP;
VP.Height = envmapRes;
VP.Width = envmapRes;
VP.TopLeftX = 0;
VP.TopLeftY = 0;
VP.MinDepth = 0.0f;
VP.MaxDepth = 1.0f;
GetDevice()->BindViewports(1, &VP, threadID);
const float zNearP = getCamera()->zNearP;
const float zFarP = getCamera()->zFarP;
bool renderhappened = false;
GetDevice()->EventBegin("Global Probe", threadID);
// There can be multiple cases how the global environment map should be updated:
// 1.) There are no local probes and no sky texture -> render dynamic sky into cubemap
// 2.) There are no local probes but there is a static sky texture -> render skydome with degamma-ed sky texture into cubemap
// 3.) TODO: what if we have local probes, probably should use them for globals instead of just sky
{
const int globalEnvMapIndex = 0;
envmapTaken[globalEnvMapIndex] = true;
GetDevice()->BindRenderTargets(1, &textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], envrenderingDepthBuffer, threadID, globalEnvMapIndex);
const float clearColor[4] = { 0,0,0,1 };
GetDevice()->ClearRenderTarget(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], clearColor, threadID, globalEnvMapIndex);
GetDevice()->ClearDepthStencil(envrenderingDepthBuffer, CLEAR_DEPTH, 0.0f, 0, threadID);
std::vector<SHCAM> cameras;
{
cameras.clear();
cameras.push_back(SHCAM(XMFLOAT4(0.5f, -0.5f, -0.5f, -0.5f), zNearP, zFarP, XM_PI / 2.0f)); //+x
cameras.push_back(SHCAM(XMFLOAT4(0.5f, 0.5f, 0.5f, -0.5f), zNearP, zFarP, XM_PI / 2.0f)); //-x
cameras.push_back(SHCAM(XMFLOAT4(1, 0, 0, -0), zNearP, zFarP, XM_PI / 2.0f)); //+y
cameras.push_back(SHCAM(XMFLOAT4(0, 0, 0, -1), zNearP, zFarP, XM_PI / 2.0f)); //-y
cameras.push_back(SHCAM(XMFLOAT4(0.707f, 0, 0, -0.707f), zNearP, zFarP, XM_PI / 2.0f)); //+z
cameras.push_back(SHCAM(XMFLOAT4(0, 0.707f, 0.707f, 0), zNearP, zFarP, XM_PI / 2.0f)); //-z
}
XMFLOAT3 center = getCamera()->translation;
XMVECTOR vCenter = XMLoadFloat3(&center);
CubeMapRenderCB cb;
for (unsigned int i = 0; i < cameras.size(); ++i)
{
cameras[i].Update(vCenter);
cb.mViewProjection[i] = cameras[i].getVP();
}
GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID);
GetDevice()->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID);
CameraCB camcb;
camcb.mCamPos = center; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB
GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &camcb, threadID);
GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID);
if (enviroMap != nullptr)
{
// 2.)
GetDevice()->BindGraphicsPSO(PSO_sky[SKYRENDERING_ENVMAPCAPTURE_STATIC], threadID);
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ONDEMAND0, threadID);
}
else
{
// 1.)
GetDevice()->BindGraphicsPSO(PSO_sky[SKYRENDERING_ENVMAPCAPTURE_DYNAMIC], threadID);
GetDevice()->BindResource(PS, textures[TEXTYPE_2D_CLOUDS], TEXSLOT_ONDEMAND0, threadID);
}
GetDevice()->Draw(240, 0, threadID);
renderhappened = true;
}
GetDevice()->EventEnd(threadID); // Global Probe
GetDevice()->EventBegin("Local Probes", threadID);
// reconstruct envmap array status:
for (EnvironmentProbe* probe : GetScene().environmentProbes)
{
@@ -5484,9 +5609,6 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
}
}
GetDevice()->EventBegin("Local Probes", threadID);
bool renderhappened = false;
for (EnvironmentProbe* probe : GetScene().environmentProbes)
{
if (probe->textureIndex < 0)
@@ -5518,77 +5640,33 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
probe->isUpToDate = true;
}
if (textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] == nullptr)
{
Texture2DDesc desc;
desc.ArraySize = envmapCount * 6;
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.Format = FORMAT_R16G16B16A16_FLOAT;
desc.Height = envmapRes;
desc.Width = envmapRes;
desc.MipLevels = 0;
desc.MiscFlags = RESOURCE_MISC_GENERATE_MIPS | RESOURCE_MISC_TEXTURECUBE;
desc.Usage = USAGE_DEFAULT;
textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] = new Texture2D;
textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->RequestIndepententRenderTargetArraySlices(true);
HRESULT hr = GetDevice()->CreateTexture2D(&desc, nullptr, (Texture2D**)&textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]);
assert(SUCCEEDED(hr));
}
static Texture2D* envrenderingDepthBuffer = nullptr;
if (envrenderingDepthBuffer == nullptr)
{
Texture2DDesc desc;
desc.ArraySize = 6;
desc.BindFlags = BIND_DEPTH_STENCIL;
desc.CPUAccessFlags = 0;
desc.Format = FORMAT_D16_UNORM;
desc.Height = envmapRes;
desc.Width = envmapRes;
desc.MipLevels = 1;
desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE;
desc.Usage = USAGE_DEFAULT;
HRESULT hr = GetDevice()->CreateTexture2D(&desc, nullptr, &envrenderingDepthBuffer);
assert(SUCCEEDED(hr));
}
GetDevice()->BindRenderTargets(1, &textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], envrenderingDepthBuffer, threadID, probe->textureIndex);
const float clearColor[4] = { 0,0,0,1 };
GetDevice()->ClearRenderTarget(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], clearColor, threadID, probe->textureIndex);
GetDevice()->ClearDepthStencil(envrenderingDepthBuffer, CLEAR_DEPTH, 0.0f, 0, threadID);
ViewPort VP;
VP.Height = envmapRes;
VP.Width = envmapRes;
VP.TopLeftX = 0;
VP.TopLeftY = 0;
VP.MinDepth = 0.0f;
VP.MaxDepth = 1.0f;
GetDevice()->BindViewports(1, &VP, threadID);
std::vector<SHCAM> cameras;
{
cameras.clear();
cameras.push_back(SHCAM(XMFLOAT4(0.5f, -0.5f, -0.5f, -0.5f), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //+x
cameras.push_back(SHCAM(XMFLOAT4(0.5f, 0.5f, 0.5f, -0.5f), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //-x
cameras.push_back(SHCAM(XMFLOAT4(0.5f, -0.5f, -0.5f, -0.5f), zNearP, zFarP, XM_PI / 2.0f)); //+x
cameras.push_back(SHCAM(XMFLOAT4(0.5f, 0.5f, 0.5f, -0.5f), zNearP, zFarP, XM_PI / 2.0f)); //-x
cameras.push_back(SHCAM(XMFLOAT4(1, 0, 0, -0), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //+y
cameras.push_back(SHCAM(XMFLOAT4(0, 0, 0, -1), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //-y
cameras.push_back(SHCAM(XMFLOAT4(1, 0, 0, -0), zNearP, zFarP, XM_PI / 2.0f)); //+y
cameras.push_back(SHCAM(XMFLOAT4(0, 0, 0, -1), zNearP, zFarP, XM_PI / 2.0f)); //-y
cameras.push_back(SHCAM(XMFLOAT4(0.707f, 0, 0, -0.707f), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //+z
cameras.push_back(SHCAM(XMFLOAT4(0, 0.707f, 0.707f, 0), getCamera()->zNearP, getCamera()->zFarP, XM_PI / 2.0f)); //-z
cameras.push_back(SHCAM(XMFLOAT4(0.707f, 0, 0, -0.707f), zNearP, zFarP, XM_PI / 2.0f)); //+z
cameras.push_back(SHCAM(XMFLOAT4(0, 0.707f, 0.707f, 0), zNearP, zFarP, XM_PI / 2.0f)); //-z
}
XMFLOAT3 center = probe->translation;
XMVECTOR vCenter = XMLoadFloat3(&center);
CubeMapRenderCB cb;
for (unsigned int i = 0; i < cameras.size(); ++i)
{
cameras[i].Update(XMLoadFloat3(&probe->translation));
cameras[i].Update(vCenter);
cb.mViewProjection[i] = cameras[i].getVP();
}
@@ -5597,14 +5675,14 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
CameraCB camcb;
camcb.mCamPos = probe->translation; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB
camcb.mCamPos = center; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB
GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &camcb, threadID);
CulledList culledObjects;
CulledCollection culledRenderer;
SPHERE culler = SPHERE(probe->translation, getCamera()->zFarP);
SPHERE culler = SPHERE(center, getCamera()->zFarP);
if (spTree != nullptr)
{
spTree->getVisible(culler, culledObjects);
@@ -5624,7 +5702,7 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
if (enviroMap != nullptr)
{
GetDevice()->BindGraphicsPSO(PSO_sky[SKYRENDERING_ENVMAPCAPTURE_STATIC], threadID);
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ENV_GLOBAL, threadID);
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ONDEMAND0, threadID);
}
else
{
@@ -5637,17 +5715,14 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
renderhappened = true;
}
GetDevice()->EventEnd(threadID); // Local Probes
if (renderhappened)
{
GetDevice()->BindRenderTargets(0, nullptr, nullptr, threadID);
GetDevice()->GenerateMips(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], threadID);
}
GetDevice()->EventEnd(threadID); // Local Probes
GetDevice()->BindResource(PS, enviroMap, TEXSLOT_ENV_GLOBAL, threadID);
GetDevice()->BindResource(CS, enviroMap, TEXSLOT_ENV_GLOBAL, threadID);
GetDevice()->BindResource(PS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ENVMAPARRAY, threadID);
GetDevice()->BindResource(CS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ENVMAPARRAY, threadID);