My shader works completely fine in the editor but once its compiled it turns pink. I’m assuming its just being stripped from the build because in the console I have it print the shader compile logs and it shows this result
my shader variants not being compiled
and this is what it looks like in editor
and in build
I’ve looked through many of peoples posts that have experienced a similar bug. I’ve included the shader in “Always Included Shaders”, “Preloaded Shaders”, Preloaded Assets" and the Resource folder to no success. I’ve also made a material with this shader and included a game object that uses this material in the main menu scene (as depicted in the screenshots).
I’ve included all API targets in the shader asset and only skip unused variants but as you can see it says both variants are included
But in the previous screen shot at the top you can see that both of the variants aren’t made.
I’ve tried just about everything I’ve seen on the forums and still cant fix the issue PLS let me know if you have the solution.
Also my shader code just incase its a code issue
Shader "Custom/VolumeLit"
{
Properties
{
/*[MainTexture]*/_BaseMap ("Texture", 2D) = "white" {}
//_Gain ("Gain", Float) = 1.5
/*[MainColor]*/_Color ("Color", Color) = (1,1,1,1)
//_EdgeColor ("Edge Color", Color) = (0,0,0,1)
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
float4 tangent : TANGENT;
};
struct v2g
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 normal : POSITION1;
float4 world : TEXCOORD2;
};
struct g2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 bary : TEXCOORD1;
float3 normal : POSITION1;
float4 world : TEXCOORD2;
};
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
//float _Gain;
float4 _Color;
//float4 _EdgeColor;
CBUFFER_END
StructuredBuffer<uint> _LightBuffer;
int _CustLightProbeCount;
float4 _LightProbeStart;
float4 _LightProbeVol;
v2g vert (appdata v)
{
v2g o;
o.world = mul(unity_ObjectToWorld, v.vertex);
o.vertex = TransformObjectToHClip(v.vertex.xyz);
o.uv = TRANSFORM_TEX(v.uv, _BaseMap);
o.normal = TransformObjectToWorldNormal(v.normal);
return o;
}
/*float edgeFactor(float3 bary)
{
float3 d = fwidth(bary);
float3 a3 = smoothstep(float3(0, 0, 0), _Gain * d, bary);
return min(min(a3.x, a3.y), a3.z);
}*/
int getindex(int x, int y, int z)
{
//x = clamp(x, 0, _LightProbeVol.x);
//y = clamp(y, 0, _LightProbeVol.y);
//z = clamp(z, 0, _LightProbeVol.z);
if (x >= 0 && y >= 0 && z >= 0 && x < _LightProbeVol.x && y < _LightProbeVol.y && z < _LightProbeVol.z)
return (y * _LightProbeVol.x * _LightProbeVol.z) + (z * _LightProbeVol.x) + x;
else
return -1;
}
half4 getcolor(int index)
{
if (index == -1)
return half4(0,0,0,0);
uint r = asint(_LightBuffer[index] & 0x000000FF);
uint g = asint(_LightBuffer[index] & 0x0000FF00) >> 8;
uint b = asint(_LightBuffer[index] & 0x00FF0000) >> 16;
half4 color = half4(r * 0.003921,g * 0.003921,b * 0.003921, 1);
return color;
}
float3 getdirection(int index)
{
int pitchi = asint(_LightBuffer[index] & 0x0F000000) >> 24;
int yawi = asint(_LightBuffer[index] & 0xF0000000) >> 28;
float pitch = -radians(-(pitchi * 24));
float yaw = radians(-(yawi * 24) - 90);
float3 dir = float3(cos(pitch)*cos(yaw), sin(pitch), cos(pitch) * sin(yaw));
return dir;
}
half4 frag (v2g i) : SV_Target
{
half4 ogcol = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv) * _Color; // tex2D(_MainTex, i.uv)
half4 col = half4(0,0,0,0);
if (_CustLightProbeCount > 0)
{
//float t = fwidth(i.bary);//edgeFactor(i.bary);
//Light mainLight = GetMainLight();
const float maxdistance = 2.0;
const float xzstepdist = 1.205464;
const float ystepdist = 2.410929;
const float xzstepdisthalf = 0.602732;
const float ystepdisthalf = 1.205464;
const float xzscale = 0.8295560; // (1.205464 = meterscale * 64 because the xz index is stepped by 64 quake units then scaled for unity) 1 / 1.205464 doing this bec i think * is faster than /
const float yscale = 0.4147778; // (2.410929 = meterscale * 128 because the y index is stepped by 128 quake units then scaled for unity) 1 / 2.410929
float3 delta = i.world.xyz - _LightProbeStart.xyz;
int xind = floor(delta.x * xzscale);
int zind = floor(delta.z * xzscale);
int yind = floor(delta.y * yscale);
//return normalize(half4(xind, yind, zind, 1));
int index = getindex(xind, yind, zind);
if (index != -1)
{
float3 lightpos = (_LightProbeStart.xyz + float3(xind * xzstepdist, yind * ystepdist, zind * xzstepdist));
//lightpos.x += xzstepdisthalf;
//lightpos.z += xzstepdisthalf;
//lightpos.y += ystepdisthalf;
delta = i.world.xyz - lightpos;
delta.x *= 0.82955608;
delta.z *= 0.82955608;
delta.y *= 0.41477787;
int index1 = getindex(xind + 1, yind, zind);
int index2 = getindex(xind, yind + 1, zind);
int index3 = getindex(xind + 1, yind + 1, zind);
int index4 = getindex(xind, yind, zind + 1);
int index5 = getindex(xind + 1, yind, zind + 1);
int index6 = getindex(xind, yind + 1, zind + 1);
int index7 = getindex(xind + 1, yind + 1, zind + 1);
half4 c000 = getcolor(index);
half4 c100 = getcolor(index1);
half4 c010 = getcolor(index2);
half4 c110 = getcolor(index3);
half4 c001 = getcolor(index4);
half4 c101 = getcolor(index5);
half4 c011 = getcolor(index6);
half4 c111 = getcolor(index7);
half4 color = (1 - delta.x) * (1 - delta.y) * (1 - delta.z) * c000 +
delta.x * (1 - delta.y) * (1 - delta.z) * c100 +
(1 - delta.x) * delta.y * (1 - delta.z) * c010 +
delta.x * delta.y * (1 - delta.z) * c110 +
(1 - delta.x) * (1 - delta.y) * delta.z * c001 +
delta.x * (1 - delta.y) * delta.z * c101 +
(1 - delta.x) * delta.y * delta.z * c011 +
delta.x * delta.y * delta.z * c111;
//return color;
float3 c0002 = getdirection(index);
float3 c1002 = getdirection(index1);
float3 c0102 = getdirection(index2);
float3 c1102 = getdirection(index3);
float3 c0012 = getdirection(index4);
float3 c1012 = getdirection(index5);
float3 c0112 = getdirection(index6);
float3 c1112 = getdirection(index7);
float3 dir = (1 - delta.x) * (1 - delta.y) * (1 - delta.z) * c0002 +
delta.x * (1 - delta.y) * (1 - delta.z) * c1002 +
(1 - delta.x) * delta.y * (1 - delta.z) * c0102 +
delta.x * delta.y * (1 - delta.z) * c1102 +
(1 - delta.x) * (1 - delta.y) * delta.z * c0012 +
delta.x * (1 - delta.y) * delta.z * c1012 +
(1 - delta.x) * delta.y * delta.z * c0112 +
delta.x * delta.y * delta.z * c1112;
half nl = dot(i.normal, dir);
if (nl > 0)
nl = 1;
else
nl = 1 + nl;
half4 diff = nl * color;
diff.w = 1;
diff = max(0, diff);
diff *= ogcol;
col += diff;
col += ogcol * half4(VertexLighting(i.world.xyz, i.normal), 1);
}
}
return col;
}
ENDHLSL
SubShader
{
Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Tags{"LightMode" = "UniversalForward"}
HLSLPROGRAM
#pragma target 2.0
#pragma multi_compile_instancing
#pragma vertex vert
#pragma fragment frag
ENDHLSL
}
}
}
Edit:
Changing #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX
to
#define _ADDITIONAL_LIGHTS_VERTEX
seems to have worked