Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Image/Raw Image Material works in scene, not in game. Possible bug?

Discussion in 'UGUI & TextMesh Pro' started by DMeville, May 13, 2015.

  1. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Maybe I'm doing something wrong, but I can easily reproduce this. Using version 5.0.1f1. I read through the latest patch notes and didn't see anything relating to this issue, maybe I'll try updating anyways.

    I have a Raw Image component with no texture, and a material. This material has a Texture set on it, and displays this texture. The material is using a custom shader, but testing shows this doesn't work with the built in shaders either. Is there something specific that a UI shader needs to get working properly? I've also noticed that this Raw Image with material doesn't work with the mask component (it's simply ignored by the mask).

    I've attached three images showing what's going on. First is the scene view, then the game view, and a screenshot of the UI inspector.

    EDIT: After trying to figure this out for a bit I found out that if the Canvas Render mode is set to either "Screen Space - Camera" or "World Space" both my default button and Raw Image show up. However setting the Canvas Render Mode to "Screen Space - Overlay" the Raw Image disappears, but the button is still visible (as seen in the screenshot below). How can I get this working on all Render Modes?

    Seems like this same bug: http://issuetracker.unity3d.com/iss...stom-shaders-does-not-render-in-the-game-view

    Shader code below.
    Code (CSharp):
    1. // Shader created with Shader Forge v1.13
    2. // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
    3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    4. /*SF_DATA;ver:1.13;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,nrsp:0,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,rprd:False,enco:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,bsrc:3,bdst:7,culm:0,dpts:2,wrdp:False,dith:0,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:1,x:33312,y:32712,varname:node_1,prsc:2|custl-2-RGB,alpha-6266-OUT;n:type:ShaderForge.SFN_Tex2d,id:2,x:32769,y:32787,ptovrint:False,ptlb:MainTexture,ptin:_MainTexture,varname:node_3880,prsc:2,ntxv:0,isnm:False;n:type:ShaderForge.SFN_OneMinus,id:6266,x:32987,y:32971,varname:node_6266,prsc:2|IN-2-A;proporder:2;pass:END;sub:END;*/
    5.  
    6. Shader "DMMap/DMMap" {
    7.     Properties {
    8.         _MainTexture ("MainTexture", 2D) = "white" {}
    9.         [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    10.     }
    11.     SubShader {
    12.         Tags {
    13.             "IgnoreProjector"="True"
    14.             "Queue"="Transparent"
    15.             "RenderType"="Transparent"
    16.         }
    17.         Pass {
    18.             Name "FORWARD"
    19.             Tags {
    20.                 "LightMode"="ForwardBase"
    21.             }
    22.             Blend SrcAlpha OneMinusSrcAlpha
    23.             ZWrite Off
    24.      
    25.             CGPROGRAM
    26.             #pragma vertex vert
    27.             #pragma fragment frag
    28.             #define UNITY_PASS_FORWARDBASE
    29.             #include "UnityCG.cginc"
    30.             #pragma multi_compile_fwdbase
    31.             #pragma multi_compile_fog
    32.             #pragma exclude_renderers xbox360 ps3
    33.             #pragma target 3.0
    34.             uniform sampler2D _MainTexture; uniform float4 _MainTexture_ST;
    35.             struct VertexInput {
    36.                 float4 vertex : POSITION;
    37.                 float2 texcoord0 : TEXCOORD0;
    38.             };
    39.             struct VertexOutput {
    40.                 float4 pos : SV_POSITION;
    41.                 float2 uv0 : TEXCOORD0;
    42.                 UNITY_FOG_COORDS(1)
    43.             };
    44.             VertexOutput vert (VertexInput v) {
    45.                 VertexOutput o = (VertexOutput)0;
    46.                 o.uv0 = v.texcoord0;
    47.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    48.                 UNITY_TRANSFER_FOG(o,o.pos);
    49.                 return o;
    50.             }
    51.             float4 frag(VertexOutput i) : COLOR {
    52. /////// Vectors:
    53. ////// Lighting:
    54.                 float4 _MainTexture_var = tex2D(_MainTexture,TRANSFORM_TEX(i.uv0, _MainTexture));
    55.                 float3 finalColor = _MainTexture_var.rgb;
    56.                 fixed4 finalRGBA = fixed4(finalColor,(1.0 - _MainTexture_var.a));
    57.                 UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
    58.                 return finalRGBA;
    59.             }
    60.             ENDCG
    61.         }
    62.     }
    63.     FallBack "Diffuse"
    64.     CustomEditor "ShaderForgeMaterialInspector"
    65. }
    66.  
     

    Attached Files:

    Last edited: May 13, 2015
  2. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    This problem still persists in 5.0.2
     
  3. jonathanvanry

    jonathanvanry

    Joined:
    Nov 14, 2014
    Posts:
    16
    You could try converting it to a different type of image such as JPEG or PNG
     
  4. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    127
    I know .... this is very old but the problem still in 5.3, to solve change the canvas to camera space.
     
    DMeville likes this.
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    I still see this issue on 5.3.3

    As an alternative to above solution, do as below
    "Make sure lighting is off. In case if you have written a surface shader, even you set the lighting off its not working. So, try to create a shader which is unlit (Project view -> Right click ->Shader -> Unlit Shader) - This is normal Cg Shader in unity with out any lighting calculations."

    Cheers,
    VB Team
     
    david_arel likes this.
  6. astralscarf_unity

    astralscarf_unity

    Joined:
    Feb 25, 2020
    Posts:
    2
    This is a SUPER old thread, but if you encounter this error in newer versions of unity with a material made with Shader Graph, try setting the Shader Mode from Unlit to Unlit Sprite in the Shader Graph Inspector!
     
    Mabbsyy, SirGhoul, Mutoky and 4 others like this.
  7. Slock20969

    Slock20969

    Joined:
    Nov 18, 2015
    Posts:
    15
    I appreciate you resurrecting this thread for this info! I was banging my head against the wall!