Search Unity

Resolved Shader error in 'Unlit/MyShader': redefinition of 'VertexOutput' at line 43 (on d3d11)

Discussion in 'Universal Render Pipeline' started by Para00100, Apr 28, 2022.

  1. Para00100

    Para00100

    Joined:
    Apr 22, 2022
    Posts:
    48
    Hi all, I am totally new to Unity, URP and shaders and have basic knowledge in programming.

    For a school project i would need to implement compute, vertex, fragment and surface shader in URP.

    As a good practice I have done now the following tutorial:
    .
    But unfortunately I am not able to assign the newly written shader to my Material as its not available there due to the following error: "Shader error in 'Unlit/MyShader': redefinition of 'VertexOutput' at line 43 (on d3d11)"

    Can anyone help me and suggest how to fix or what I did wrong?

    This is the shader code (using Unity 2021.3 with URP):

    Shader "Unlit/MyShader"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Tags { "RenderType"="Opaque" }
    LOD 100

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

    CBUFFER_START(UnityPerMaterial)
    float4 _BaseColor;

    CBUFFER_END

    TEXTURE2D(_MainTex);
    SAMPLER(sampler_MainTex);

    struct VertexInput
    {
    float4 position : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct VertexOutput
    {
    float4 position : SV_POSITION;
    float2 uv : TEXCOORD0;
    }

    ENDHLSL

    Pass
    {
    HLSLPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    VertexOutput vert(VertexInput i)
    {
    VertexOutput o;
    o.position = TransformObjectToHClip(i.position.xyz);
    o.uv = i.uv;

    return o;
    }

    float4 frag(VertexOutput i) : SV_Target
    {
    float4 baseTex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);

    return baseTex * _BaseColor;
    }

    ENDHLSL


    }
    }
    }
     
  2. Para00100

    Para00100

    Joined:
    Apr 22, 2022
    Posts:
    48
    i have resolved it now.
     
  3. Pizzaman90001

    Pizzaman90001

    Joined:
    Jul 26, 2022
    Posts:
    1
    How did you resolve this?
     
  4. cmo

    cmo

    Joined:
    Aug 10, 2012
    Posts:
    13
    I'm pretty sure it's in the ten commandments or smth to not comment "I fixed it!" with no details.

    The easiest solution without actually knowing anything about shaders is to just rename the instances of the redefinition error variable throughout the script.
     
  5. wechat_os_Qy09b-SqgzL8yayR77VaHQNA4

    wechat_os_Qy09b-SqgzL8yayR77VaHQNA4

    Joined:
    Aug 29, 2023
    Posts:
    1
    Thanks a lot!It did help
     
  6. adilwaheed848

    adilwaheed848

    Joined:
    May 3, 2021
    Posts:
    1
    Man Thanks alot you are a life saver! I made a game but for a certain reason i upgraded from unity version 2022.3.17f to 2022.3.22f1 and after opening the project the shader asset got corrupted somehow, reimporting didnt help at all. Then I did what you just said and voila magically all errors went away and its working perfectly. Thanks alot!