I’m using Unity 2021.2.0b16.
I’m also almost completely new to shaders, so there’s that.
I’m trying to rewrite a shader graph into a shader since I need to do some things which I can’t in shader graph
The shader graph I made used a custom function(from a youtube tutorial), and it needs a reference to
ShaderLibrary/Shadows.hlsl
The problem is, when I try to include shadows.hlsl, it gives a redefinition error of ‘PackHeightmap’ in Common.hlsl if I include UnityCG.cginc, and a redefinition error of ‘_Time’ in UnityInput.hlsl (which happens even if I only include shadows.hlsl)
Am I doing something wrong?
There’s more information about literally anything else on the internet than this.
#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED
void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color,
out half DistanceAtten, out half ShadowAtten) {
#ifdef SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = mainLight.shadowAttenuation;
#endif
}
#endif
Also note that this function works completely fine in Shader Graph.