浏览代码

Merge pull request #1077 from Unity-Technologies/backport/lw-optimizations-backport

Backport/lw optimizations backport
/2018.1
GitHub 7 年前
当前提交
cbfce342
共有 7 个文件被更改,包括 31 次插入17 次删除
  1. 5
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl
  2. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Core.hlsl
  3. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurface.hlsl
  4. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Lighting.hlsl
  5. 19
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
  6. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl
  7. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader

5
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl


return normalize(normal);
}
real3 UnpackNormalRGBNoScale(real4 packedNormal)
{
return packedNormal.rgb * 2.0 - 1.0;
}
real3 UnpackNormalAG(real4 packedNormal, real scale = 1.0)
{
real3 normal;

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Core.hlsl


half3 UnpackNormal(half4 packedNormal)
{
// Compiler will optimize the scale away
return UnpackNormalRGB(packedNormal, 1.0);
return UnpackNormalRGBNoScale(packedNormal);
// Compiler will optimize the scale away
return UnpackNormalmapRGorAG(packedNormal, 1.0);
#endif
}

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurface.hlsl


half3 Normal(float2 uv)
{
#if _NORMALMAP
return UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv), _BumpScale);
#if BUMP_SCALE_NOT_SUPPORTED
return UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv));
#else
return UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv), _BumpScale);
#endif
#else
return half3(0.0h, 0.0h, 1.0h);
#endif

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Lighting.hlsl


{
half3 halfVec = SafeNormalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specularReflection = specularGloss.rgb * pow(NdotH, shininess) * specularGloss.a;
half modifier = pow(NdotH, shininess) * specularGloss.a;
half3 specularReflection = specularGloss.rgb * modifier;
return lightColor * specularReflection;
}

}
#endif
half3 finalColor = diffuseColor * diffuse + emission;
finalColor += inputData.vertexLighting * diffuse;
half3 fullDiffuse = diffuseColor + inputData.vertexLighting;
half3 finalColor = fullDiffuse * diffuse + emission;
#if defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
finalColor += specularColor;

19
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl


{
float2 uv : TEXCOORD0;
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1);
float3 posWS : TEXCOORD2;
float4 posWSShininess : TEXCOORD2; // xyz: posWS, w: Shininess * 128
half4 binormal : TEXCOORD5; // xyz: binormal, w: viewDir.w
half4 binormal : TEXCOORD5; // xyz: binormal, w: viewDir.z
#else
half3 normal : TEXCOORD3;
half3 viewDir : TEXCOORD6;

void InitializeInputData(LightweightVertexOutput IN, half3 normalTS, out InputData inputData)
{
inputData.positionWS = IN.posWS.xyz;
inputData.positionWS = IN.posWSShininess.xyz;
half3 viewDir = half3(IN.tangent.w, IN.binormal.w, IN.normal.w);
half3 viewDir = half3(IN.normal.w, IN.tangent.w, IN.binormal.w);
inputData.normalWS = TangentToWorldNormal(normalTS, IN.tangent.xyz, IN.binormal.xyz, IN.normal.xyz);
#else
half3 viewDir = IN.viewDir;

o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.posWS = TransformObjectToWorld(v.vertex.xyz);
o.clipPos = TransformWorldToHClip(o.posWS);
o.posWSShininess.xyz = TransformObjectToWorld(v.vertex.xyz);
o.posWSShininess.w = _Shininess * 128.0;
o.clipPos = TransformWorldToHClip(o.posWSShininess.xyz);
half3 viewDir = GetCameraPositionWS() - o.posWS;
half3 viewDir = GetCameraPositionWS() - o.posWSShininess.xyz;
#if !SHADER_HINT_NICE_QUALITY
// Normalize in vertex and avoid renormalizing it in frag to save ALU.
viewDir = SafeNormalize(viewDir);

OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUV);
OUTPUT_SH(o.normal.xyz, o.vertexSH);
half3 vertexLight = VertexLighting(o.posWS, o.normal.xyz);
half3 vertexLight = VertexLighting(o.posWSShininess.xyz, o.normal.xyz);
half fogFactor = ComputeFogFactor(o.clipPos.z);
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
o.shadowCoord = ComputeShadowCoord(o.clipPos);

half3 emission = Emission(uv);
half4 specularGloss = SpecularGloss(uv, diffuseAlpha.a);
half shininess = _Shininess * 128.0h;
half shininess = IN.posWSShininess.w;
InputData inputData;
InitializeInputData(IN, normalTS, inputData);

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl


float scale = invNdotL * _ShadowBias.y;
// normal bias is negative since we want to apply an inset normal offset
o.posWS = o.normal * scale.xxx + o.posWS;
float4 clipPos = TransformWorldToHClip(o.posWS);
o.posWSShininess.xyz = o.normal * scale.xxx + o.posWSShininess.xyz;
float4 clipPos = TransformWorldToHClip(o.posWSShininess.xyz);
// _ShadowBias.x sign depens on if platform has reversed z buffer
clipPos.z += _ShadowBias.x;

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader


#pragma vertex LitPassVertex
#pragma fragment LitPassFragmentSimple
#define BUMP_SCALE_NOT_SUPPORTED 1
#include "LWRP/ShaderLibrary/LightweightPassLit.hlsl"
ENDHLSL
}

#pragma vertex ShadowPassVertex
#pragma fragment LitPassFragmentSimpleNull
#define BUMP_SCALE_NOT_SUPPORTED 1
#include "LWRP/ShaderLibrary/LightweightPassShadow.hlsl"
ENDHLSL
}

#pragma vertex LitPassVertex
#pragma fragment LitPassFragmentSimpleNull
#define BUMP_SCALE_NOT_SUPPORTED 1
#include "LWRP/ShaderLibrary/LightweightPassLit.hlsl"
ENDHLSL
}

正在加载...
取消
保存