浏览代码

Initial integration of Post-FX V2 MSVO to LW

/projects-TheLastStand
John 7 年前
当前提交
afae267f
共有 3 个文件被更改,包括 79 次插入0 次删除
  1. 48
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  2. 16
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.hlsl
  3. 15
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/InputSurface.hlsl

48
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


Subtractive,
};
public static class AdvancedFeatureIDs
{
//SSAO
//############################################
public static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture");
public static readonly int _AmbientOcclusionParam = Shader.PropertyToID("_AmbientOcclusionParam");
//############################################
}
public static class CameraRenderTargetID
{
// Camera color target. Not used when camera is rendering to backbuffer or camera

context.SetupCameraProperties(m_CurrCamera, stereoEnabled);
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPass))
{
//<<< MSVO BEGIN
RenderMSVO(ref context);
//>>> MSVO END
}
ForwardPass(visibleLights, frameRenderingConfiguration, ref context, ref lightData, stereoEnabled);
// Release temporary RT

context.Submit();
}
}
//<<< MSVO BEGIN
private void RenderMSVO(ref ScriptableRenderContext context)
{
if(m_CameraPostProcessLayer == null) return;
CommandBuffer cmd = CommandBufferPool.Get("MSVO");
var settings = m_CameraPostProcessLayer.GetSettings<AmbientOcclusion>();
if(settings.IsEnabledAndSupported(null))
{
cmd.GetTemporaryRT(AdvancedFeatureIDs._AmbientOcclusionTexture, new RenderTextureDescriptor(m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, RenderTextureFormat.R8, 0)
{
sRGB = false,
enableRandomWrite = true
}, FilterMode.Bilinear);
m_CameraPostProcessLayer.BakeMSVOMap(cmd, m_CurrCamera, AdvancedFeatureIDs._AmbientOcclusionTexture, m_DepthRT, true);
cmd.SetGlobalVector(AdvancedFeatureIDs._AmbientOcclusionParam, new Vector4(settings.color.value.r, settings.color.value.g, settings.color.value.b, settings.directLightingStrength.value));
}
else
{
cmd.SetGlobalTexture(AdvancedFeatureIDs._AmbientOcclusionTexture, RuntimeUtilities.blackTexture); // Neutral is black, see the comment in the shaders
cmd.SetGlobalVector(AdvancedFeatureIDs._AmbientOcclusionParam, Vector4.zero);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
//>>> MSVO END
private void ShadowPass(VisibleLight[] visibleLights, ref ScriptableRenderContext context, ref LightData lightData)
{

16
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.hlsl


half3 viewDir : TEXCOORD6;
half4 fogFactorAndVertexLight : TEXCOORD7; // x: fogFactor, yzw: vertex light
//<<< MSVO BEGIN
float4 screenUV : TEXCOORD8;
//>>> MSVO END
float4 clipPos : SV_POSITION;
};

half fogFactor = ComputeFogFactor(o.clipPos.z);
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
//<<< MSVO BEGIN
o.screenUV = o.clipPos * 0.5f;
o.screenUV.xy = float2(o.screenUV.x, o.screenUV.y * -1) + o.screenUV.w;
o.screenUV.zw = o.clipPos.zw;
//>>> MSVO END
return o;
}

half3 indirectDiffuse = SampleGI(IN.lightmapUVOrVertexSH, normalWS);
float fogFactor = IN.fogFactorAndVertexLight.x;
//<<< MSVO BEGIN
//TODO: Work with JP to properly apply this AO term.
// For now just roll into texture ao so it takes part in proper lighting calculations
surfaceData.occlusion *= MSVO(IN.screenUV);
//>>> MSVO END
half4 color = LightweightFragmentPBR(IN.posWS.xyz, normalWS, IN.viewDir, indirectDiffuse, IN.fogFactorAndVertexLight.yzw, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);

15
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/InputSurface.hlsl


half _Shininess;
CBUFFER_END
//<<< MSVO BEGIN
TEXTURE2D(_AmbientOcclusionTexture); SAMPLER(sampler_AmbientOcclusionTexture);
CBUFFER_START(UnityAmbientOcclusionParameters)
float4 _AmbientOcclusionParam;
CBUFFER_END
//>>> MSVO END
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap);
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap);

return 1.0;
#endif
}
//<<< MSVO BEGIN
half MSVO(float4 uv)
{
return 1.0 - SAMPLE_TEXTURE2D(_AmbientOcclusionTexture, sampler_AmbientOcclusionTexture, uv.xy / uv.w).x;
}
//>>> MSVO END
half3 Emission(float2 uv)
{

正在加载...
取消
保存