1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

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:
    39
    Hello,

    I'm using a movie for 'emission' map
    [​IMG]
    ...and would like to boost the 'emission' power...but if I do so the image itself is overexposed
    [​IMG]

    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. YanVerde

    YanVerde

    Joined:
    Jul 11, 2013
    Posts:
    125
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    18,839
    Probably the best way, yeah.
     
  4. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    39
    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. YanVerde

    YanVerde

    Joined:
    Jul 11, 2013
    Posts:
    125
    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:
    39
    YanVerde, thanks for your reply!

    No, it doesn't!