Search Unity

TV screen shader: unlit shader with meta pass...possible?

Discussion in 'Shaders' started by Jayme65, Mar 16, 2017.

  1. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    Hello,

    I'm using a movie for 'emission' map

    ...and would like to boost the 'emission' power...but if I do so the image itself is overexposed


    Ideally, I would like to be able to use a 'unlit' shader (so that the screen is always perfectly displayed) AND use a meta pass with a intensity slider to be able to boost emission power over 1 !
    Is this possible or is it a total non sense? (shader noob here ;-) )

    Thanks!!
     
  2. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    314
    simple way, you could use a unlit shader to render your TV and use a second mesh to render your emission. The second mesh would be in a layer that is not rendered by your camera, this way you can crank up the emission and the TV would not change, only the light emitted.

    more complex way, make a custom shader that changes the value only in the meta pass, look at the built in standard shader, it has a meta pass you could use.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Probably the best way, yeah.
     
  4. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    Unfortunately, I'm new to all this (including Unity ;)) I've already this piece of code, just missing a slider to boost emission power over 1 ! (as one can do for 'emission' power in the standard shader)

    Code (csharp):
    1.  
    2. Shader "Custom/metaPassShader"{
    3.  
    4.     Properties {
    5.         _Color ("Color", Color)=(1,1,1,1)
    6.         _MainTex ("Albedo (RGB)",2D)="white"{}
    7.         _Glossiness ("Smoothness", Range(0,1))=0.5
    8.         _Metallic ("Metallic", Range(0,1))=0.0
    9.  
    10.         _GIAlbedoColor ("Color Albedo (GI)", Color)=(1,1,1,1)
    11.         _GIAlbedoTex ("Albedo (GI)",2D)="white"{}
    12.     }
    13.  
    14.     SubShader {
    15.     // ------------------------------------------------------------------
    16.     // Extracts information for lightmapping, GI (emission, albedo, ...)
    17.     // This pass is not used during regular rendering.
    18.         Pass
    19.         {
    20.             Name "META"
    21.             Tags {"LightMode"="Meta"}
    22.             Cull Off
    23.             CGPROGRAM
    24.  
    25.             #include"UnityStandardMeta.cginc"
    26.  
    27.             sampler2D _GIAlbedoTex;
    28.             fixed4 _GIAlbedoColor;
    29.             float4 frag_meta2 (v2f_meta i): SV_Target
    30.             {
    31.                 // We're interested in diffuse & specular colors
    32.                 // and surface roughness to produce final albedo.
    33.            
    34.                 FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv);
    35.                 UnityMetaInput o;
    36.                 UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
    37.                 fixed4 c = tex2D (_GIAlbedoTex, i.uv);
    38.                 o.Albedo = fixed3(c.rgb * _GIAlbedoColor.rgb);
    39.                 o.Emission = Emission(i.uv.xy);
    40.                 return UnityMetaFragment(o);
    41.             }
    42.        
    43.             #pragma vertex vert_meta
    44.             #pragma fragment frag_meta2
    45.             #pragma shader_feature _EMISSION
    46.             #pragma shader_feature _METALLICGLOSSMAP
    47.             #pragma shader_feature ___ _DETAIL_MULX2
    48.             ENDCG
    49.         }
    50.    
    51.         Tags {"IgnoreProjector"="True" "RenderType"="Opaque"}
    52.         LOD 200
    53.  
    54.         CGPROGRAM
    55.         // Physically-based Standard lighting model, and enable shadows on all light types
    56.         #pragma surface surf Standard fullforwardshadows nometa
    57.         // Use Shader model 3.0 target, to get nicer looking lighting
    58.         #pragma target 3.0
    59.  
    60.         sampler2D _MainTex;
    61.  
    62.         struct Input {
    63.             float2 uv_MainTex;
    64.         };
    65.    
    66.         half _Glossiness;
    67.         half _Metallic;
    68.         fixed4 _Color;
    69.    
    70.         void surf (Input IN,inout SurfaceOutputStandard o){
    71.             // Albedo comes from a texture tinted by color
    72.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex)* _Color;
    73.             o.Albedo = c.rgb;
    74.             // Metallic and smoothness come from slider variables
    75.             o.Metallic = _Metallic;
    76.             o.Smoothness = _Glossiness;
    77.             o.Alpha = c.a;
    78.         }
    79.         ENDCG
    80.     }
    81.  
    82.     FallBack "Diffuse"
    83. }
     
    Last edited: Mar 16, 2017
  5. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    314
    is replacing
    o.Emission = Emission(i.uv.xy);
    by
    o.Emission = Emission(i.uv.xy) * _SomeFloatValue;

    and setting the _SomeFloatValue to somthing higher than 1 works?
     
  6. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    YanVerde, thanks for your reply!

    No, it doesn't!