[add] Volumetric Fog

This commit is contained in:
Chanbin Kim
2025-12-27 22:22:07 +09:00
parent 0e0a4e4c89
commit e693b37ff8
18 changed files with 1146 additions and 16 deletions
@@ -94,6 +94,9 @@ float g_fFogPow;
float g_fFogHeightValue;
bool g_bFogVisible;
vector g_vFogColor;
float g_fDepthPackExponent;
Texture3D g_VolumeTexture;
float g_fWeights_32[32] =
{
@@ -1142,6 +1145,8 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
vector vColor = g_OriginalTexture.Sample(DefaultSampler, In.vTexcoord);
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
float3 vVolumeUV = float3(In.vTexcoord.xy, pow(vDepthDesc.y, g_fDepthPackExponent));
if (0.f == g_fFogPow)
{
if (1 == vDepthDesc.y)
@@ -1151,9 +1156,10 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
return Out;
}
float4 vVolumeValue = g_VolumeTexture.Sample(DefaultSampler, vVolumeUV);
float fViewZ = vDepthDesc.y * g_fFar;
float4 vPosition, vPreShadowPosition;
float4 vPosition;
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
vPosition.z = vDepthDesc.x;
@@ -1174,14 +1180,19 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
fRatio = pow(1.f - saturate(exp(-1.f * vDepthDesc.y * g_fFogDensity)), g_fFogPow);
vFinalColor = lerp(vColor, g_vFogColor, fRatio);
vFinalColor.a = 1.f;
vVolumeValue.r = vVolumeValue.r < 1.413f ? pow(abs(vVolumeValue.r * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.r);
vVolumeValue.g = vVolumeValue.g < 1.413f ? pow(abs(vVolumeValue.g * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.g);
vVolumeValue.b = vVolumeValue.b < 1.413f ? pow(abs(vVolumeValue.b * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.b);
vVolumeValue.a = saturate(1.f - vVolumeValue.a);
vFinalColor = float4(lerp(vColor.rgb, vVolumeValue.rgb, vVolumeValue.a), 1.f);
if (1.f == vDepthDesc.y)
{
vFinalColor = float4(g_vFogColor);
vFinalColor = float4(vVolumeValue.rgb, 1.f);
}
Out.vFirstTarget = vFinalColor;
Out.vFirstTarget = vVolumeValue;
return Out;
}
@@ -0,0 +1,88 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float DensityScale = 0.01f;
Texture3D<float4> g_VolumeSRV : register(t0);
RWTexture3D<float4> g_AccVolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float ConvertNdcZToDepth(float ndcZ);
float SliceTickness(float ndcZ, uint dimZ);
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness);
// 볼륨 텍스쳐 밀도, 산란 누적 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_AccVolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float4 accumulatedColor = float4(0.f, 0.f, 0.f, 1.f);
uint3 Position = uint3(DispatchThreadID.xy, 0);
[loop]
for (uint i = 0; i < dims.z; ++i)
{
Position.z = i;
float4 slice = g_VolumeSRV[Position];
float tickness = SliceTickness((float)i / dims.z, dims.z);
accumulatedColor = ScatterStep(accumulatedColor.rgb, accumulatedColor.a, slice.rgb, slice.a, tickness);
g_AccVolumeUAV[Position] = accumulatedColor;
}
}
float SliceTickness (float ndcZ, uint dimZ)
{
return ConvertNdcZToDepth(ndcZ + 1.f / float(dimZ)) - ConvertNdcZToDepth(ndcZ);
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness)
{
sliceDensity = max(sliceDensity, 0.000001f);
sliceDensity *= DensityScale;
float sliceTransmittance = exp(-sliceDensity * tickness);
// Frostbite의 누적 방식
float3 sliceLightIntegral = sliceLight * (1.f - sliceTransmittance) / sliceDensity;
accumulatedLight += sliceLightIntegral * accumulatedTransmittance;
accumulatedTransmittance *= sliceTransmittance;
return float4(accumulatedLight, accumulatedTransmittance);
}
@@ -0,0 +1,111 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float EPSILON = 1e-6f;
struct LightData
{
uint itype;
float3 vDirection;
float3 vPosition;
float fRange;
float4 vColor;
};
//StructuredBuffer<LightData> g_LightBuffer : register(t1);
RWTexture3D<float4> g_VolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims);
float ConvertNdcZToDepth(float ndcZ);
float3 ConvertToWorldPosition(float3 ndc, float depth);
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims);
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAnisotropy);
// 볼륨 텍스쳐 밀도, 산란 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_VolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float3 worldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - worldPosition);
float3 lighting = vLightColor.rgb * vLightColor.a;
float3 lightDir = normalize(vLightDirection);
float3 toLight = -lightDir;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
lighting += vLightColor.rgb * vLightColor.rgb * phase;
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fDensity, fDensity);
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims)
{
float3 ndc = id + 0.5f;
ndc *= float3(2.0f / dims.x, -2.0f / dims.y, 1.0f / dims.z);
ndc += float3(-1.0f, 1.0f, 0.0f);
return ndc;
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float3 ConvertToWorldPosition(float3 ndc, float depth)
{
float4 vViewRay = mul(float4(ndc, 1.f), InvProjMatrix);
vViewRay /= vViewRay.w;
vViewRay /= vViewRay.z;
float4 worldPosition = mul(float4(vViewRay.xyz * depth, 1.f), InvViewMatrix);
return worldPosition.xyz;
}
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims)
{
float3 ndc = ConvertThreadIdToNdc(id, dims);
float depth = ConvertNdcZToDepth(ndc.z);
return ConvertToWorldPosition(ndc, depth);
}
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAsymmetryParameter)
{
float cosTheta = dot(vInputDir, vOutputDir);
float denom = pow(1.f + (fAsymmetryParameter * fAsymmetryParameter) - 2.f * fAsymmetryParameter * cosTheta, 3.f / 2.f);
return (1.f / (4.f * PI)) * ((1.f - (fAsymmetryParameter * fAsymmetryParameter)) / max(denom, EPSILON));
}
@@ -0,0 +1,88 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float DensityScale = 0.01f;
Texture3D<float4> g_VolumeSRV : register(t0);
RWTexture3D<float4> g_AccVolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float ConvertNdcZToDepth(float ndcZ);
float SliceTickness(float ndcZ, uint dimZ);
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness);
// 볼륨 텍스쳐 밀도, 산란 누적 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_AccVolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float4 accumulatedColor = float4(0.f, 0.f, 0.f, 1.f);
uint3 Position = uint3(DispatchThreadID.xy, 0);
[loop]
for (uint i = 0; i < dims.z; ++i)
{
Position.z = i;
float4 slice = g_VolumeSRV[Position];
float tickness = SliceTickness((float)i / dims.z, dims.z);
accumulatedColor = ScatterStep(accumulatedColor.rgb, accumulatedColor.a, slice.rgb, slice.a, tickness);
g_AccVolumeUAV[Position] = accumulatedColor;
}
}
float SliceTickness (float ndcZ, uint dimZ)
{
return ConvertNdcZToDepth(ndcZ + 1.f / float(dimZ)) - ConvertNdcZToDepth(ndcZ);
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness)
{
sliceDensity = max(sliceDensity, 0.000001f);
sliceDensity *= DensityScale;
float sliceTransmittance = exp(-sliceDensity * tickness);
// Frostbite의 누적 방식
float3 sliceLightIntegral = sliceLight * (1.f - sliceTransmittance) / sliceDensity;
accumulatedLight += sliceLightIntegral * accumulatedTransmittance;
accumulatedTransmittance *= sliceTransmittance;
return float4(accumulatedLight, accumulatedTransmittance);
}
@@ -0,0 +1,111 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float EPSILON = 1e-6f;
struct LightData
{
uint itype;
float3 vDirection;
float3 vPosition;
float fRange;
float4 vColor;
};
//StructuredBuffer<LightData> g_LightBuffer : register(t1);
RWTexture3D<float4> g_VolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims);
float ConvertNdcZToDepth(float ndcZ);
float3 ConvertToWorldPosition(float3 ndc, float depth);
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims);
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAnisotropy);
// 볼륨 텍스쳐 밀도, 산란 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_VolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float3 worldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - worldPosition);
float3 lighting = vLightColor.rgb * vLightColor.a;
float3 lightDir = normalize(vLightDirection);
float3 toLight = -lightDir;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
lighting += vLightColor.rgb * vLightColor.rgb * phase;
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fDensity, fDensity);
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims)
{
float3 ndc = id + 0.5f;
ndc *= float3(2.0f / dims.x, -2.0f / dims.y, 1.0f / dims.z);
ndc += float3(-1.0f, 1.0f, 0.0f);
return ndc;
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float3 ConvertToWorldPosition(float3 ndc, float depth)
{
float4 vViewRay = mul(float4(ndc, 1.f), InvProjMatrix);
vViewRay /= vViewRay.w;
vViewRay /= vViewRay.z;
float4 worldPosition = mul(float4(vViewRay.xyz * depth, 1.f), InvViewMatrix);
return worldPosition.xyz;
}
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims)
{
float3 ndc = ConvertThreadIdToNdc(id, dims);
float depth = ConvertNdcZToDepth(ndc.z);
return ConvertToWorldPosition(ndc, depth);
}
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAsymmetryParameter)
{
float cosTheta = dot(vInputDir, vOutputDir);
float denom = pow(1.f + (fAsymmetryParameter * fAsymmetryParameter) - 2.f * fAsymmetryParameter * cosTheta, 3.f / 2.f);
return (1.f / (4.f * PI)) * ((1.f - (fAsymmetryParameter * fAsymmetryParameter)) / max(denom, EPSILON));
}
@@ -94,6 +94,9 @@ float g_fFogPow;
float g_fFogHeightValue;
bool g_bFogVisible;
vector g_vFogColor;
float g_fDepthPackExponent;
Texture3D g_VolumeTexture;
float g_fWeights_32[32] =
{
@@ -1142,6 +1145,8 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
vector vColor = g_OriginalTexture.Sample(DefaultSampler, In.vTexcoord);
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
float3 vVolumeUV = float3(In.vTexcoord.xy, pow(vDepthDesc.y, g_fDepthPackExponent));
if (0.f == g_fFogPow)
{
if (1 == vDepthDesc.y)
@@ -1151,9 +1156,10 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
return Out;
}
float4 vVolumeValue = g_VolumeTexture.Sample(DefaultSampler, vVolumeUV);
float fViewZ = vDepthDesc.y * g_fFar;
float4 vPosition, vPreShadowPosition;
float4 vPosition;
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
vPosition.z = vDepthDesc.x;
@@ -1174,14 +1180,19 @@ PS_OUT_FLT4_SINGLE PS_MAIN_FOG(PS_IN In)
fRatio = pow(1.f - saturate(exp(-1.f * vDepthDesc.y * g_fFogDensity)), g_fFogPow);
vFinalColor = lerp(vColor, g_vFogColor, fRatio);
vFinalColor.a = 1.f;
vVolumeValue.r = vVolumeValue.r < 1.413f ? pow(abs(vVolumeValue.r * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.r);
vVolumeValue.g = vVolumeValue.g < 1.413f ? pow(abs(vVolumeValue.g * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.g);
vVolumeValue.b = vVolumeValue.b < 1.413f ? pow(abs(vVolumeValue.b * 0.38317f), 1.f / 2.2f) : 1.f - exp(-vVolumeValue.b);
vVolumeValue.a = saturate(1.f - vVolumeValue.a);
vFinalColor = float4(lerp(vColor.rgb, vVolumeValue.rgb, vVolumeValue.a), 1.f);
if (1.f == vDepthDesc.y)
{
vFinalColor = float4(g_vFogColor);
vFinalColor = float4(vVolumeValue.rgb, 1.f);
}
Out.vFirstTarget = vFinalColor;
Out.vFirstTarget = vVolumeValue;
return Out;
}
@@ -0,0 +1,88 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float DensityScale = 0.01f;
Texture3D<float4> g_VolumeSRV : register(t0);
RWTexture3D<float4> g_AccVolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float ConvertNdcZToDepth(float ndcZ);
float SliceTickness(float ndcZ, uint dimZ);
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness);
// 볼륨 텍스쳐 밀도, 산란 누적 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_AccVolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float4 accumulatedColor = float4(0.f, 0.f, 0.f, 1.f);
uint3 Position = uint3(DispatchThreadID.xy, 0);
[loop]
for (uint i = 0; i < dims.z; ++i)
{
Position.z = i;
float4 slice = g_VolumeSRV[Position];
float tickness = SliceTickness((float)i / dims.z, dims.z);
accumulatedColor = ScatterStep(accumulatedColor.rgb, accumulatedColor.a, slice.rgb, slice.a, tickness);
g_AccVolumeUAV[Position] = accumulatedColor;
}
}
float SliceTickness (float ndcZ, uint dimZ)
{
return ConvertNdcZToDepth(ndcZ + 1.f / float(dimZ)) - ConvertNdcZToDepth(ndcZ);
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float4 ScatterStep(float3 accumulatedLight, float accumulatedTransmittance, float3 sliceLight, float sliceDensity, float tickness)
{
sliceDensity = max(sliceDensity, 0.000001f);
sliceDensity *= DensityScale;
float sliceTransmittance = exp(-sliceDensity * tickness);
// Frostbite의 누적 방식
float3 sliceLightIntegral = sliceLight * (1.f - sliceTransmittance) / sliceDensity;
accumulatedLight += sliceLightIntegral * accumulatedTransmittance;
accumulatedTransmittance *= sliceTransmittance;
return float4(accumulatedLight, accumulatedTransmittance);
}
@@ -0,0 +1,111 @@
#include "Engine_Shader_Functions.hlsli"
#include "Engine_Shader_Defines.hlsli"
static const float EPSILON = 1e-6f;
struct LightData
{
uint itype;
float3 vDirection;
float3 vPosition;
float fRange;
float4 vColor;
};
//StructuredBuffer<LightData> g_LightBuffer : register(t1);
RWTexture3D<float4> g_VolumeUAV : register(u0);
cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐이더 바인딩할때 인덱스가 동일해야함
{
uint3 VolumeSize;
float fDepthPackExponent;
float fTemporalAccum;
float fFrameIndex;
float fNear;
float fFar;
float3 vCameraPosition;
float fDensity;
float fLightIntensity;
float3 vLightDirection;
float4 vLightColor;
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims);
float ConvertNdcZToDepth(float ndcZ);
float3 ConvertToWorldPosition(float3 ndc, float depth);
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims);
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAnisotropy);
// 볼륨 텍스쳐 밀도, 산란 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint3 dims;
g_VolumeUAV.GetDimensions(dims.x, dims.y, dims.z);
if (!all(DispatchThreadID < dims))
return;
float3 worldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - worldPosition);
float3 lighting = vLightColor.rgb * vLightColor.a;
float3 lightDir = normalize(vLightDirection);
float3 toLight = -lightDir;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
lighting += vLightColor.rgb * vLightColor.rgb * phase;
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fDensity, fDensity);
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims)
{
float3 ndc = id + 0.5f;
ndc *= float3(2.0f / dims.x, -2.0f / dims.y, 1.0f / dims.z);
ndc += float3(-1.0f, 1.0f, 0.0f);
return ndc;
}
float ConvertNdcZToDepth(float ndcZ)
{
float t = pow(ndcZ, fDepthPackExponent);
return t * (fFar - fNear) + fNear;
}
float3 ConvertToWorldPosition(float3 ndc, float depth)
{
float4 vViewRay = mul(float4(ndc, 1.f), InvProjMatrix);
vViewRay /= vViewRay.w;
vViewRay /= vViewRay.z;
float4 worldPosition = mul(float4(vViewRay.xyz * depth, 1.f), InvViewMatrix);
return worldPosition.xyz;
}
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims)
{
float3 ndc = ConvertThreadIdToNdc(id, dims);
float depth = ConvertNdcZToDepth(ndc.z);
return ConvertToWorldPosition(ndc, depth);
}
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAsymmetryParameter)
{
float cosTheta = dot(vInputDir, vOutputDir);
float denom = pow(1.f + (fAsymmetryParameter * fAsymmetryParameter) - 2.f * fAsymmetryParameter * cosTheta, 3.f / 2.f);
return (1.f / (4.f * PI)) * ((1.f - (fAsymmetryParameter * fAsymmetryParameter)) / max(denom, EPSILON));
}
@@ -331,6 +331,7 @@ call Update_Lib.bat
<ClCompile Include="..\Private\VIBuffer_Rect.cpp" />
<ClCompile Include="..\private\VIBuffer_UI_Instance.cpp" />
<ClCompile Include="..\Private\VIBuffer_Terrain.cpp" />
<ClCompile Include="..\private\Volumetric.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Public\Animation.h" />
@@ -570,6 +571,7 @@ call Update_Lib.bat
<ClInclude Include="..\Public\VIBuffer_Rect.h" />
<ClInclude Include="..\public\VIBuffer_UI_Instance.h" />
<ClInclude Include="..\Public\VIBuffer_Terrain.h" />
<ClInclude Include="..\public\Volumetric.h" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Samplers.hlsli">
@@ -647,6 +649,8 @@ call Update_Lib.bat
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Volumetric_Accumulate.hlsl" />
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Volumetric_Compute.hlsl" />
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_WeightBlend.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
@@ -313,6 +313,9 @@
<Filter Include="02.Element\02.Component\13.NPCStat">
<UniqueIdentifier>{a564976c-cade-4f34-85c8-891b28d96b93}</UniqueIdentifier>
</Filter>
<Filter Include="01.Utility\08.Volumetric">
<UniqueIdentifier>{950977f0-f3c9-42f1-83f1-270b4bebf7ef}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Private\Base.cpp">
@@ -597,6 +600,9 @@
<ClCompile Include="..\private\NPCStat.cpp">
<Filter>02.Element\02.Component\13.NPCStat</Filter>
</ClCompile>
<ClCompile Include="..\private\Volumetric.cpp">
<Filter>01.Utility\08.Volumetric</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Public\Base.h">
@@ -1247,6 +1253,9 @@
<ClInclude Include="..\public\NPCStat.h">
<Filter>02.Element\02.Component\13.NPCStat</Filter>
</ClInclude>
<ClInclude Include="..\public\Volumetric.h">
<Filter>01.Utility\08.Volumetric</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\Public\Assimp\color4.inl">
@@ -1341,5 +1350,11 @@
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Local_Compute.hlsl">
<Filter>99.Define\01.SHADER</Filter>
</FxCompile>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Volumetric_Compute.hlsl">
<Filter>99.Define\01.SHADER</Filter>
</FxCompile>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Volumetric_Accumulate.hlsl">
<Filter>99.Define\01.SHADER</Filter>
</FxCompile>
</ItemGroup>
</Project>
@@ -173,8 +173,6 @@ ID3D11UnorderedAccessView* CComputeShader::GetOutputUAV(_uint iIndex) const
return m_pOutputUAV[iIndex];
}
void CComputeShader::Reset()
{
//다음 랜더링 패스에 연관되지 않도록 초기화
+1
View File
@@ -33,6 +33,7 @@ HRESULT CFog::Bind_FogValue(CShader* pShader)
pShader->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_bool));
pShader->Bind_Matrix("g_invMatView", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW_INV));
pShader->Bind_Matrix("g_invmatProj", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ_INV));
pShader->Bind_SRV("g_VolumeTexture", m_pGameInstance->Get_VolumeSRV());
}
else
{
@@ -19,6 +19,7 @@
#include "Fog.h"
#include "Resource_Manager.h"
#include "Font_Manager.h"
#include "Volumetric.h"
IMPLEMENT_SINGLETON(CGameInstance)
@@ -115,6 +116,11 @@ HRESULT CGameInstance::Initialize_Engine(const ENGINE_DESC& EngineDesc, ID3D11De
return E_FAIL;
}
m_pVolumetric = CVolumetric::Create(*ppDevice, *ppContext);
if (nullptr == m_pVolumetric) {
return E_FAIL;
}
m_pFont_Manager = CFont_Manager::Create(*ppDevice, *ppContext);
if (nullptr == m_pFont_Manager) {
return E_FAIL;
@@ -150,6 +156,8 @@ void CGameInstance::Update_Engine(_float fTimeDelta)
m_pObject_Manager->Late_Update(fExcuteTimeDelta);
m_pVolumetric->Dispatch();
m_pLevel_Manager->Update(fExcuteTimeDelta);
m_pObject_Manager->Clear_DeadObj();
@@ -939,6 +947,10 @@ _float CGameInstance::Get_CameraFov()
{
return m_pCamera_Manager->Get_CameraFov();
}
_float CGameInstance::Get_CameraNear()
{
return m_pCamera_Manager->Get_CameraNear();
}
const _float* CGameInstance::Get_CurrentCameraFar()
{
return m_pCamera_Manager->Get_CurrentCameraFar();
@@ -1284,6 +1296,16 @@ _float CGameInstance::FontSizeX(const _wstring& strFontTag, const _tchar* pText)
return m_pFont_Manager->FontSizeX(strFontTag, pText);
}
ID3D11ShaderResourceView* CGameInstance::Get_VolumeSRV()
{
return m_pVolumetric->Get_VolumeSRV();
}
_float* CGameInstance::Get_DepthPackExponentPtr()
{
return m_pVolumetric->Get_DepthPackExponentPtr();
}
#pragma endregion
void CGameInstance::Release_Engine()
@@ -1302,6 +1324,7 @@ void CGameInstance::Release_Engine()
SAFE_RELEASE(m_pKey_Manager);
SAFE_RELEASE(m_pMouse_Manager);
SAFE_RELEASE(m_pTimer_Manager);
SAFE_RELEASE(m_pVolumetric);
SAFE_RELEASE(m_pRenderer);
SAFE_RELEASE(m_pObject_Manager);
SAFE_RELEASE(m_pPhysX_Manager);
+11 -4
View File
@@ -563,16 +563,23 @@ void CRenderer::Render_Fog()
{
COMPUTE_TIMEDELTA("Timer_Render_Fog");
EVENTSCOPE_("Render_Fog");
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_Fog"), m_pShader, "g_Texture"))) {
return;
}
m_pShader->Begin(ENUM_CLASS(SHADER_PASS_DEFERRED::DEBUG));
m_pVIBuffer->Bind_Resources();
m_pVIBuffer->Render();
m_pShader->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float));
m_pShader->Bind_RawValue("g_fDepthPackExponent", m_pGameInstance->Get_DepthPackExponentPtr(), sizeof(_float));
if (FAILED(m_pGameInstance->Bind_FogValue(m_pShader))) { // 여기서 포그에서 쓰는 상수들 바인딩 해줌
assert(false);
}
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_Fog"), m_pShader, "g_OriginalTexture"))) {
return;
}
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_Depth"), m_pShader, "g_DepthTexture"))) {
return;
}
@@ -0,0 +1,355 @@
#include "pch.h"
#include "Volumetric.h"
#include "GameInstance.h"
#include "RenderEventDebugger.h"
CVolumetric::CVolumetric(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
: m_pDevice{ pDevice }
, m_pContext{ pContext }
, m_pGameInstance{ CGameInstance::GetInstance() }
{
SAFE_ADDREF(m_pDevice);
SAFE_ADDREF(m_pContext);
SAFE_ADDREF(m_pGameInstance);
}
HRESULT CVolumetric::Initialize()
{
if (FAILED(CreateBlob()))
return E_FAIL;
if (FAILED(CreateComputeShader()))
return E_FAIL;
if (FAILED(CreateBuffers()))
return E_FAIL;
if(FAILED(CreateResourceViews()))
return E_FAIL;
return S_OK;
}
void CVolumetric::Update()
{
}
void CVolumetric::Cumpute_Volume()
{
EVENTSCOPE_("Render_Cumpute_Volume");
D3D11_MAPPED_SUBRESOURCE ConstantSubResource = {};
if (FAILED(m_pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ConstantSubResource)))
{
MSG_BOX("Failed to Map : CVolumetric");
}
else
{
CS_VOLUME_CONSTANT_DESC* pDesc = static_cast<CS_VOLUME_CONSTANT_DESC*>(ConstantSubResource.pData);
pDesc->VolumeSize = { 160, 90, 128 };
pDesc->fDepthPackExponent = m_fDepthPackExponent;
pDesc->fTemporalAccum = 0.f;
pDesc->fFrameIndex = 0.f;
pDesc->fNear = m_pGameInstance->Get_CameraNear();
pDesc->fFar = *(m_pGameInstance->Get_CurrentCameraFar());
memcpy(&pDesc->vCameraPosition, m_pGameInstance->Get_CamPosition(), sizeof(_float3));
pDesc->fDensity = m_fDensity;
pDesc->fLightIntensity = m_fLightIntensity;
const LIGHT_DESC* pLightDesc = m_pGameInstance->Get_Light_Info(m_pGameInstance->Get_CurrentLevelID(), 0);
if(nullptr != pLightDesc)
{
memcpy(&pDesc->vLightDirection, pLightDesc->pDirection, sizeof(_float3));
pDesc->vLightColor = pLightDesc->vDiffuse;
}
else
pDesc->vLightDirection = _float3(-0.5f, -0.5f, 0.f);
XMStoreFloat4x4(&pDesc->InvProjMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ_INV));
XMStoreFloat4x4(&pDesc->InvViewMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW_INV));
pDesc->fAsymmetryParameter = m_fAsymmetryParameter;
pDesc->padding0 = 0.f;
pDesc->padding1 = 0.f;
pDesc->padding2 = 0.f;
m_pContext->Unmap(m_pConstantBuffer, 0);
}
//컴퓨트 쉐이더 바인딩
m_pContext->CSSetShader(m_pCSVolumeCalculate, nullptr, 0);
m_pContext->CSSetConstantBuffers(0, 1, &m_pConstantBuffer);
//SRV, UAV 바인딩
m_pContext->CSSetUnorderedAccessViews(0, 1, &m_pVolumeUAV, nullptr);
//컴퓨트 쉐이더 실행
XMUINT3 vGroupCount = { (160 + 7) / 8, (90 + 7) / 8, (128 + 3) / 4 };
m_pContext->Dispatch((_uint)vGroupCount.x, (_uint)vGroupCount.y, (_uint)vGroupCount.z);
//m_pContext->CopyResource(ppBuffers[i], m_pOutputBuffer[i]);
ID3D11ShaderResourceView* nullSRV = { nullptr };
ID3D11UnorderedAccessView* nullUAV = { nullptr };
// Reset
//m_pContext->CSSetShaderResources(0, 1, &nullSRV);
m_pContext->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr);
m_pContext->CSSetShader(nullptr, nullptr, 0);
}
void CVolumetric::Accumulate_Volume()
{
EVENTSCOPE_("Render_Accumulate_Volume");
//컴퓨트 쉐이더 바인딩
m_pContext->CSSetShader(m_pCSVolumeAccumulate, nullptr, 0);
m_pContext->CSSetConstantBuffers(0, 1, &m_pConstantBuffer);
//SRV, UAV 바인딩
m_pContext->CSSetShaderResources(0, 1, &m_pVolumeSRV);
m_pContext->CSSetUnorderedAccessViews(0, 1, &m_pAccVolumeUAV, nullptr);
//컴퓨트 쉐이더 실행
XMUINT3 vGroupCount = { (160 + 7) / 8, (90 + 7) / 8, (128 + 3) / 4 };
m_pContext->Dispatch((_uint)vGroupCount.x, (_uint)vGroupCount.y, (_uint)vGroupCount.z);
ID3D11ShaderResourceView* nullSRV = { nullptr };
ID3D11UnorderedAccessView* nullUAV = { nullptr };
// Reset
m_pContext->CSSetShaderResources(0, 1, &nullSRV);
m_pContext->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr);
m_pContext->CSSetShader(nullptr, nullptr, 0);
}
HRESULT CVolumetric::Dispatch()
{
#ifdef _DEBUG
Describe_Entity();
#endif // _DEBUG
Cumpute_Volume();
Accumulate_Volume();
return S_OK;
}
CVolumetric* CVolumetric::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
{
CVolumetric* pInstance = new CVolumetric(pDevice, pContext);
if (FAILED(pInstance->Initialize()))
{
MSG_BOX("Failed to Created : CVolumetric");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CVolumetric::Free()
{
__super::Free();
SAFE_RELEASE(m_pConstantBuffer);
SAFE_RELEASE(m_pLightInfoBuffer);
SAFE_RELEASE(m_pAccVolumeUAV);
SAFE_RELEASE(m_pAccVolumeSRV);
SAFE_RELEASE(m_pVolumeUAV);
SAFE_RELEASE(m_pVolumeSRV);
SAFE_RELEASE(m_pTexture3D);
SAFE_RELEASE(m_pAccumulateTexture3D);
SAFE_RELEASE(m_pCSBlobCalculate);
SAFE_RELEASE(m_pCSVolumeCalculate);
SAFE_RELEASE(m_pCSVolumeAccumulate);
SAFE_RELEASE(m_pCSBlobAccumulate);
SAFE_RELEASE(m_pDevice);
SAFE_RELEASE(m_pContext);
SAFE_RELEASE(m_pGameInstance);
}
#ifdef _DEBUG
void CVolumetric::Describe_Entity()
{
_bool open = true;
GUI::Begin("SYSTEM", &open, IMGUI_GLOBAL_BEGIN_FLAG);
if (GUI::CollapsingHeader("VOLUMETRIC")) {
GUI::SliderFloat("Density", &m_fDensity,0.01f, 5.f);
GUI::SliderFloat("LightIntensity", &m_fLightIntensity, 0.01f, 5.f);
GUI::SliderFloat("AsymmetryParameter", &m_fAsymmetryParameter, 0.01f, 5.f);
GUI::SliderFloat("DepthPackExponent", &m_fDepthPackExponent, 0.01f, 5.f);
}
GUI::End();
}
#endif // _DEBUG
HRESULT CVolumetric::CreateComputeShader()
{
if (FAILED(m_pDevice->CreateComputeShader(
m_pCSBlobCalculate->GetBufferPointer(), // 컴파일된 쉐이더 코드
m_pCSBlobCalculate->GetBufferSize(), // 코드 길이
nullptr, // 클래스 인스턴스 (없음)
&m_pCSVolumeCalculate // 컴퓨트 쉐이더 객체
)))
return E_FAIL;
if (FAILED(m_pDevice->CreateComputeShader(
m_pCSBlobAccumulate->GetBufferPointer(),
m_pCSBlobAccumulate->GetBufferSize(),
nullptr,
&m_pCSVolumeAccumulate
)))
return E_FAIL;
return S_OK;
}
HRESULT CVolumetric::CreateBlob()
{
UINT HLSLFlags = {};
#ifdef _DEBUG
HLSLFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
#else
HLSLFlags = D3DCOMPILE_OPTIMIZATION_LEVEL1;
#endif // _DEBUG
if(FAILED(D3DCompileFromFile(TEXT("../Bin/Resources/ShaderFiles/Shader_Volumetric_Compute.hlsl"),
nullptr,
D3D_COMPILE_STANDARD_FILE_INCLUDE,
"CS_MAIN",
"cs_5_0",
HLSLFlags,
0,
&m_pCSBlobCalculate,
nullptr)))
return E_FAIL;
if (FAILED(D3DCompileFromFile(TEXT("../Bin/Resources/ShaderFiles/Shader_Volumetric_Accumulate.hlsl"),
nullptr,
D3D_COMPILE_STANDARD_FILE_INCLUDE,
"CS_MAIN",
"cs_5_0",
HLSLFlags,
0,
&m_pCSBlobAccumulate,
nullptr)))
return E_FAIL;
return S_OK;
}
HRESULT CVolumetric::CreateBuffers()
{
//컨스턴트 버퍼 생성
D3D11_BUFFER_DESC cbDesc = {};
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.ByteWidth = sizeof(CS_VOLUME_CONSTANT_DESC);
D3D11_SUBRESOURCE_DATA CBInitialDesc = {};
if (FAILED(m_pDevice->CreateBuffer(&cbDesc, nullptr, &m_pConstantBuffer)))
return E_FAIL;
D3D11_MAPPED_SUBRESOURCE ConstantSubResource = {};
if (FAILED(m_pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ConstantSubResource)))
{
MSG_BOX("Failed to Map : CVolumetric");
}
else
{
CS_VOLUME_CONSTANT_DESC* pDesc = static_cast<CS_VOLUME_CONSTANT_DESC*>(ConstantSubResource.pData);
pDesc->VolumeSize = { 160, 90, 128 };
pDesc->fDepthPackExponent = m_fDepthPackExponent;
pDesc->fTemporalAccum = 0.f;
pDesc->fFrameIndex = 0.f;
pDesc->fNear = m_pGameInstance->Get_CameraNear();
pDesc->fFar = *(m_pGameInstance->Get_CurrentCameraFar());
memcpy(&pDesc->vCameraPosition, m_pGameInstance->Get_CamPosition(), sizeof(_float3));
pDesc->fDensity = m_fDensity;
pDesc->fLightIntensity = m_fLightIntensity;
// GetLingtInfo ....................
pDesc->vLightDirection = _float3(0.f, 0.577f, 0.f);
pDesc->vLightColor = _float4(1.f, 1.f, 1.f, 1.f);
XMStoreFloat4x4(&pDesc->InvProjMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ_INV));
XMStoreFloat4x4(&pDesc->InvViewMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW_INV));
pDesc->fAsymmetryParameter = 0.0f;
pDesc->padding0 = 0.f;
pDesc->padding1 = 0.f;
pDesc->padding2 = 0.f;
m_pContext->Unmap(m_pConstantBuffer, 0);
}
return S_OK;
}
HRESULT CVolumetric::CreateResourceViews()
{
D3D11_TEXTURE3D_DESC TextureDesc{};
TextureDesc.Width = 160;
TextureDesc.Height = 90;
TextureDesc.Depth = 128; // 64 or 128
TextureDesc.MipLevels = 1;
TextureDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
TextureDesc.Usage = D3D11_USAGE_DEFAULT;
TextureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
TextureDesc.CPUAccessFlags = 0;
TextureDesc.MiscFlags = 0;
if (FAILED(m_pDevice->CreateTexture3D(&TextureDesc, nullptr, &m_pTexture3D))) {
return E_FAIL;
}
if (FAILED(m_pDevice->CreateTexture3D(&TextureDesc, nullptr, &m_pAccumulateTexture3D))) {
return E_FAIL;
}
if (FAILED(m_pDevice->CreateShaderResourceView(m_pTexture3D, nullptr, &m_pVolumeSRV))) {
return E_FAIL;
}
if (FAILED(m_pDevice->CreateShaderResourceView(m_pAccumulateTexture3D, nullptr, &m_pAccVolumeSRV))) {
return E_FAIL;
}
D3D11_UNORDERED_ACCESS_VIEW_DESC UAV_Decs{};
UAV_Decs.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
UAV_Decs.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
UAV_Decs.Texture3D.FirstWSlice = 0;
UAV_Decs.Texture3D.MipSlice = 0;
UAV_Decs.Texture3D.WSize = TextureDesc.Depth;
if (FAILED(m_pDevice->CreateUnorderedAccessView(m_pTexture3D, &UAV_Decs, &m_pVolumeUAV)))
return E_FAIL;
if (FAILED(m_pDevice->CreateUnorderedAccessView(m_pAccumulateTexture3D, &UAV_Decs, &m_pAccVolumeUAV)))
return E_FAIL;
return S_OK;
}
@@ -18,6 +18,7 @@ class CCamera_Manager final : public CBase
HRESULT IsBinded_Camera(const _wstring& wstrCameraKey);
_vector Get_CameraLook();
_float Get_CameraFov();
_float Get_CameraNear() const { return m_fNear; }
void Force_CamPosition(_fvector vPos);
@@ -35,6 +36,7 @@ class CCamera_Manager final : public CBase
_wstring m_wstrCurrentCameraKey = {};
_float m_fFar = 500.f;
_float m_fNear = 0.1f;
private:
HRESULT Initialize(_uint iLevelNumber);
@@ -196,6 +196,7 @@ class ENGINE_DLL CGameInstance final : public CBase
HRESULT IsBinded_Camera(const _wstring& strCameraKey);
_vector Get_CameraLook();
_float Get_CameraFov();
_float Get_CameraNear();
const _float* Get_CurrentCameraFar();
void Force_CamPosition(_fvector vPos);
#pragma endregion
@@ -265,6 +266,11 @@ class ENGINE_DLL CGameInstance final : public CBase
_float FontSizeX(const _wstring& strFontTag, const _tchar* pText);
#pragma endregion
#pragma region VOLUMETRIC
ID3D11ShaderResourceView* Get_VolumeSRV();
_float* Get_DepthPackExponentPtr();
#pragma endregion
public:
void Add_ModelToMap(const _char* filePath, CModel* pModel);
@@ -304,6 +310,7 @@ class ENGINE_DLL CGameInstance final : public CBase
class CFog* m_pFog = { nullptr };
class CResource_Manager* m_pResource_Manager = { nullptr };
class CFont_Manager* m_pFont_Manager = { nullptr };
class CVolumetric* m_pVolumetric = { nullptr };
mt19937 m_Rng{ random_device{}() };
_float2 m_vViewPortSize = {};
@@ -0,0 +1,99 @@
#pragma once
#include "Base.h"
#include "RenderEventDebugger.h"
NS_BEGIN(Engine)
class CVolumetric final : public CBase
{
typedef struct tagCSVolumeConstantDesc
{
XMUINT3 VolumeSize;
_float fDepthPackExponent; // 깊이 비선형 분포 지수 2.0 정도
_float fTemporalAccum; // Temporal 사용 여부 off :0 /On: 1
_float fFrameIndex;
_float fNear;
_float fFar;
_float3 vCameraPosition;
_float fDensity;
_float fLightIntensity;
_float3 vLightDirection;
_float4 vLightColor;
_float4x4 InvProjMatrix;
_float4x4 InvViewMatrix;
_float fAsymmetryParameter;
_float padding0;
_float padding1;
_float padding2;
}CS_VOLUME_CONSTANT_DESC;
private:
CVolumetric(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
virtual ~CVolumetric() = default;
public:
HRESULT Initialize();
void Update();
void Cumpute_Volume();
void Accumulate_Volume();
HRESULT Dispatch();
ID3D11ShaderResourceView* Get_VolumeSRV() { return m_pAccVolumeSRV; }
_float* Get_DepthPackExponentPtr() { return &m_fDepthPackExponent; }
private:
class CGameInstance* m_pGameInstance = { nullptr };
ID3D11Device* m_pDevice = { nullptr };
ID3D11DeviceContext* m_pContext = { nullptr };
ID3D11Texture3D* m_pTexture3D = { nullptr };
ID3D11Texture3D* m_pAccumulateTexture3D = { nullptr };
ID3D11ShaderResourceView* m_pVolumeSRV = {nullptr};
ID3D11UnorderedAccessView* m_pVolumeUAV = { nullptr };
ID3D11ShaderResourceView* m_pAccVolumeSRV = {nullptr};
ID3D11UnorderedAccessView* m_pAccVolumeUAV = { nullptr };
ID3D11Buffer* m_pConstantBuffer = { nullptr };
ID3D11Buffer* m_pLightInfoBuffer = { nullptr };
ID3D11ComputeShader* m_pCSVolumeCalculate = { nullptr };
ID3DBlob* m_pCSBlobCalculate = { nullptr };
ID3D11ComputeShader* m_pCSVolumeAccumulate = { nullptr };
ID3DBlob* m_pCSBlobAccumulate = { nullptr };
_float m_fDensity = { 0.5f };
_float m_fLightIntensity = { 1.f };
_float m_fAsymmetryParameter = { 0.2f };
_float m_fDepthPackExponent = { 2.f };
#ifdef _DEBUG
class CRenderEventDebugger m_AnnotationHelper = {};
#endif // _DEBUG
private:
HRESULT CreateComputeShader();
HRESULT CreateBlob();
HRESULT CreateBuffers();
HRESULT CreateResourceViews();
public:
static CVolumetric* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
virtual void Free();
#ifdef _DEBUG
void Describe_Entity();
#endif // _DEBUG
};
NS_END