#Sampling Additional Shadows In Custom Shader Graph Function

1 messages · Page 1 of 1 (latest)

versed frigate
#
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _SHADOWS_SOFT

#pragma multi_compile _ _ADDITIONAL_LIGHTS

#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RealtimeLights.hlsl"


void SampleShadow_half(float3 WorldPos, out float Value)
{
    float totalShadow = 0.0; //Black

    int additionalLightCount = GetAdditionalLightsCount();
     
    float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);

    Light light = GetMainLight(shadowCoord);

    totalShadow += 1 - light.shadowAttenuation;

    for (int i = 0; i < additionalLightCount; i++)
    {
        Light light = GetAdditionalLight(i, WorldPos);

        totalShadow += 1 - light.shadowAttenuation;
    }


    Value = 1 - saturate(totalShadow);
}

So im having my hand in making a custom toon shader with a custom shadow function for my game, and im running into a roadblock, no matter what I try, I cannot get my additional lights to actually cast shadows, ive updated them to cast shadows in my pipeline asset, ive tried multiplying, adding, and I just cant seem to get it, I wonder if im just missing an include? or maybe something in my graph im not doing correctly?

edgy pollen
#

What do the errors next to the nodes say?

#

You should also check errors in the console and on the shader graph asset.

versed frigate
#

im getting : _AdditionalLightsPosition: Implicit array missing initial value at line 169

but that seems to be coming from an include I have used up top possible?

#

im in an unlit shader but trying to access lighting data which may be it?

#

all other parts of lighting has worked up until now, even the main lighting shadows

#

wait I ahve made progress

#

so apparently the syntax for sampling lights in realtime has significantly changed between pre 6.0 and post 6.0, so now using the
AdditionalLightRealtimeShadow
and
MainLightRealtimeShadow
is now the way to use it?

void SampleShadow_half(float3 WorldPos, out float Value)
{
    float totalShadow = 1.0; //Black

    int additionalLightCount = GetAdditionalLightsCount();
     
    float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);

    totalShadow *= MainLightRealtimeShadow(shadowCoord);

    for (int i = 0; i < additionalLightCount; i++)
    {
        totalShadow *=  AdditionalLightRealtimeShadow(i, WorldPos);
    }


    Value = saturate(totalShadow);
}