浏览代码

Fixed an issue in vertex lighting.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
4e6c2856
共有 2 个文件被更改,包括 28 次插入15 次删除
  1. 28
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  2. 15
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc

28
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


half grazingTerm;
};
half SpecularReflectivity(half3 specular)
half ReflectivitySpecular(half3 specular)
// SM2.0: simplified SpecularStrength
return specular.r; // Red channel - because most metals are either monocrhome or with redish/yellowish tint
#else
return max(max(specular.r, specular.g), specular.b);

inline void InitializeBRDFData(half3 albedo, half metallic, half3 specular, half smoothness, half alpha, out BRDFData outBRDFData)
half OneMinusReflectivityMetallic(half metallic)
#ifdef _SPECULAR_SETUP
half reflectivity = SpecularReflectivity(specular);
outBRDFData.diffuse = albedo * (half3(1.0h, 1.0h, 1.0h) - specular);
outBRDFData.specular = specular;
#else
// 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;
return oneMinusDielectricSpec - metallic * oneMinusDielectricSpec;
}
inline void InitializeBRDFData(half3 albedo, half metallic, half3 specular, half smoothness, half alpha, out BRDFData outBRDFData)
{
#ifdef _SPECULAR_SETUP
half reflectivity = ReflectivitySpecular(specular);
half oneMinusReflectivity = 1.0 - reflectivity;
outBRDFData.diffuse = albedo * (half3(1.0h, 1.0h, 1.0h) - specular);
outBRDFData.specular = specular;
#else
half oneMinusReflectivity = OneMinusReflectivityMetallic(metallic);
half reflectivity = 1.0 - oneMinusReflectivity;
outBRDFData.diffuse = albedo * oneMinusReflectivity;

#ifdef _ALPHAPREMULTIPLY_ON
outBRDFData.diffuse *= alpha;
alpha = reflectivity + alpha * (1.0 - reflectivity);
alpha = alpha * oneMinusReflectivity + reflectivity;
#endif
}

15
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


#endif
#if _VERTEX_LIGHTS
diffuseGI += IN.fogFactorAndVertexLight.yzw;
#if _SPECULAR_SETUP
// monochrome reflectivity for vertex to save ALU. Most metals are redish/yellowish
half3 diffuse = surfaceData.albedo * (1.0 - ReflectivitySpecular(surfaceData.specular));
#else
half3 diffuse = surfaceData.albedo * OneMinusReflectivityMetallic(surfaceData.metallic);
#endif
diffuseGI += (diffuse * IN.fogFactorAndVertexLight.yzw);
#endif
float fogFactor = IN.fogFactorAndVertexLight.x;

half3 lightDirection;
#if defined(LIGHTMAP_ON)
half3 color = SampleLightmap(lightmapUV, normalWorld) * diffuse;
half3 color = SampleLightmap(lightmapUV, normalWorld);
half3 color = EvaluateSHPerPixel(normalWorld, IN.vertexSH) * diffuse;
half3 color = EvaluateSHPerPixel(normalWorld, IN.vertexSH);
color = (color + IN.fogFactorAndVertexLight.yzw) * diffuse;
half shininess = _Shininess * 128.0h;

#endif // _ADDITIONAL_LIGHTS
color += Emission(uv);
color += IN.fogFactorAndVertexLight.yzw;
// Computes Fog Factor per vextex
ApplyFog(color, IN.fogFactorAndVertexLight.x);

正在加载...
取消
保存