-
Notifications
You must be signed in to change notification settings - Fork 840
Fixed ambient probe convolution warning #6523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
3d81248
Refactor SkyManager with render graph (WIP1)
JulienIgnace-Unity b1fb2a7
WIP2
JulienIgnace-Unity 02dde63
WIP 3
JulienIgnace-Unity c78a480
WIP 4
JulienIgnace-Unity f0117ee
Fixed SkyRenderer.Update not having a proper command buffer
JulienIgnace-Unity 63dd5a0
Removed hack to wait for ambient probe readback on first frame.
JulienIgnace-Unity 745ffe2
Fixed RequiresPreRenderSky API to not use stale BuiltinParameters
JulienIgnace-Unity 293600c
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity da3c895
Fixed cubemap allocation for cloud ambient computation
JulienIgnace-Unity cee99d9
Volumetric Lighting now uses an ambient probe directly coming from GP…
JulienIgnace-Unity 22a2cb6
Fixed cases with no sky and where ambient convolution should not outp…
JulienIgnace-Unity 9787551
Ambient probe read by the APV is now directly a compute buffer instea…
JulienIgnace-Unity 86db727
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity f0e1478
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity 6dd6902
Remvoed useless comment and changed function signature based on revie…
JulienIgnace-Unity 8dec347
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity f91af06
Merge branch 'hd/gpu-ambient-probe' of https://github.com/Unity-Techn…
JulienIgnace-Unity b29beeb
Post merge fix
JulienIgnace-Unity 6403b13
Refactor ambient probe convolutions with proper math and added a SH u…
JulienIgnace-Unity b55a256
Fixed SH inversion
JulienIgnace-Unity b47aa76
Moved some SH functions to utility file
JulienIgnace-Unity b37c0ff
Update SphericalHarmonics.hlsl
sebastienlagarde 399f3a4
Update BuiltinGIUtilities.hlsl
sebastienlagarde 3f9be80
Update AmbientProbeConvolution.compute
sebastienlagarde a693b9f
Update changelog
JulienIgnace-Unity ee4f615
Update AmbientProbeConvolution.compute
sebastienlagarde 72eb1e1
Merge branch 'master' into hd/gpu-ambient-probe
JulienIgnace-Unity c38d2c6
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity ea5ff0c
Merge branch 'hd/gpu-ambient-probe' of https://github.com/Unity-Techn…
JulienIgnace-Unity dd716f9
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity dcac9ad
Apply formatting changes
a214dc5
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity 1ca76c3
Fixed null ref when clouds are enbaled
JulienIgnace-Unity e1366f2
Fixed shader compilation
JulienIgnace-Unity c46b6cf
Fixed warning in ambient probe convolution shader
JulienIgnace-Unity 94d87ab
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity 1b37c11
Post merge fix
JulienIgnace-Unity d611830
Whitespace
JulienIgnace-Unity ef8c4e9
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity 58726ab
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
JulienIgnace-Unity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,12 @@ RWStructuredBuffer<float> _AmbientProbeOutputBuffer; | |
RWStructuredBuffer<float4> _VolumetricAmbientProbeOutputBuffer; | ||
RWStructuredBuffer<float4> _DiffuseAmbientProbeOutputBuffer; | ||
|
||
// If we use local VGPRs as a scratch buffer we end up using too many register | ||
// To avoid that we go through memory. | ||
// This is quite messy and bad for performance but this shader should never be critical so it should be fine. | ||
// Uint is used as it's the only format supported everywhere as read/write from same thread. | ||
RWStructuredBuffer<uint> _ScratchBuffer; | ||
|
||
uniform float4 _FogParameters; | ||
|
||
#define _FogDimmer _FogParameters.x | ||
|
@@ -40,6 +46,45 @@ uniform float4 _FogParameters; | |
groupshared float outputSHCoeffsLDS[SH_COEFF_COUNT * SAMPLE_COUNT / 2]; | ||
#endif | ||
|
||
void PackSHFromScratchBuffer(RWStructuredBuffer<float4> buffer) | ||
{ | ||
int c = 0; | ||
for (c = 0; c < 3; c++) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra white line |
||
{ | ||
buffer[c] = float4(asfloat(_ScratchBuffer[c * 9 + 3]), asfloat(_ScratchBuffer[c * 9 + 1]), asfloat(_ScratchBuffer[c * 9 + 2]), asfloat(_ScratchBuffer[c * 9 + 0]) - asfloat(_ScratchBuffer[c * 9 + 6])); | ||
} | ||
|
||
// Quadratic (4/5) | ||
for (c = 0; c < 3; c++) | ||
{ | ||
buffer[3 + c] = float4(asfloat(_ScratchBuffer[c * 9 + 4]), asfloat(_ScratchBuffer[c * 9 + 5]), asfloat(_ScratchBuffer[c * 9 + 6]) * 3.0f, asfloat(_ScratchBuffer[c * 9 + 7])); | ||
} | ||
|
||
// Quadratic (5) | ||
buffer[6] = float4(asfloat(_ScratchBuffer[0 * 9 + 8]), asfloat(_ScratchBuffer[1 * 9 + 8]), asfloat(_ScratchBuffer[2 * 9 + 8]), 1.0f); | ||
} | ||
|
||
void ConvolveZonalFromScratchBuffer(float3 zh) | ||
{ | ||
for (int l = 0; l <= 2; l++) | ||
{ | ||
float n = sqrt((4.0f * PI) / (2 * l + 1)); | ||
float k = zh[l]; | ||
float p = n * k; | ||
|
||
for (int m = -l; m <= l; m++) | ||
{ | ||
int i = l * (l + 1) + m; | ||
|
||
for (int c = 0; c < 3; c++) | ||
{ | ||
_ScratchBuffer[c * 9 + i] = asuint(asfloat(_ScratchBuffer[c * 9 + i]) * p); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[numthreads(SAMPLE_COUNT, 1, 1)] | ||
void KERNEL_NAME(uint dispatchThreadId : SV_DispatchThreadID) | ||
{ | ||
|
@@ -173,16 +218,14 @@ void KERNEL_NAME(uint dispatchThreadId : SV_DispatchThreadID) | |
_AmbientProbeOutputBuffer[i] = outputSHCoeffs[i] * kClampedCosineCoefs[i % 9] * kSHBasisCoef[i % 9]; | ||
} | ||
|
||
float result[27]; | ||
|
||
#if OUTPUT_DIFFUSE | ||
for (i = 0; i < SH_COEFF_COUNT; ++i) | ||
{ | ||
result[i] = _AmbientProbeOutputBuffer[i]; | ||
_ScratchBuffer[i] = asuint(_AmbientProbeOutputBuffer[i]); | ||
} | ||
|
||
// Diffuse convolution packed to be ready for shader consumption | ||
PackSH(_DiffuseAmbientProbeOutputBuffer, result); | ||
PackSHFromScratchBuffer(_DiffuseAmbientProbeOutputBuffer); | ||
#endif | ||
|
||
#if OUTPUT_VOLUMETRIC | ||
|
@@ -191,24 +234,24 @@ void KERNEL_NAME(uint dispatchThreadId : SV_DispatchThreadID) | |
// Apply FogDimmer | ||
for (i = 0; i < SH_COEFF_COUNT; ++i) | ||
{ | ||
result[i] = outputSHCoeffs[i] *_FogDimmer; | ||
_ScratchBuffer[i] = asuint(outputSHCoeffs[i] *_FogDimmer); | ||
} | ||
|
||
// Apply CornetteShank phase function | ||
float3 zh; | ||
GetCornetteShanksPhaseFunction(zh, _FogAnisotropy); | ||
ConvolveZonal(result, zh); | ||
ConvolveZonalFromScratchBuffer(zh); | ||
|
||
// Premultiplies the SH with the polynomial coefficients of SH basis functions, | ||
// which avoids using any constants during SH evaluation. | ||
// The resulting evaluation takes the form: | ||
// (c_0 - c_6) + c_1 y + c_2 z + c_3 x + c_4 x y + c_5 y z + c_6 (3 z^2) + c_7 x z + c_8 (x^2 - y^2) | ||
for (i = 0; i < SH_COEFF_COUNT; ++i) | ||
{ | ||
result[i] = result[i] * kSHBasisCoef[i % 9]; | ||
_ScratchBuffer[i] = asuint(asfloat(_ScratchBuffer[i]) * kSHBasisCoef[i % 9]); | ||
} | ||
|
||
PackSH(_VolumetricAmbientProbeOutputBuffer, result); | ||
PackSHFromScratchBuffer(_VolumetricAmbientProbeOutputBuffer); | ||
#endif | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*on all platforms
Many platform do support typed loads on other formats