浏览代码

More PR fixes

- Change sampling offset to uniform and remove shader pass
- Change Scale 1 to point filtering
- Change Scale 0.5 to bilinear filtering
- Add bilinear 0.25 scale option
- Add DrawAnimatedPopup method
/LW-DistortionPass
Matt Dean 7 年前
当前提交
500dc7e2
共有 4 个文件被更改,包括 30 次插入38 次删除
  1. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 12
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  3. 19
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  4. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightSampling.shader

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


public enum TextureScale
{
One,
Half,
Quarter
OnePoint = 0,
HalfBilinear,
QuarterBox,
QuarterBilinear
}
public enum DefaultMaterialType

[SerializeField] private bool m_RequireDepthTexture = false;
[SerializeField] private bool m_RequireSoftParticles = false;
[SerializeField] private bool m_RequireOpaqueTexture = false;
[SerializeField] private TextureScale m_OpaqueTextureScale = TextureScale.Half;
[SerializeField] private TextureScale m_OpaqueTextureScale = TextureScale.HalfBilinear;
[SerializeField] private bool m_SupportsHDR = false;
[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] private float m_RenderScale = 1.0f;

12
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs


public static string[] shadowTypeOptions = {"No Shadows", "Hard Shadows", "Hard and Soft Shadows"};
public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
public static string[] opaqueTextureScaleOptions = {"One (Point)", "Half (Bilinear)", "Quarter (Box)", "Quarter (Bilinear)"};
}
AnimBool m_ShowSoftParticles = new AnimBool();

m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;
m_ShowOpaqueTextureScale.valueChanged.AddListener(Repaint);
m_ShowOpaqueTextureScale.value = m_OpaqueTextureScaleProp.boolValue;
m_ShowOpaqueTextureScale.value = m_RequireOpaqueTextureProp.boolValue;
}
void OnDisable()

EditorGUILayout.PropertyField(prop, content);
}
void DrawAnimatedPopup(SerializedProperty prop, GUIContent content, string[] options, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
CoreEditorUtils.DrawPopup(content, prop, options);
}
public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(m_RequireDepthTextureProp, Styles.requireDepthTexture);
DrawAnimatedProperty(m_RequireSoftParticlesProp, Styles.requireSoftParticles, m_ShowSoftParticles);
EditorGUILayout.PropertyField(m_RequireOpaqueTextureProp, Styles.requireOpaqueTexture);
DrawAnimatedProperty(m_OpaqueTextureScaleProp, Styles.opaqueTextureScale, m_ShowOpaqueTextureScale);
DrawAnimatedPopup(m_OpaqueTextureScaleProp, Styles.opaqueTextureScale, Styles.opaqueTextureScaleOptions, m_ShowOpaqueTextureScale);
EditorGUILayout.PropertyField(m_HDR, Styles.hdrContent);
EditorGUILayout.PropertyField(m_MSAA, Styles.msaaContent);

19
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private RenderTargetIdentifier m_CopyDepth;
private RenderTargetIdentifier m_Color;
private RenderTargetIdentifier m_OpaqueRT;
private float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f};
private float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f};
private bool m_IntermediateTextureArray;
private bool m_RequireDepthTexture;

private Material m_ErrorMaterial;
private Material m_ScreenSpaceShadowsMaterial;
private Material m_SamplingMaterial;
private int m_SampleOffset;
private int m_BlitTexID = Shader.PropertyToID("_BlitTex");
private CopyTextureSupport m_CopyTextureSupport;

CameraRenderTargetID.depth = Shader.PropertyToID("_CameraDepthTexture");
CameraRenderTargetID.depthCopy = Shader.PropertyToID("_CameraCopyDepthTexture");
CameraRenderTargetID.opaque = Shader.PropertyToID("_CameraOpaqueTexture");
m_SampleOffset = Shader.PropertyToID("_SampleOffset");
m_ShadowMapRT = new RenderTargetIdentifier(m_ShadowMapRTID);
m_ScreenSpaceShadowMapRT = new RenderTargetIdentifier(m_ScreenSpaceShadowMapRTID);

RenderTextureDescriptor opaqueDesc = CreateRTDesc(frameRenderingConfiguration, opaqueScaler);
CommandBuffer cmd = CommandBufferPool.Get("Opaque Copy");
cmd.GetTemporaryRT(CameraRenderTargetID.opaque, opaqueDesc, FilterMode.Bilinear);
cmd.GetTemporaryRT(CameraRenderTargetID.opaque, opaqueDesc, m_Asset.OpaqueTextureScale == TextureScale.OnePoint ? FilterMode.Point : FilterMode.Bilinear);
case TextureScale.One:
case TextureScale.OnePoint:
case TextureScale.Half:
case TextureScale.HalfBilinear:
cmd.Blit(m_CurrCameraColorRT, CameraRenderTargetID.opaque);
break;
case TextureScale.QuarterBox:
m_SamplingMaterial.SetFloat(m_SampleOffset, 2);
case TextureScale.Quarter:
cmd.Blit(m_CurrCameraColorRT, CameraRenderTargetID.opaque, m_SamplingMaterial, 1);
case TextureScale.QuarterBilinear:
cmd.Blit(m_CurrCameraColorRT, CameraRenderTargetID.opaque);
break;
}
SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);

28
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightSampling.shader


SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
half4 FragBoxDownsample(Interpolators i) : SV_Target
{
half4 col = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy, 1.0);
return half4(col.rgb, 1);
}
ENDHLSL
}
// 1 - 2x Downsample - Box filtering
Pass
{
Tags { "LightMode" = "LightweightForward"}
ZTest Always
ZWrite Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma vertex Vertex
#pragma fragment FragBoxDownsample
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
float _SampleOffset;
half4 col = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy, 2.0);
half4 col = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy, _SampleOffset);
return half4(col.rgb, 1);
}
ENDHLSL

正在加载...
取消
保存