浏览代码

Ambient SH done perpixel until we find a proper solution on how to handle it for ShanderGraph

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

16
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


half3 emission;
half occlusion;
half alpha;
half3 ambient;
};
struct SurfaceInput

outSurfaceData.occlusion = 1.0h;
outSurfaceData.emission = half3(0.0h, 0.0h, 0.0h);
outSurfaceData.alpha = 1.0h;
outSurfaceData.ambient = half3(0.0h, 0.0h, 0.0h);
}
half SpecularReflectivity(half3 specular)

return c;
}
UnityIndirect LightweightGI(float4 lightmapUV, half3 ambientColor, half3 normalWorld, half3 reflectVec, half occlusion, half perceptualRoughness)
UnityIndirect LightweightGI(float4 lightmapUV, half3 normalWorld, half3 reflectVec, half occlusion, half perceptualRoughness)
ambientColor += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV.xy)));
o.diffuse += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV.xy))) * occlusion;
ambientColor += SHEvalLinearL0L1(half4(normalWorld, 1.0));
ambientColor = max(half3(0.0, 0.0, 0.0), ambientColor);
o.diffuse = ShadeSH9(half4(normalWorld, 1.0)) * occlusion;
o.diffuse = ambientColor * occlusion;
#ifndef _GLOSSYREFLECTIONS_OFF
Unity_GlossyEnvironmentData g;

half4 LightweightFragmentPBR(half4 lightmapUV, float3 positionWS, half3 normalWS, half3 tangentWS, half3 bitangentWS,
half3 viewDirectionWS, half fogFactor, half3 albedo, half metallic, half3 specular, half smoothness,
half3 normalTS, half ambientOcclusion, half3 emission, half alpha, half3 ambient)
half3 normalTS, half ambientOcclusion, half3 emission, half alpha)
{
BRDFData brdfData;
InitializeBRDFData(albedo, metallic, specular, smoothness, alpha, brdfData);

half3 reflectVec = reflect(-viewDirectionWS, normalWS);
half roughness2 = brdfData.roughness * brdfData.roughness;
UnityIndirect indirectLight = LightweightGI(lightmapUV, ambient, normalWS, reflectVec, ambientOcclusion, brdfData.perceptualRoughness);
UnityIndirect indirectLight = LightweightGI(lightmapUV, normalWS, reflectVec, ambientOcclusion, brdfData.perceptualRoughness);
// PBS
half fresnelTerm = Pow4(1.0 - saturate(dot(normalWS, viewDirectionWS)));

17
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


outSurfaceData.emission = EmissionLW(uv);
outSurfaceData.emission += IN.fogFactorAndVertexLight.yzw;
outSurfaceData.alpha = Alpha(albedoAlpha.a);
#if LIGHTMAP_ON
outSurfaceData.ambient = half4(0.0h, 0.0h, 0.0h, 0.0h);
#else
outSurfaceData.ambient = half4(IN.ambientOrLightmapUV);
#endif
}
void InitializeSurfaceInput(LightweightVertexOutput IN, out SurfaceInput outSurfaceInput)

o.ambientOrLightmapUV.xy = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
// TODO: Dynamic Lightmap
o.ambientOrLightmapUV.zw = float2(0.0, 0.0);
#else
o.ambientOrLightmapUV = half4(SHEvalLinearL2(half4(normal, 1.0)), 0.0h);
// TODO: Currently there's no way to pass in ambient contribution to fragmentPBR.
// We should allow to create custom ambient computation for things like SH evaluation, lightmap, ambient color etc.
//#else
// o.ambientOrLightmapUV = half4(SHEvalLinearL2(half4(normal, 1.0)), 0.0h);
#endif
o.fogFactorAndVertexLight.yzw = half3(0.0h, 0.0h, 0.0h);

SurfaceInput surfaceInput;
InitializeSurfaceInput(IN, surfaceInput);
return LightweightFragmentPBR(surfaceInput.lightmapUV, surfaceInput.positionWS, surfaceInput.normalWS, surfaceInput.tangentWS, surfaceInput.bitangentWS, surfaceInput.viewDirectionWS, surfaceInput.fogFactor, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.normal, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha, surfaceData.ambient);
return LightweightFragmentPBR(surfaceInput.lightmapUV, surfaceInput.positionWS, surfaceInput.normalWS, surfaceInput.tangentWS, surfaceInput.bitangentWS, surfaceInput.viewDirectionWS, surfaceInput.fogFactor, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.normal, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);
}
half4 LitPassFragmentSimple(LightweightVertexOutput IN) : SV_Target

#if defined(LIGHTMAP_ON)
half3 color = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.ambientOrLightmapUV.xy)) * diffuse;
#else
half3 color = (SHEvalLinearL0L1(half4(normalWorld, 1.0)) + IN.ambientOrLightmapUV.xyz) * diffuse;
half3 color = (ShadeSH9(half4(normalWorld, 1.0)) + IN.ambientOrLightmapUV.xyz) * diffuse;
#endif
LightInput lightInput;

正在加载...
取消
保存