浏览代码

LinearGamma conversions added based on Pipeline keyword.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
8ec89a38
共有 5 个文件被更改,包括 24 次插入5 次删除
  1. 4
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetInspector.cs
  2. 5
      Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  3. 7
      Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.cs
  4. 1
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
  5. 12
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc

4
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetInspector.cs


public static GUIContent renderingLabel = new GUIContent("Rendering");
public static GUIContent shadowLabel = new GUIContent("Shadows");
public static GUIContent defaults = new GUIContent("Defaults");
public static GUIContent linearRenderingLabel = new GUIContent("Linear Colorspace", "When enabled Lightweight shader will perform gamma to linear conversion when linear rendering is not supported or disabled");
public static GUIContent maxPixelLights = new GUIContent("Per-Object Pixel Lights",
"Max amount of dynamic per-object pixel lights.");

public static GUIContent msaaContent = new GUIContent("Anti Aliasing", "Controls the global anti aliasing quality. When set to disabled, MSAA will not be performed even if the camera allows it.");
}
private SerializedProperty m_LinearRenderingProperty;
private SerializedProperty m_MaxPixelLights;
private SerializedProperty m_SupportsVertexLightProp;
private SerializedProperty m_EnableLightmapsProp;

void OnEnable()
{
m_LinearRenderingProperty = serializedObject.FindProperty("m_LinearRendering");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");
m_EnableLightmapsProp = serializedObject.FindProperty("m_EnableLightmaps");

EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.renderingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LinearRenderingProperty, Styles.linearRenderingLabel);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.maxPixelLights);
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxPixelLights.intValue, 0, 4);

5
Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


private void SetShaderKeywords(CommandBuffer cmd, bool renderShadows, bool singleDirecitonal, bool vertexLightSupport)
{
if (m_Asset.ForceLinearRendering)
cmd.EnableShaderKeyword("LIGHTWEIGHT_LINEAR");
else
cmd.DisableShaderKeyword("LIGHTWEIGHT_LINEAR");
if (vertexLightSupport)
cmd.EnableShaderKeyword("_VERTEX_LIGHTS");
else

7
Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.cs


[SerializeField] private ShadowCascades m_ShadowCascades = ShadowCascades.NO_CASCADES;
[SerializeField] private float m_Cascade2Split = 0.25f;
[SerializeField] private Vector3 m_Cascade4Split = new Vector3(0.067f, 0.2f, 0.467f);
[SerializeField] private bool m_LinearRendering = true;
[SerializeField] private Material m_DefaultDiffuseMaterial;
[SerializeField] private Material m_DefaultParticleMaterial;

{
get { return m_Cascade4Split; }
private set { m_Cascade4Split = value; }
}
public bool ForceLinearRendering
{
get { return m_LinearRendering; }
set { m_LinearRendering = value; }
}
#endregion

1
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader


#pragma shader_feature _EMISSION
#pragma shader_feature _ _REFLECTION_CUBEMAP _REFLECTION_PROBE
#pragma multi_compile _ LIGHTWEIGHT_LINEAR
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ _LIGHT_PROBES_ON

12
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#define _SHADOW_CASCADES
#endif
#if (defined(UNITY_COLORSPACE_GAMMA) || SHADER_TARGET < 30) && defined(LIGHTWEIGHT_FORCE_LINEAR)
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR)
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine
//#define LIGHTWEIGHT_GAMMA_TO_LINEAR(gammaColor) gammaColor * gammaColor
//#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linColor) sqrt(color)

inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss)
{
#ifdef _SPECGLOSSMAP
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss = tex2D(_SpecGlossMap, uv);
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR)
specularGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb);
#endif
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, uv).rgb) * _SpecColor.rgb;
specularGloss.a = alpha;
#else
specularGloss = _SpecColor;

half NdotL = saturate(dot(normal, lightDir));
half3 diffuse = diffuseColor * NdotL;
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * pow(NdotH, _Shininess * 128.0) * specularGloss.a;

正在加载...
取消
保存