skybox pass separation for single vs double output

This commit is contained in:
antonmic
2021-05-07 20:56:40 -07:00
parent 1f3d0beb38
commit 24aa0f8521
8 changed files with 113 additions and 15 deletions
@@ -305,7 +305,7 @@
},
{
"Name": "SkyBoxPass",
"TemplateName": "SkyBoxTemplate",
"TemplateName": "SkyBoxTwoOutputsTemplate",
"Enabled": true,
"Connections": [
{
@@ -315,6 +315,13 @@
"Attachment": "SpecularInputOutput"
}
},
{
"LocalSlot": "ReflectionInputOutput",
"AttachmentRef": {
"Pass": "ReflectionsPass",
"Attachment": "ReflectionOutput"
}
},
{
"LocalSlot": "SkyBoxDepth",
"AttachmentRef": {
@@ -331,8 +338,8 @@
{
"LocalSlot": "ReflectionInput",
"AttachmentRef": {
"Pass": "ReflectionsPass",
"Attachment": "ReflectionOutput"
"Pass": "SkyBoxPass",
"Attachment": "ReflectionInputOutput"
}
},
{
@@ -92,6 +92,10 @@
"Name": "SkyBoxTemplate",
"Path": "Passes/SkyBox.pass"
},
{
"Name": "SkyBoxTwoOutputsTemplate",
"Path": "Passes/SkyBox_TwoOutputs.pass"
},
{
"Name": "UIPassTemplate",
"Path": "Passes/UI.pass"
@@ -12,6 +12,11 @@
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "ReflectionInputOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "SkyBoxDepth",
"SlotType": "InputOutput",
@@ -0,0 +1,43 @@
{
"Type": "JsonSerialization",
"Version": 1,
"ClassName": "PassAsset",
"ClassData": {
"PassTemplate": {
"Name": "SkyBoxTwoOutputsTemplate",
"PassClass": "FullScreenTriangle",
"Slots": [
{
"Name": "SpecularInputOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "ReflectionInputOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "SkyBoxDepth",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "DepthStencil"
}
],
"PassData": {
"$type": "FullscreenTrianglePassData",
"ShaderAsset": {
"FilePath": "shaders/skybox/skybox_twooutputs.shader"
},
"PipelineViewTag": "MainCamera",
"ShaderDataMappings": {
"FloatMappings": [
{
"Name": "m_sunIntensityMultiplier",
"Value": 1.0
}
]
}
}
}
}
}
@@ -53,22 +53,13 @@ PSOutput MainPS(VSOutput IN)
uint width, height, samples;
PassSrg::m_reflection.GetDimensions(width, height, samples);
float nonZeroSamples = 0.0f;
for (uint sampleIndex = 0; sampleIndex < samples; ++sampleIndex)
{
float3 reflectionSample = PassSrg::m_reflection.Load(IN.m_position.xy, sampleIndex).rgb;
if(any(reflectionSample))
{
reflection += reflectionSample;
nonZeroSamples += 1.0f;
}
}
if(nonZeroSamples != 0.0f)
{
reflection /= nonZeroSamples;
reflection += PassSrg::m_reflection.Load(IN.m_position.xy, sampleIndex).rgb;
}
reflection /= samples;
PSOutput OUT;
OUT.m_color = float4(reflection, 1.0f);
return OUT;
@@ -10,6 +10,11 @@
*
*/
// Static Options:
//
// SKYBOX_TWO_OUTPUTS - Allows the skybox to render to two rendertargets instead of one
#include <Atom/Features/ColorManagement/TransformColor.azsli>
#include <Atom/Features/PostProcessing/FullscreenVertexUtil.azsli>
#include <Atom/Features/MatrixUtility.azsli>
@@ -102,6 +107,9 @@ float3 GetCubemapCoords(float3 original)
struct PSOutput
{
float4 m_specular : SV_Target0;
#ifdef SKYBOX_TWO_OUTPUTS
float4 m_reflection : SV_Target1;
#endif
};
PSOutput MainPS(VSOutput input)
@@ -162,5 +170,8 @@ PSOutput MainPS(VSOutput input)
PSOutput OUT;
OUT.m_specular = float4(color, 1.0);
#ifdef SKYBOX_TWO_OUTPUTS
OUT.m_reflection = float4(color, 1.0);
#endif
return OUT;
}
@@ -0,0 +1,15 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#define SKYBOX_TWO_OUTPUTS
#include "SkyBox.azsl"
@@ -0,0 +1,22 @@
{
"Source" : "SkyBox_TwoOutputs",
"DepthStencilState" : {
"Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" }
},
"ProgramSettings":
{
"EntryPoints":
[
{
"name": "MainVS",
"type": "Vertex"
},
{
"name": "MainPS",
"type": "Fragment"
}
]
}
}