skip to Main Content

So currently i created a new project, and created a lit/standard surface shader, i do not change anything in the code and create a material from it. When applying this material to an object it becomes purple, which usually means there is something wrong. However i cannot find out what, visual studio nor visual code nor unity return an error. I’ve applied the texture, i have checked all packages, i have tried on 2021.3.5f, 2022.1.9f1, and 2022.2.8f1.
I have also check project settings, i am on 3d urp, and there is a scriptable renderer pipeline asset connected and also the universal renderer pipeline global settings is connected.

As mentioned before, it is purely the starting code, but here it is anyways:

(I did add a texture to the material, just a simple black and white texture)

Shader "Custom/TestShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Anyone knows anything that might fix this problem?

2

Answers


  1. Chosen as BEST ANSWER

    So after a bit of research, it looks like that shadergraph/shaders had an update, and creating a shader via the window that unity provides does not work anymore. As someone mentioned in the comments, it is possible to make a shadergraph shader, compile it and work from there, however its 5000 lines of code.

    The method im using right now, is the custom node in unity, it can now (when i last used it about 2 years ago, it was still very basic) hold almost all your shader code that you original would put in a shader script. So you either can write all your code in 1 custom node, or split up the functionality so you can use it in different shader graphs. For me this is actually perfect as i like shader graph but some functionalities were not possible before with just shader graph.


  2. The shader is incompatible with the universal render pipeline.
    When you create a new lit shader you get the boilerplate code for a shader that is intended to work with the default Unity render that does not involve a render pipeline.

    The currently prefered method of creating a custom shader for URP is via Shader Graph. If you for some reason don’t like the visual representation you can always compile it and work on the shader in text form.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search