浏览代码

Update SurfaceData to match ShaderGraph layout

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
bb4866a1
共有 3 个文件被更改,包括 36 次插入26 次删除
  1. 37
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  2. 8
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc
  3. 17
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc

37
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc


float2 uv = i.uv01.xy;
half4 albedoAlpha = tex2D(_MainTex, uv);
half4 specGloss = MetallicSpecGloss(uv, albedoAlpha);
outSurfaceData.alpha = Alpha(albedoAlpha.a);
outSurfaceData.metallicSpecGloss = MetallicSpecGloss(uv, albedoAlpha);
#if _METALLIC_SETUP
outSurfaceData.specular = half4(1.0h, 1.0h, 1.0h, 1.0h);
outSurfaceData.metallic = specGloss.r;
#else
outSurfaceData.specular = specGloss.rgb;
outSurfaceData.metallic = 1.0h;
#endif
outSurfaceData.smoothness = specGloss.a;
outSurfaceData.ao = OcclusionLW(uv);
outSurfaceData.occlusion = OcclusionLW(uv);
outSurfaceData.alpha = Alpha(albedoAlpha.a);
}
inline void InitializeBRDFData(SurfaceData surfaceData, out BRDFData outBRDFData)

half2 metallicGloss = surfaceData.metallicSpecGloss.ra;
half metallic = metallicGloss.r;
half smoothness = metallicGloss.g;
// We'll need oneMinusReflectivity, so
// 1-reflectivity = 1-lerp(dielectricSpec, 1, metallic) = lerp(1-dielectricSpec, 0, metallic)
// store (1-dielectricSpec) in kDieletricSpec.a, then

half oneMinusReflectivity = oneMinusDielectricSpec - metallic * oneMinusDielectricSpec;
half oneMinusReflectivity = oneMinusDielectricSpec - surfaceData.metallic * oneMinusDielectricSpec;
outBRDFData.specular = lerp(kDieletricSpec.rgb, surfaceData.albedo, metallic);
outBRDFData.specular = lerp(kDieletricSpec.rgb, surfaceData.albedo, surfaceData.metallic);
half3 specular = surfaceData.metallicSpecGloss.rgb;
half smoothness = surfaceData.metallicSpecGloss.a;
half reflectivity = SpecularReflectivity(specular);
half reflectivity = SpecularReflectivity(surfaceData.specular);
outBRDFData.diffuse = surfaceData.albedo * (half3(1.0h, 1.0h, 1.0h) - specular);
outBRDFData.specular = specular;
outBRDFData.diffuse = surfaceData.albedo * (half3(1.0h, 1.0h, 1.0h) - surfaceData.specular);
outBRDFData.specular = surfaceData.specular;
outBRDFData.grazingTerm = saturate(smoothness + reflectivity);
outBRDFData.perceptualRoughness = 1.0h - smoothness;
outBRDFData.grazingTerm = saturate(surfaceData.smoothness + reflectivity);
outBRDFData.perceptualRoughness = 1.0h - surfaceData.smoothness;
outBRDFData.roughness = outBRDFData.perceptualRoughness * outBRDFData.perceptualRoughness;
#ifdef _ALPHAPREMULTIPLY_ON

8
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc


struct SurfaceData
{
half3 albedo;
half alpha;
half4 metallicSpecGloss;
half3 specular;
half metallic;
half smoothness;
half ao;
half occlusion;
half alpha;
};
struct BRDFData

17
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;

o.fogCoord.yzw = SHEvalLinearL2(half4(normal, 1.0));
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
half4 LitPassFragment(LightweightVertexOutput i) : SV_Target
half4 LightweightFragmentPBR(LightweightVertexOutput i, SurfaceData surfaceData)
SurfaceData surfaceData;
InitializeSurfaceData(i, surfaceData);
BRDFData brdfData;
InitializeBRDFData(surfaceData, brdfData);

half roughness2 = brdfData.roughness * brdfData.roughness;
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, normal, reflectVec, surfaceData.ao, brdfData.perceptualRoughness);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, normal, reflectVec, surfaceData.occlusion, brdfData.perceptualRoughness);
// PBS
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));

color += surfaceData.emission;
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, surfaceData.alpha);
}
half4 LitPassFragment(LightweightVertexOutput i) : SV_Target
{
SurfaceData surfaceData;
InitializeSurfaceData(i, surfaceData);
return LightweightFragmentPBR(i, surfaceData);
}
half4 LitPassFragmentSimple(LightweightVertexOutput i) : SV_Target

正在加载...
取消
保存