浏览代码

Minor shader optimization

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
d72cae5f
共有 5 个文件被更改,包括 31 次插入16 次删除
  1. 1
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  2. 2
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset
  3. 40
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  4. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader
  5. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader

1
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


CoreUtils.SetKeyword(cmd, "_MAIN_LIGHT_COOKIE", mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
CoreUtils.SetKeyword (cmd, "_MAIN_DIRECTIONAL_LIGHT", mainLightIndex == -1 || visibleLights[mainLightIndex].lightType == LightType.Directional);
CoreUtils.SetKeyword (cmd, "_MAIN_SPOT_LIGHT", mainLightIndex != -1 && visibleLights[mainLightIndex].lightType == LightType.Spot);
CoreUtils.SetKeyword (cmd, "_MAIN_POINT_LIGHT", mainLightIndex != -1 && visibleLights[mainLightIndex].lightType == LightType.Point);
CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SHADOWMASK", m_MixedLightingSetup == MixedLightingSetup.ShadowMask);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive);

2
ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset


m_EditorClassIdentifier:
m_MaxAdditionalPixelLights: 4
m_SupportsVertexLight: 0
m_SupportSoftParticles: 1
m_SupportSoftParticles: 0
m_MSAA: 4
m_RenderScale: 1
m_ShadowType: 1

40
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


#define SAMPLE_METALLICSPECULAR(uv) tex2D(_MetallicGlossMap, uv)
#endif
CBUFFER_START(MaterialProperties)
half4 _MainTex_ST;
sampler2D _MainTex; half4 _MainTex_ST;
sampler2D _MetallicGlossMap;
sampler2D _SpecGlossMap;
sampler2D _BumpMap;
sampler2D _OcclusionMap;
sampler2D _EmissionMap;
CBUFFER_END
sampler2D _MainTex;
sampler2D _MetallicGlossMap;
sampler2D _SpecGlossMap;
sampler2D _BumpMap;
sampler2D _OcclusionMap;
sampler2D _EmissionMap;
struct LightweightVertexInput
{

#endif
half3 viewDir : TEXCOORD5;
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
#if defined(EVALUATE_SH_VERTEX) || defined(EVALUATE_SH_MIXED)
#ifndef LIGHTMAP_ON
///////////////////////////////////////////////////////////////////////////////
// Material Property Helpers //
///////////////////////////////////////////////////////////////////////////////
inline half Alpha(half albedoAlpha)
{
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)

outSurfaceData.alpha = Alpha(albedoAlpha.a);
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
// Vertex: Used for Standard and StandardSimpleLighting shaders
LightweightVertexOutput LitPassVertex(LightweightVertexInput v)
{
LightweightVertexOutput o = (LightweightVertexOutput)0;

o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
float3 positionWS = mul(unity_ObjectToWorld, v.vertex).xyz;
half3 viewDirectionWS = SafeNormalize(_WorldSpaceCameraPos - positionWS);
float4 positionWS = mul(unity_ObjectToWorld, v.vertex);
half3 viewDirectionWS = SafeNormalize(_WorldSpaceCameraPos - positionWS.xyz);
#if _NORMALMAP
OutputTangentToWorld(v.tangent, v.normal, o.tangent, o.binormal, o.normal);

float4 clipPos = UnityObjectToClipPos(v.vertex);
float4 clipPos = mul(UNITY_MATRIX_VP, positionWS);
#if defined(EVALUATE_SH_VERTEX) || defined(EVALUATE_SH_MIXED)
#ifndef LIGHTMAP_ON
o.fogFactorAndVertexLight.yzw = VertexLighting(positionWS, o.normal);
o.fogFactorAndVertexLight.yzw = VertexLighting(positionWS.xyz, o.normal);
o.fogFactorAndVertexLight.x = ComputeFogFactor(clipPos.z);
o.clipPos = clipPos;

// Used for Standard shader
half4 LitPassFragment(LightweightVertexOutput IN) : SV_Target
{
SurfaceData surfaceData;

return OUTPUT_COLOR(color);
}
// Used for StandardSimpleLighting shader
half4 LitPassFragmentSimple(LightweightVertexOutput IN) : SV_Target
{
float2 uv = IN.uv01.xy;

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader


#pragma vertex ParticlesLitVertex
#pragma fragment ParticlesLitFragment
#pragma multi_compile __ SOFTPARTICLES_ON
#pragma multi_compile _MAIN_DIRECTIONAL_LIGHT _MAIN_SPOT_LIGHT _MAIN_POINT_LIGHT
#pragma multi_compile _MAIN_DIRECTIONAL_LIGHT _MAIN_SPOT_LIGHT
#pragma target 3.5
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader


#pragma shader_feature _EMISSION
#pragma multi_compile _ _MAIN_LIGHT_COOKIE
#pragma multi_compile _MAIN_DIRECTIONAL_LIGHT _MAIN_SPOT_LIGHT _MAIN_POINT_LIGHT
#pragma multi_compile _MAIN_DIRECTIONAL_LIGHT _MAIN_SPOT_LIGHT
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE _MIXED_LIGHTING_SHADOWMASK
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON

正在加载...
取消
保存