浏览代码

add mipindex for blit + add a separate sahder resources

/main
sebastienlagarde 7 年前
当前提交
3623b5e1
共有 8 个文件被更改,包括 150 次插入46 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
  2. 39
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  4. 32
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/Blit.shader
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  7. 111
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BlitMipFlip.shader
  8. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BlitMipFlip.shader.meta

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs


newAsset.cameraMotionVectors = Load<Shader>(HDRenderPipelinePath + "RenderPipelineResources/CameraMotionVectors.shader");
newAsset.copyStencilBuffer = Load<Shader>(HDRenderPipelinePath + "RenderPipelineResources/CopyStencilBuffer.shader");
newAsset.blit = Load<Shader>(HDRenderPipelinePath + "RenderPipelineResources/Blit.shader");
newAsset.blitFlipMip = Load<Shader>(HDRenderPipelinePath + "RenderPipelineResources/BlitFlipMip.shader");
// Sky
newAsset.blitCubemap = Load<Shader>(HDRenderPipelinePath + "Sky/BlitCubemap.shader");

39
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


Material m_DebugFullScreen;
Material m_DebugColorPicker;
Material m_Blit;
Material m_BlitFlipMip;
Material m_ErrorMaterial;
// Various buffer

m_DebugFullScreen = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.debugFullScreenShader);
m_DebugColorPicker = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.debugColorPickerShader);
m_Blit = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.blit);
m_BlitFlipMip = CoreUtils.CreateEngineMaterial(m_Asset.renderPipelineResources.blitFlipMip);
m_ErrorMaterial = CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader");
}

CoreUtils.Destroy(m_DebugFullScreen);
CoreUtils.Destroy(m_DebugColorPicker);
CoreUtils.Destroy(m_Blit);
CoreUtils.Destroy(m_BlitFlipMip);
CoreUtils.Destroy(m_ErrorMaterial);
m_SSSBufferManager.Cleanup();

// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, cmd);
RenderPyramidDepth(camera, cmd, renderContext, FullScreenDebugMode.DepthPyramid);
RenderPyramidDepth(hdCamera, cmd, renderContext, FullScreenDebugMode.DepthPyramid);
if (m_CurrentDebugDisplaySettings.IsDebugMaterialDisplayEnabled())

RenderForward(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.PreRefraction);
RenderForwardError(m_CullResults, camera, renderContext, cmd, ForwardPass.PreRefraction);
RenderGaussianPyramidColor(camera, cmd, renderContext, true);
RenderGaussianPyramidColor(hdCamera, cmd, renderContext, true);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(m_CullResults, hdCamera, renderContext, cmd, ForwardPass.Transparent);

RenderTransparentDepthPostpass(m_CullResults, camera, renderContext, cmd, ForwardPass.Transparent);
RenderGaussianPyramidColor(camera, cmd, renderContext, false);
RenderGaussianPyramidColor(hdCamera, cmd, renderContext, false);
AccumulateDistortion(m_CullResults, hdCamera, renderContext, cmd);
RenderDistortion(cmd, m_Asset.renderPipelineResources, hdCamera);

}
}
void RenderGaussianPyramidColor(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, bool isPreRefraction)
void RenderGaussianPyramidColor(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, bool isPreRefraction)
{
if (isPreRefraction)
{

cmd.SetGlobalVector(HDShaderIDs._GaussianPyramidColorMipSize, new Vector4(pyramidSideSize, pyramidSideSize, lodCount, 0));
cmd.SetGlobalTexture(HDShaderIDs._BlitTexture, m_CameraColorBufferRT);
cmd.SetGlobalTexture(HDShaderIDs._MainTex, m_CameraColorBufferRT);
CoreUtils.DrawFullScreen(cmd, m_Blit, m_GaussianPyramidColorBufferRT, null, 1); // Bilinear filtering
var last = m_GaussianPyramidColorBuffer;

last = HDShaderIDs._GaussianPyramidColorMips[i + 1];
}
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, lodCount, m_GaussianPyramidColorBufferDesc, isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, lodCount, m_GaussianPyramidColorBufferDesc, hdCamera, isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
cmd.SetGlobalTexture(HDShaderIDs._GaussianPyramidColorTexture, m_GaussianPyramidColorBuffer);

}
}
void RenderPyramidDepth(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
void RenderPyramidDepth(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
{
using (new ProfilingSample(cmd, "Pyramid Depth", CustomSamplerId.PyramidDepth.GetSampler()))
{

cmd.CopyTexture(HDShaderIDs._DepthPyramidMips[i + 1], 0, 0, m_DepthPyramidBufferRT, 0, i + 1);
}
PushFullScreenDebugDepthMip(cmd, m_DepthPyramidBufferRT, lodCount, m_DepthPyramidBufferDesc, debugMode);
PushFullScreenDebugDepthMip(cmd, m_DepthPyramidBufferRT, lodCount, m_DepthPyramidBufferDesc, hdCamera, debugMode);
cmd.SetGlobalTexture(HDShaderIDs._DepthPyramidTexture, m_DepthPyramidBuffer);

// RenderDebug() is call after the final pass that flip the screen (if we are not SceneView).
// Mean that when we push the buffer here, we need to flip it to display correctly.
bool flipY = hdCamera.camera.cameraType != CameraType.SceneView;
cmd.Blit(textureID, m_DebugColorPickerRT, m_Blit, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flip
m_BlitFlipMip.SetFloat(HDShaderIDs._MipIndex, 0);
cmd.Blit(textureID, m_DebugColorPickerRT, m_BlitFlipMip, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flip
}
}

// RenderDebug() is call after the final pass that flip the screen (if we are not SceneView).
// Mean that when we push the buffer here, we need to flip it to display correctly.
bool flipY = hdCamera.camera.cameraType != CameraType.SceneView;
cmd.Blit(textureID, m_DebugFullScreenTempRT, m_Blit, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flipY
m_BlitFlipMip.SetFloat(HDShaderIDs._MipIndex, 0);
cmd.Blit(textureID, m_DebugFullScreenTempRT, m_BlitFlipMip, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flipY
void PushFullScreenDebugTextureMip(CommandBuffer cmd, RenderTargetIdentifier textureID, int lodCount, RenderTextureDescriptor desc, FullScreenDebugMode debugMode)
void PushFullScreenDebugTextureMip(CommandBuffer cmd, RenderTargetIdentifier textureID, int lodCount, RenderTextureDescriptor desc, HDCamera hdCamera, FullScreenDebugMode debugMode)
{
if (debugMode == m_CurrentDebugDisplaySettings.fullScreenDebugMode)
{

desc.height = desc.height >> mipIndex;
CoreUtils.CreateCmdTemporaryRT(cmd, m_DebugFullScreenTempRT, desc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.CopyTexture(textureID, 0, mipIndex, m_DebugFullScreenTempRT, 0, 0); // TODO: Support tex arrays
// TODO: TexArray
bool flipY = hdCamera.camera.cameraType != CameraType.SceneView;
m_BlitFlipMip.SetFloat(HDShaderIDs._MipIndex, mipIndex);
cmd.Blit(textureID, m_DebugFullScreenTempRT, m_BlitFlipMip, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flipY
void PushFullScreenDebugDepthMip(CommandBuffer cmd, RenderTargetIdentifier textureID, int lodCount, RenderTextureDescriptor desc, FullScreenDebugMode debugMode)
void PushFullScreenDebugDepthMip(CommandBuffer cmd, RenderTargetIdentifier textureID, int lodCount, RenderTextureDescriptor desc, HDCamera hdCamera, FullScreenDebugMode debugMode)
{
if (debugMode == m_CurrentDebugDisplaySettings.fullScreenDebugMode)
{

desc.height = desc.height >> mipIndex;
CoreUtils.CreateCmdTemporaryRT(cmd, m_DebugFullScreenTempRT, desc, 0, FilterMode.Point, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
cmd.CopyTexture(textureID, 0, mipIndex, m_DebugFullScreenTempRT, 0, 0); // TODO: Support tex arrays
// TODO: TexArray
bool flipY = hdCamera.camera.cameraType != CameraType.SceneView;
m_BlitFlipMip.SetFloat(HDShaderIDs._MipIndex, mipIndex);
cmd.Blit(textureID, m_DebugFullScreenTempRT, m_BlitFlipMip, flipY ? 2 : 0); // 2 is nearest filtering and flip the image on Y, 1 is without flipY
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _DebugFullScreenTexture = Shader.PropertyToID("_DebugFullScreenTexture");
public static readonly int _BlitTexture = Shader.PropertyToID("_BlitTexture");
public static readonly int _MainTex = Shader.PropertyToID("_MainTex");
public static readonly int _MipIndex = Shader.PropertyToID("_MipIndex");
public static readonly int _WorldScales = Shader.PropertyToID("_WorldScales");
public static readonly int _FilterKernels = Shader.PropertyToID("_FilterKernels");

32
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/Blit.shader


return SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.texcoord);
}
float4 FragNearestFlipY(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D(_BlitTexture, sampler_PointClamp, float2(input.texcoord.x, 1.0 - input.texcoord.y));
}
float4 FragBilinearFlipY(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, float2(input.texcoord.x, 1.0 - input.texcoord.y));
}
ENDHLSL
SubShader

HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinear
ENDHLSL
}
// 2: Nearest + flipY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearestFlipY
ENDHLSL
}
// 3: Bilinear + flipY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinearFlipY
ENDHLSL
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


cameraMotionVectors: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, type: 3}
copyStencilBuffer: {fileID: 4800000, guid: 3d1574f1cdfa0ce4995f9bc79ed7f8ec, type: 3}
blit: {fileID: 4800000, guid: 370f7a9cc4e362d488af024d371091e8, type: 3}
blitFlipMip: {fileID: 4800000, guid: ef092fc4aaa1bb546a9ab4e457c4b07a, type: 3}
blitCubemap: {fileID: 4800000, guid: d05913e251bed7a4992c921c62e1b647, type: 3}
buildProbabilityTables: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c,
type: 3}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader cameraMotionVectors;
public Shader copyStencilBuffer;
public Shader blit;
public Shader blitFlipMip;
// Sky
public Shader blitCubemap;

111
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BlitMipFlip.shader


Shader "Hidden/HDRenderPipeline/BlitMipFlip"
{
Properties
{
_MainTex("Texture", any) = "" {} // Name it like in internal-BlitCopy so we can reuse the shader with Blit command
_MipIndex("MipIndex", Float) = 0
}
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../ShaderVariables.hlsl"
TEXTURE2D(_MainTex); // Name it like in internal-BlitCopy so we can reuse the shader with Blit command
SamplerState sampler_PointClamp;
SamplerState sampler_LinearClamp;
float _MipIndex;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
float4 FragNearest(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_PointClamp, input.texcoord, _MipIndex);
}
float4 FragBilinear(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_LinearClamp, input.texcoord, _MipIndex);
}
float4 FragNearestFlipY(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_PointClamp, float2(input.texcoord.x, 1.0 - input.texcoord.y), _MipIndex);
}
float4 FragBilinearFlipY(Varyings input) : SV_Target
{
return SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_LinearClamp, float2(input.texcoord.x, 1.0 - input.texcoord.y), _MipIndex);
}
ENDHLSL
SubShader
{
// 0: Nearest
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
// 1: Bilinear
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinear
ENDHLSL
}
// 2: Nearest + flipY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearestFlipY
ENDHLSL
}
// 3: Bilinear + flipY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinearFlipY
ENDHLSL
}
}
Fallback Off
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BlitMipFlip.shader.meta


fileFormatVersion: 2
guid: ef092fc4aaa1bb546a9ab4e457c4b07a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存