Search Unity

shader not working in unity 2017

Discussion in 'Shaders' started by gaiastellar, Aug 28, 2017.

  1. gaiastellar

    gaiastellar

    Joined:
    Nov 8, 2013
    Posts:
    57
    hi all,
    i am trying to use this billboard shader from wikibooks - ive seen it used and working on a youtube tutorial (using unity 5x), but i cant get it to work.

    i create a new surface shader, delete the code that is there and paste in the code from wikibooks, compile, and then try to add it to a material.

    the first issue is that all the shader is tagged "cg shader for billboards" in the codes first line, it only shows up in the shader drop down menu as its file name 'new surface shader' under the custom tab.
    secondly and most importantly - it doesnt work - ive applied it to a material but nothing -
    in the youtube video its clear that is does work...
    i dont know whether some of the code has changed in the upgrade from 5x to 2017 but can someone help please?

    the youtube link is:


    and the code is :
    Code (CSharp):
    1. Shader "Cg  shader for billboards" {
    2.    Properties {
    3.       _MainTex ("Texture Image", 2D) = "white" {}
    4.       _ScaleX ("Scale X", Float) = 1.0
    5.       _ScaleY ("Scale Y", Float) = 1.0
    6.    }
    7.    SubShader {
    8.       Pass {  
    9.          CGPROGRAM
    10.          #pragma vertex vert
    11.          #pragma fragment frag
    12.  
    13.          // User-specified uniforms          
    14.          uniform sampler2D _MainTex;      
    15.          uniform float _ScaleX;
    16.          uniform float _ScaleY;
    17.  
    18.          struct vertexInput {
    19.             float4 vertex : POSITION;
    20.             float4 tex : TEXCOORD0;
    21.          };
    22.          struct vertexOutput {
    23.             float4 pos : SV_POSITION;
    24.             float4 tex : TEXCOORD0;
    25.          };
    26.          vertexOutput vert(vertexInput input)
    27.          {
    28.             vertexOutput output;
    29.  
    30.             output.pos = mul(UNITY_MATRIX_P,
    31.               mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
    32.               + float4(input.vertex.x, input.vertex.y, 0.0, 0.0)
    33.               * float4(_ScaleX, _ScaleY, 1.0, 1.0));
    34.             output.tex = input.tex;
    35.  
    36.             return output;
    37.          }
    38.          float4 frag(vertexOutput input) : COLOR
    39.          {
    40.             return tex2D(_MainTex, float2(input.tex.xy));  
    41.          }
    42.          ENDCG
    43.       }
    44.    }
    45. }

    thanks all

    paul uk
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    works here..

    if the shader displays that "new surface shader' name, it means its not saved or compiled,
    that happens with visual studio sometimes (even if press save, it wont), close the shader in vs and save, then it works.
     
  3. gaiastellar

    gaiastellar

    Joined:
    Nov 8, 2013
    Posts:
    57
    hi, thanks... but im using monodevelop - i realise now why none of the custom shaders ive been trying have not worked - none of them have saved or compiled at all - they just compile as new surface shader - thats probably also why they dont show up in the shader drop down list with their tag name - just the file name they were created with. im not sure why this is happening ? i paste the code into the empty shader , hit the compile button on monodevelop, but it seems its not changing the code at all?
    any ideas - this is very frustrating as i need some custom shaders to work?
    thanks for your help

    paul uk
     
  4. gaiastellar

    gaiastellar

    Joined:
    Nov 8, 2013
    Posts:
    57
    hi, thanks but i solved it - in monodevelop, you dont click build, you just 'save', and then back in unity it updates - i havent seen that anywhere, saying how to do that!