Parse error: syntax error, unexpected '}' in line 69 with URP shader.
Asked Answered
U

2

0

I am a beginner in shader programming and I use URP. I wanted to create a raymarching cloud shader and keep getting this error - Parse error: syntax error, unexpected ‘}’ in line 69. I don’t know what to do and any help is very much appreciated. Here is the shader -


Shader "Custom/ProceduralCloudsMobile"
{
    Properties
    {
        _CloudColor("Cloud Color", Color) = (1,1,1,1)
        _ScatterColor("Scatter Color", Color) = (1,1,1,1)
        _ScatterAmount("Scatter Amount", Range(0, 1)) = 0.5
        _CloudDensity("Cloud Density", Range(0, 1)) = 0.5
        _CloudSharpness("Cloud Sharpness", Range(0, 1)) = 0.5
        _CloudSpeed("Cloud Speed", Range(0, 1)) = 0.5
        _CloudScale("Cloud Scale", Range(0, 10)) = 2
        _CloudHeight("Cloud Height", Range(0, 1000)) = 500
        _StepSize("Step Size", Range(0, 1)) = 0.01
        _MaxSteps("Max Steps", Range(0, 100)) = 50
    }

        SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 100

        HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/PBSLights.hlsl"

        float3 GetCloudNoise(float3 pos)
        {
            return cnoise(pos * _CloudScale * _CloudSharpness + _Time.y * _CloudSpeed);
        }

        float SampleCloudDensity(float3 pos)
        {
            return saturate(GetCloudNoise(pos).r * _CloudDensity);
        }

        float SampleScatterAmount(float3 pos)
        {
            return saturate(GetCloudNoise(pos).r * _ScatterAmount);
        }

        void surf(SurfaceOutput o, inout SurfaceInput input)
        {
            // Calculate 3D position of the current pixel in world space
            float3 worldPos = mul(unity_ObjectToWorld, float4(input.uv, 0, 1)).xyz;
            worldPos.y += _CloudHeight;

            // Cast a ray into the scene and sample the cloud density along the ray
            float3 rayDir = normalize(worldPos - _WorldSpaceCameraPos);
            float rayLength = length(worldPos - _WorldSpaceCameraPos);
            float3 rayPos = _WorldSpaceCameraPos;
            float cloudDensity = 0;
            for (int i = 0; i < _MaxSteps; i++)
            {
                cloudDensity += SampleCloudDensity(rayPos) * _StepSize;
                rayPos += rayDir * _StepSize;
                if (cloudDensity >= 1)
                    break;
            }

            // Calculate scatter amount at the final ray position
            float scatterAmount = SampleScatterAmount(rayPos);

            // Blend cloud color and scatter color based on density and scatter amount
            fixed4 cloudColor = lerp(_CloudColor, _ScatterColor, scatterAmount);
            o.Albedo = cloudColor.rgb * cloudDensity;
            o.Alpha = cloudDensity;
        }

        ENDHLSL
    }
}

`

Unilobed answered 17/12, 2022 at 15:21 Comment(0)
S
0

Parse error: syntax error, unexpected
‘}’ in line 69 with URP shader.

This error tells you what the problem is. there is an unexpected ‘}’ on line 69.


brackets come in pairs and opening and closing pair of the same type. What that means is that you have an additional } where there shouldn’t be one. Check that you have the same number of opening and closing curly brackets, check that they are wrapped around the code as you would expect.


Remove any extraneous ones/ add any missing ones and the error will disappear.

Swarm answered 18/12, 2022 at 14:33 Comment(0)
B
0

The main issue here is that you’re trying to use a surface shader within the universal RP, which is no longer supported - you need to be using a vertex/fragment shader. I don’t know too much about surface shaders and nothing about raymarching so can’t be too helpful regarding this part.

If you can refactor your shader to use vertex/fragment functions instead of surface then, as far as the compiler is concerned, it is expecting a Pass block. If you put everything from and including HLSLINCLUDE to ENDHLSL inside “Pass { … }” and add a URP-compatible tags block then this should fix the compiler error, or at least it did for me.

E.g.

Pass {
    Tags { "LightMode" = "UniversalForward" }
    HLSLPROGRAM
    ...
    <your refactored vert/frag shader code>
    ...
    ENDHLSL
}

I appreciate people trying to help but replies are just frustrating when you can see that the brackets are balanced and something else is going on here.

Billboard answered 26/6 at 19:50 Comment(1)

Adding a pass with Tags { "LightMode" = "UniversalForward" } resolved my error, thanks!

Very

© 2022 - 2024 — McMap. All rights reserved.