Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static class ShaderProperty

private enum LightCookieShaderFormat
{
None = -1,

RGB = 0,
Alpha = 1,
Red = 2
Expand Down Expand Up @@ -580,6 +582,13 @@ bool SetupMainLight(CommandBuffer cmd, ref VisibleLight visibleMainLight)
cmd.SetGlobalMatrix(ShaderProperty.mainLightWorldToLight, cookieMatrix);
cmd.SetGlobalFloat(ShaderProperty.mainLightCookieTextureFormat, cookieFormat);
}
else
{
// Make sure we erase stale data in case the main light is disabled but cookie system is enabled (for additional lights).
cmd.SetGlobalTexture(ShaderProperty.mainLightTexture, Texture2D.whiteTexture);
cmd.SetGlobalMatrix(ShaderProperty.mainLightWorldToLight, Matrix4x4.identity);
cmd.SetGlobalFloat(ShaderProperty.mainLightCookieTextureFormat, (float)LightCookieShaderFormat.None);
}

return isMainLightCookieEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ float2 ComputeLightCookieUVDirectional(float4x4 worldToLight, float3 samplePosit
{
// Translate and rotate 'positionWS' into the light space.
// Project point to light "view" plane, i.e. discard Z.
float2 positionLS = mul(worldToLight, float4(samplePositionWS, 1)).xy;
float2 positionLS = mul(worldToLight, float4(samplePositionWS, 1)).xy;

// Remap [-1, 1] to [0, 1]
// (implies the transform has ortho projection mapping world space box to [-1, 1])
Expand Down Expand Up @@ -70,6 +70,9 @@ float2 ComputeLightCookieUVPoint(float4x4 worldToLight, float3 samplePositionWS,

real3 SampleMainLightCookie(float3 samplePositionWS)
{
if(!IsMainLightCookieEnabled())
return real3(1,1,1);

float2 uv = ComputeLightCookieUVDirectional(_MainLightWorldToLight, samplePositionWS, float4(1, 1, 0, 0), URP_TEXTURE_WRAP_MODE_NONE);
real4 color = SampleMainLightCookieTexture(uv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ real4 SampleAdditionalLightsCookieAtlasTexture(float2 uv)
}

// Helpers
bool IsMainLightCookieEnabled()
{
return _MainLightCookieTextureFormat != URP_LIGHT_COOKIE_FORMAT_NONE;
}

bool IsLightCookieEnabled(int lightBufferIndex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// Types

#define URP_LIGHT_COOKIE_FORMAT_NONE (-1)
#define URP_LIGHT_COOKIE_FORMAT_RGB (0)
#define URP_LIGHT_COOKIE_FORMAT_ALPHA (1)
#define URP_LIGHT_COOKIE_FORMAT_RED (2)
Expand Down