Last active
September 17, 2020 10:57
-
-
Save Dandarawy/74ccc5f3e12c668743e3cd5f422eb278 to your computer and use it in GitHub Desktop.
Unity URP shader based gamma correction (Step 1.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) | |
{ | |
#if UNITY_COLORSPACE_GAMMA | |
half gamma =2.2; | |
#endif | |
half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)); | |
outSurfaceData.alpha = Alpha(albedoAlpha.a, _BaseColor, _Cutoff); | |
half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a); | |
outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb; | |
#if UNITY_COLORSPACE_GAMMA | |
specGloss.rgb = pow(specGloss.rgb, half3(gamma, gamma, gamma)); | |
outSurfaceData.albedo= pow(outSurfaceData.albedo, half3(gamma, gamma, gamma)); | |
#endif | |
#if _SPECULAR_SETUP | |
outSurfaceData.metallic = 1.0h; | |
outSurfaceData.specular = specGloss.rgb; | |
#else | |
outSurfaceData.metallic = specGloss.r; | |
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h); | |
#endif | |
outSurfaceData.smoothness = specGloss.a; | |
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale); | |
outSurfaceData.occlusion = SampleOcclusion(uv); | |
outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap)); | |
#if UNITY_COLORSPACE_GAMMA | |
outSurfaceData.occlusion = pow(outSurfaceData.occlusion, half3(gamma, gamma, gamma)); | |
outSurfaceData.emission = pow(outSurfaceData.emission, half3(gamma, gamma, gamma)); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment