Sphere
Log in Join
☆ 13

unity 2022 urp shader keeps failing to compile on build

Shader error in 'Custom/Water': 'AppBuilderGetPos' : cannot map expression to pixel shader instruction set at line 87. That's the error in the console when I build for Windows in Unity 2022.3.14f1 with URP 14.0.9. The shader works fine in the editor and in the preview but the player build fails. I copy-pasted a tutorial shader that uses a vertex-to-fragment struct and I think something about the interpolator count is over the limit. Any idea what actually causes this and how to debug which line is the problem? I've never really written shader code beyond editing existing ones.

⚑ Report

4 replies

☆ 0
M moth ·2026-11-03#1

That error usually means the compiler can't emit an instruction for something you're doing in the fragment stage - often a texture sample with a computed UV or a dynamic loop. Line 87 isn't always the real culprit. Right-click the shader and 'Show Generated Code' and look at what URP is generating around that line. Also check how many interpolators your v2f struct has; URP mobile is strict but desktop shouldn't fail on that.

⚑ Report
☆ 0
C cardboard ·2026-11-05#2

Generated code is huge. I found the line: I'm sampling _CameraDepthTexture with a screen UV computed in the fragment shader using gl_FragCoord.xy / _ScreenParams.xy. That's the texture sample with computed UV thing. In the editor it's fine but the compiler chokes. Is there a way to pass the screen UV from the vertex shader instead?

⚑ Report
☆ 0
R regex ·2026-11-07#3

Yes. Compute it in the vertex shader and pass it as a TEXCOORD in your v2f. But note sampling depth needs the depth texture enabled in the URP asset - turn on 'Depth Texture' or the sample returns garbage. Also _CameraOpaqueTexture if you're doing refraction needs 'Opaque Texture' checked, otherwise you get magenta in the build.

⚑ Report
☆ 0
S stack ·2026-11-11#4

Moved the UV calc to the vertex stage and enabled Depth Texture in the URP renderer asset, build now passes. One more gotcha: in URP 14 sampling depth needs the include 'Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl'. Without that it compiled but sampled black. Anyway, that was my weekend.

⚑ Report
Log in to reply.