Trying to compile my project with custom shaders results in the Unity IDE crashing during build process.
I've got two custom shaders for terrain that seems to be the root of the problem.
What I've done:
- Checked error logs, reports access violation in Unity.exe, with stacktrace pointing to BuildPlayerRenderPipeline
- Changed shader of terrains to Nature->Terrain->Diffuse. This works fine.
- Run Unity Editor as admin, no change.
- No error codes on Shader code in Editor
See the attached (most critical) shader below.
The second one is very similar.
Shader "Custom/HueTerrainShader"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
_Color("Alpha Color Key", Color) = (0,0,0,1)
_HeightMin("Height Min", Float) = -1
_HeightMax("Height Max", Float) = 100
_HSVRangeMin("HSV Affect Range Min", Range(0, 1)) = 0
_HSVRangeMax("HSV Affect Range Max", Range(0, 1)) = 1
_HSVAAdjust("HSVA Adjust", Vector) = (0, 0, 0, 0)
_Opacity("Opacity", Float) = 1
}
SubShader
{
Tags { "RenderType"="Opaque" }
//LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
uniform float _HeightMin;
uniform float _HeightMax;
float4 _Color;
float _HSVRangeMin;
float _HSVRangeMax;
float4 _HSVAAdjust;
float _Opacity;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
};
float3 rgb2hsv(float3 c) {
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c) {
c = float3(c.x, clamp(c.yz, 0.0, 1.0));
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void surf(Input IN, inout SurfaceOutput o)
{
/*
Hue vs h values:
Red: hue = 0, hsv.x = 0, h = 1 --> highest point on map
Blue: hue = 240, hsv.x = 240/360, h = 0 --> lowest point on map
Everything in between, go from hue = 240 -> 0, h = 0 -> 1, hsv.x = (1 - h)(*240/360)
*/
float3 hsv = rgb2hsv(_Color.rgb);
float affectMult = step(_HSVRangeMin, hsv.r) * step(hsv.r, _HSVRangeMax);
float h = (_HeightMax - IN.worldPos.y) / (_HeightMax);
hsv.y += _HSVAAdjust.y;
hsv.z += _HSVAAdjust.z;
hsv.x = h*(240.0f / 360.0f);
float3 rgb = hsv2rgb(hsv);
o.Albedo = rgb;
o.Alpha = _Opacity;
}
ENDCG
}
FallBack "Diffuse"
}
question from:
https://stackoverflow.com/questions/65945171/build-crash-with-custom-shader-unity-exe-access-violation