Search Unity

Disabling Shadows on Shader [ HELP ]

Discussion in 'Shaders' started by Flegy, Apr 16, 2019.

  1. Flegy

    Flegy

    Joined:
    Jan 5, 2017
    Posts:
    30
    Hello,

    I need a small help to disable shadows on shader.

    upload_2019-4-16_3-4-58.png

    Code (CSharp):
    1. Shader "IgnoreShadows" {
    2.     Properties{
    3.         _MainTex("Base (RGB) Boob Mask (A)", 2D) = "white" {}
    4.         _MaskTex("Skin Masks: Spec (R) Gloss (G) Occlusion (B)", 2D) = "white" {}
    5.         _NormalMap("Normalmap", 2D) = "bump" {}
    6.         _BoobMap("Boob Map", 2D) = "gray" {}
    7.         _BRDFTex("Brdf Map", 2D) = "gray" {}
    8.         _BeckmannTex("BeckmannTex", 2D) = "gray" {}
    9.         _Color2("Diffuse Tint", color) = (1, 0.859, 0.859, 0)
    10.         _Color3("Deep Layer", color) = (0.463, 0.243, 0.224, 0)
    11.             //_SpecColor ("Spec color", color) = (1, 0.882, 0.867, 0)
    12.             _SpecPow("Specularity", Range(1, 16)) = 3.12
    13.             _GlossPow("Smoothness", Range(0, 1)) = 0.28
    14.             _Blend1("Blend Amount", Range(0, 1)) = 1
    15.             _AmbientContribution("Ambience", Range(0, 1)) = 1
    16.             _Bright("Brightness", Range(0, 1)) = 1
    17.     }
    18.         SubShader{
    19.             Tags { "RenderType" = "Opaque" }
    20.             LOD 300
    21.  
    22.             CGPROGRAM
    23.             #pragma surface surf StandardSkin addshadow
    24.             #pragma target 3.0
    25.             #include "UnityCG.cginc"
    26.  
    27.             struct SurfaceOutputStandardSkin {
    28.                 fixed3 Albedo;      // diffuse color
    29.                 half Specular;        // specular color
    30.                 fixed3 Normal;      // tangent space normal, if written
    31.                 half3 Emission;
    32.                 half Specularity;
    33.                 half Smoothness;    // 0 = rough, 1 = smooth
    34.                 half Occlusion;     // occlusion (default 1)
    35.                 fixed Alpha;        // alpha for transparencies
    36.             };
    37.  
    38.             struct appdata {
    39.                 float4 vertex : POSITION;
    40.                 float4 tangent : TANGENT;
    41.                 float3 normal : NORMAL;
    42.                 float2 texcoord : TEXCOORD0;
    43.                 float2 texcoord1 : TEXCOORD1;
    44.                 float2 texcoord2 : TEXCOORD2;
    45.                 //fixed4 color : COLOR;
    46.                 //#if defined(SHADER_API_XBOX360)
    47.                 //half4 texcoord3 : TEXCOORD3;
    48.                 //half4 texcoord4 : TEXCOORD4;
    49.                 //half4 texcoord5 : TEXCOORD5;
    50.                 //#endif  
    51.                 UNITY_VERTEX_INPUT_INSTANCE_ID //f u 2018
    52.             };
    53.  
    54.             struct Input {
    55.                 float2 uv_MainTex;
    56.                 float2 uv_MaskTex;
    57.                 float3 coords0;
    58.                 float3 coords1;
    59.                 float3 viewDir;
    60.             };
    61.  
    62.  
    63.             sampler2D _MainTex;
    64.             sampler2D _NormalMap;
    65.             fixed4 _Color2;
    66.             fixed4 _Color3;
    67.             float _SpecPow;
    68.             float _GlossPow;
    69.             float _Blend1;
    70.             float _Bright;
    71.  
    72.             sampler2D _MaskTex;
    73.             //uniform float4 _NormalMap_ST;
    74.             float _AmbientContribution;
    75.  
    76.             sampler2D _BoobMap;
    77.             sampler2D _BRDFTex;
    78.             sampler2D _BeckmannTex;
    79.  
    80.             void vert(inout appdata v, out Input o)
    81.             {
    82.  
    83.                 UNITY_INITIALIZE_OUTPUT(Input, o);
    84.  
    85.                 TANGENT_SPACE_ROTATION;
    86.                 o.coords0 = mul(rotation, UNITY_MATRIX_IT_MV[0].xyz);
    87.                 o.coords1 = mul(rotation, UNITY_MATRIX_IT_MV[1].xyz);
    88.             }
    89.  
    90.             float Fresnel(float3 _half, float3 view, float f0) {
    91.                 float base = 1.0 - dot(view, _half);
    92.                 float exponential = pow(base, 5.0);
    93.                 return exponential + f0 * (1.0 - exponential);
    94.             }
    95.  
    96.             half SpecularKSK(sampler2D beckmannTex, float3 normal, float3 light, float3 view, float roughness) {
    97.  
    98.                 const float _specularFresnel = 1.08;
    99.  
    100.                 half3 _half = view + light;
    101.                 half3 halfn = normalize(_half);
    102.  
    103.                 half ndotl = max(dot(normal, light), 0.0);
    104.                 half ndoth = max(dot(normal, halfn), 0.0);
    105.  
    106.                 half ph = pow(2.0 * tex2D(beckmannTex, float2(ndoth, roughness)).r, 10.0);
    107.                 half f = lerp(0.25, Fresnel(halfn, view, 0.028), _specularFresnel);
    108.                 half ksk = max(ph * f / dot(_half, _half), 0.0);
    109.  
    110.                 return ndotl * ksk;
    111.             }
    112.  
    113.             half3 Skin_BRDF_PBS(SurfaceOutputStandardSkin s, float oneMinusReflectivity, half3 viewDir, UnityLight light, UnityIndirect gi)
    114.             {
    115.  
    116.                 half3 normalizedLightDir = normalize(light.dir);
    117.                 viewDir = normalize(viewDir);
    118.  
    119.                 float3 occl = light.color.rgb * s.Occlusion;
    120.  
    121.                 half specular = (s.Specularity * SpecularKSK(_BeckmannTex, s.Normal, normalizedLightDir, viewDir , s.Smoothness));
    122.                 half specular2 = (s.Specularity * SpecularKSK(_BeckmannTex, s.Normal, normalizedLightDir, viewDir , (s.Smoothness + 0.2)));
    123.  
    124.                 const float blendAmount = 0.6;
    125.                 specular = blendAmount * specular + (1 - blendAmount) * specular2;
    126.  
    127.                 half3 brdf = float3(1,1,1);
    128.                 float dotNL = dot(s.Normal, normalizedLightDir);
    129.                 float2 brdfUV;
    130.  
    131.                 brdfUV.x = dotNL * 0.5 + 0.5;
    132.                 brdfUV.y = 0.7 * dot(light.color, fixed3(0.2126, 0.7152, 0.0722));
    133.  
    134.                 brdf = tex2D(_BRDFTex, brdfUV).rgb;
    135.  
    136.                 half3 color = half3(0,0,0);
    137.  
    138.                 half nv = DotClamped(s.Normal, viewDir);
    139.                 half grazingTerm = saturate(1 - s.Smoothness + (1 - oneMinusReflectivity));
    140.  
    141.                 color.rgb += 0
    142.                             + s.Albedo * (_AmbientContribution * gi.diffuse + occl * brdf)
    143.                             + specular * light.color
    144.                             + gi.specular * FresnelLerp(specular, grazingTerm, nv) * _AmbientContribution;
    145.  
    146.                 return color;
    147.             }
    148.  
    149.             inline half4 LightingStandardSkin(SurfaceOutputStandardSkin s, half3 viewDir, UnityGI gi)
    150.             {
    151.                 s.Normal = normalize(s.Normal);
    152.  
    153.                 half oneMinusReflectivity;
    154.                 half3 specColor;
    155.                 s.Albedo = EnergyConservationBetweenDiffuseAndSpecular(s.Albedo, s.Specular, /*out*/ oneMinusReflectivity);
    156.  
    157.                 half outputAlpha;
    158.                 s.Albedo = PreMultiplyAlpha(s.Albedo, s.Alpha, oneMinusReflectivity, /*out*/ outputAlpha);
    159.  
    160.                 half4 color = half4(0.0, 0.0, 0.0, 1.0);
    161.                 color.a = s.Alpha;
    162.                 color.rgb = Skin_BRDF_PBS(s, oneMinusReflectivity, viewDir, gi.light, gi.indirect);
    163.  
    164.                 return color;
    165.             }
    166.  
    167.             inline void LightingStandardSkin_GI(SurfaceOutputStandardSkin s, UnityGIInput data, inout UnityGI gi)
    168.             {
    169.                 gi = UnityGlobalIllumination(data, s.Occlusion, s.Smoothness, s.Normal);
    170.             }
    171.  
    172.             void surf(Input IN, inout SurfaceOutputStandardSkin o) {
    173.  
    174.                 half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color2;
    175.  
    176.                 float3 normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
    177.                 fixed3 blurredNormal = UnpackNormal(tex2Dlod(_NormalMap, float4(IN.uv_MainTex, 0.0, 3.0)));
    178.  
    179.                 half2 nmCombined;
    180.                 nmCombined.x = dot(IN.coords0, blurredNormal);
    181.                 nmCombined.y = dot(IN.coords1, blurredNormal);
    182.  
    183.                 half4 boobMap = tex2D(_BoobMap, nmCombined * 0.5 + 0.5);
    184.                 half mask = tex2D(_MainTex, IN.uv_MainTex).a;
    185.  
    186.                 o.Normal = lerp(blurredNormal, normal, IN.viewDir);
    187.  
    188.                 float twiceLuminance = dot(c, fixed4(0.2126, 0.7152, 0.0722, 0)) * 2;
    189.                 fixed4 output = 0;
    190.  
    191.                 if (twiceLuminance < 1) {
    192.                     output = lerp(_Color3, boobMap, twiceLuminance);
    193.                 }
    194. else {
    195.   output = lerp(boobMap, _Color3, twiceLuminance - 1);
    196. }
    197.  
    198.                 //we don't need a rim light on this one
    199.                 //half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    200.                 //o.Emission = _SpecColor * mask * pow (rim, 4) * 0.2;
    201.  
    202.                 o.Albedo = lerp(output, c.rgb, (1.0 - mask * _Blend1)) * _Bright * 2;
    203.  
    204.                 o.Specularity = tex2D(_MaskTex, IN.uv_MaskTex).r * _SpecPow;
    205.                 o.Smoothness = tex2D(_MaskTex, IN.uv_MaskTex).g * _GlossPow;
    206.                 o.Occlusion = tex2D(_MaskTex, IN.uv_MaskTex).b;
    207.  
    208.  
    209.             }
    210.             ENDCG
    211.         }
    212.             FallBack "Diffuse"
    213. }
     
  2. Flegy

    Flegy

    Joined:
    Jan 5, 2017
    Posts:
    30
    bump
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
  4. Flegy

    Flegy

    Joined:
    Jan 5, 2017
    Posts:
    30
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Ah, your issue is not that you want to disable shadows. You either want to disable lighting entirely, or use a fixed lighting direction, or boost the ambient lighting. Basically you want the character's face to be visible regardless of the actual scene lighting.

    My suggestion would be to not fix this within the shader, but instead with the camera used to render the view and use a custom lighting rig. That's a fancy way of saying use a group of lights that are only visible for the portrait camera and disabled for the main camera. Have them attached to the camera itself. You may even want to hide the sun light for that camera.

    The fancier way of handling this would be to use some sort of auto-exposure post process on the portrait camera, or have an extra light (only visible in the portrait camera) that you place programmatically based on the current lighting, but that gets complicated quickly.