浏览代码

Fixed a normalization issue. Fixed keywords not being properly set in SpecularSetup.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
602d1a7c
共有 7 个文件被更改,包括 24 次插入32 次删除
  1. 25
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardShaderGUI.cs
  2. 5
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  3. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
  4. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc
  5. 16
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader
  6. 3
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/024_Shader_PBRvalidation/Adam/Materials/Crowd_LOD0_Mat_Limbs.mat
  7. 3
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/024_Shader_PBRvalidation/Adam/Materials/Crowd_LOD0_Mat_Torso.mat

25
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardShaderGUI.cs


private MaterialProperty uvSetSecondary = null;
private MaterialEditor m_MaterialEditor;
private WorkflowMode m_WorkflowMode = WorkflowMode.Metallic;
private const float kMaxfp16 = 65536f; // Clamp to a value that fits into fp16.
private ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, kMaxfp16, 1 / kMaxfp16, 3f);

// material to a lightweight shader.
if (m_FirstTimeApply)
{
MaterialChanged(material, m_WorkflowMode);
MaterialChanged(material);
m_FirstTimeApply = false;
}

if (EditorGUI.EndChangeCheck())
{
foreach (var obj in blendMode.targets)
MaterialChanged((Material)obj, m_WorkflowMode);
MaterialChanged((Material)obj);
}
EditorGUILayout.Space();

// TODO: material.HasKeyword()?
if (oldShader.name.Equals("Standard (Specular setup)"))
m_WorkflowMode = WorkflowMode.Specular;
material.SetFloat("_WorkflowMode", (float)WorkflowMode.Specular);
m_WorkflowMode = WorkflowMode.Metallic;
material.SetFloat("_WorkflowMode", (float)WorkflowMode.Metallic);
MaterialChanged(material, m_WorkflowMode);
MaterialChanged(material);
}
private void DoPopup(string label, MaterialProperty property, string[] options)

return SmoothnessMapChannel.SpecularMetallicAlpha;
}
static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
static void SetMaterialKeywords(Material material)
bool isSpecularWorkFlow = (WorkflowMode)material.GetFloat("_WorkflowMode") == WorkflowMode.Specular;
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_SETUP", isSpecularWorkFlow);
LightweightShaderHelper.SetKeyword(material, "_METALLIC_SETUP", !isSpecularWorkFlow);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_SETUP", workflowMode == WorkflowMode.Specular);
LightweightShaderHelper.SetKeyword(material, "_METALLIC_SETUP", workflowMode == WorkflowMode.Metallic);
LightweightShaderHelper.SetKeyword(material, "_SPECULARHIGHLIGHTS_ON", material.GetFloat("_SpecularHighlights") > 0.0f);
LightweightShaderHelper.SetKeyword(material, "_GLOSSYREFLECTIONS_ON", material.GetFloat("_GlossyReflections") > 0.0f);
LightweightShaderHelper.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_MetallicSpecGlossMap") != null);

}
}
static void MaterialChanged(Material material, WorkflowMode workflowMode)
static void MaterialChanged(Material material)
SetMaterialKeywords(material, workflowMode);
SetMaterialKeywords(material);
}
}
}

5
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


private RenderTextureFormat m_ColorFormat = RenderTextureFormat.ARGB32;
private PostProcessRenderContext m_PostProcessRenderContext;
// Stores the dieletric F0 (rgb) and (1.0 - dieletricSpec) (alpha) for energy conservation
private Vector4 kDieletricSpecLinear = new Vector4(0.02f, 0.02f, 0.02f, 0.88f);
public LightweightPipeline(LightweightPipelineAsset asset)
{
m_Asset = asset;

cmd.SetGlobalColor("_LightColor", lightColor);
cmd.SetGlobalVector("_LightSpotDir", lightSpotDir);
cmd.SetGlobalVector("_LightAttenuationParams", lightAttenuationParams);
cmd.SetGlobalVector("_DieletricSpec", kDieletricSpecLinear);
if (m_Asset.AttenuationTexture != null) cmd.SetGlobalTexture("_AttenuationTexture", m_Asset.AttenuationTexture);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();

cmd.SetGlobalVectorArray ("globalLightColor", m_LightColors);
cmd.SetGlobalVectorArray ("globalLightAtten", m_LightAttenuations);
cmd.SetGlobalVectorArray ("globalLightSpotDir", m_LightSpotDirections);
cmd.SetGlobalVector("_DieletricSpec", kDieletricSpecLinear);
if (m_Asset.AttenuationTexture != null) cmd.SetGlobalTexture("_AttenuationTexture", m_Asset.AttenuationTexture);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#define LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
#endif
#define _DieletricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04) // standard dielectric reflectivity coef at incident angle (= 4%)
half SpecularReflectivity(half3 specular)
{
#if (SHADER_TARGET < 30)

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc


// glsl compiler will generate underperforming code by using a row-major pre multiplication matrix: mul(normalmap, i.tangentToWorld)
// i.tangetToWorld was initialized as column-major in vs and here dot'ing individual for better performance.
// The code below is similar to post multiply: mul(i.tangentToWorld, normalmap)
normal = half3(dot(normalmap, i.tangentToWorld0), dot(normalmap, i.tangentToWorld1), dot(normalmap, i.tangentToWorld2));
normal = normalize(half3(dot(normalmap, i.tangentToWorld0), dot(normalmap, i.tangentToWorld1), dot(normalmap, i.tangentToWorld2)));
#else
normal = normalize(i.normal);
#endif

16
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader


#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = normalize(UnityObjectToWorldDir(v.tangent));
half3 tangent = UnityObjectToWorldDir(v.tangent);
half3 binormal = cross(normal, tangent) * sign;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code

// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
// GI
#ifdef _METALLICGLOSSMAP
// grazingTerm = F90
#else
half grazingTerm = i.viewDir.w;
#endif
half perVertexFresnelTerm = i.posWS.w;
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, grazingTerm, perVertexFresnelTerm);
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS

#endif
color += Emission(uv);
//UNITY_APPLY_FOG(i.fogCoord, color);
//color = (normal + 1.0) * 0.5;
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
}

3
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/024_Shader_PBRvalidation/Adam/Materials/Crowd_LOD0_Mat_Limbs.mat


m_PrefabInternal: {fileID: 0}
m_Name: Crowd_LOD0_Mat_Limbs
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_ShaderKeywords: _METALLIC_SETUP _NORMALMAP _SPECGLOSSMAP
m_ShaderKeywords: _GLOSSYREFLECTIONS_ON _METALLICSPECGLOSSMAP _METALLIC_SETUP _NORMALMAP
_SPECULARHIGHLIGHTS_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

3
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/024_Shader_PBRvalidation/Adam/Materials/Crowd_LOD0_Mat_Torso.mat


m_PrefabInternal: {fileID: 0}
m_Name: Crowd_LOD0_Mat_Torso
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_ShaderKeywords: _EMISSION _METALLIC_SETUP _NORMALMAP _SPECGLOSSMAP
m_ShaderKeywords: _EMISSION _GLOSSYREFLECTIONS_ON _METALLICSPECGLOSSMAP _METALLIC_SETUP
_NORMALMAP _SPECULARHIGHLIGHTS_ON
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

正在加载...
取消
保存