HLSL Shader gives error, output parameter 'Direction' not completely initialized
Asked Answered
A

3

0

I’ve been following a tutorial over a cel shader and I’ve been getting an error that only I seem to have. The error says,

Shader error in 'Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Assets/Shaders/Lighting.hlsl(1) (on glcore)

The function MainLight_float looks like this:

void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, 
	out float DistanceAtten, out float ShadowAtten)
{

#ifdef SHADERGRAPH_PREVIEW
    Direction = normalize(float3(0.5f, 0.5f, 0.25f));
    Color = float3(1.0f, 1.0f, 1.0f);
    DistanceAtten = 1.0f;
    ShadowAtten = 1.0f;

#else
    float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    Light mainLight = GetMainLight(shadowCoord);
    Direction = mainLight.direction;
    Color = mainLight.color;
    DistanceAtten = mainLight.distanceAttenuation;
    ShadowAtten = mainLight.shadowAttenuation;
#endif
}

I have no idea what to do, as it definitely looks completely initialized to me. Help would be appreciated.

Actinal answered 31/8, 2023 at 6:31 Comment(0)
S
0

I assume this code is a Shadergraph custom function?

Make sure the output parameter Direction has been set to the type Vector3 in Shadergraph Custom function node.

Schoolmate answered 31/8, 2023 at 6:31 Comment(0)
G
0

@Actinal
I’m assuming you are using the function taken from:

One quick question:
Are you using the built-in render pipeline?
If so, then that’s why you are getting that error. Why? Got no idea, but seems that hlsl shaders compile completely different on URP

Godin answered 16/2, 2023 at 21:1 Comment(0)
M
0

If you are using this demo:

The first thing you should do is to install the universal rp package in package manager, create a new urp asset and change your project settings → graphics → scriptable render piprline settings to it.
Then everything works!

Moskowitz answered 31/8, 2023 at 3:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.