Search Unity

Mobile shader fresnel

Discussion in 'Shaders' started by marcmantraunity, Aug 18, 2017.

?

Why shader is broken by commented lines?

  1. This is your mistake

    1 vote(s)
    100.0%
  2. You have to replace the code for this

    0 vote(s)
    0.0%
  1. marcmantraunity

    marcmantraunity

    Joined:
    May 31, 2014
    Posts:
    21
    Hi,
    I'm trying to create for a VR game a mobile shader (as they are optimized). The challenge is to take the built-in BumpSpecular one and and tweak it to multiply the reflection by a "fresnel" ramp.
    I don't know what's wrong, I'm not a shader developer but I need it to process on a Single Pass VR.

    The commented lines are which break the shader.
    Anyone can help me? Thanks on advance,

    Code (CSharp):
    1. Shader "Reflect-BumpSpec" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
    5.     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    6.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    7.     _Fresnel ("Fresnel", Range(0.0,8.0)) = 2.0
    8.     _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
    9.     _Cube ("Reflection Cubemap", Cube) = "" {}
    10.     _BumpMap ("Normalmap", 2D) = "bump" {}
    11. }
    12.  
    13. SubShader {
    14.     Tags { "RenderType"="Opaque" }
    15.     LOD 400
    16. CGPROGRAM
    17. #pragma surface surf BlinnPhong
    18. #pragma target 3.0
    19.  
    20. sampler2D _MainTex;
    21. sampler2D _BumpMap;
    22. samplerCUBE _Cube;
    23.  
    24. fixed4 _Color;
    25. fixed4 _ReflectColor;
    26. half _Shininess;
    27.  
    28. struct Input {
    29.     float2 uv_MainTex;
    30.     float2 uv_BumpMap;
    31.     float3 worldRefl;
    32.     float3 viewDir;
    33.     INTERNAL_DATA
    34. };
    35.  
    36. void surf (Input IN, inout SurfaceOutput o) {
    37.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    38.     fixed4 c = tex * _Color;
    39.     o.Albedo = c.rgb;
    40.  
    41.     o.Gloss = tex.a;
    42.     o.Specular = _Shininess;
    43.  
    44.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    45.  
    46.     half rim = 1-saturate(dot(normalize(IN.viewDir), o.Normal));
    47.  
    48.     float3 worldRefl = WorldReflectionVector (IN, o.Normal);
    49.     fixed4 reflcol = texCUBE (_Cube, worldRefl);
    50.     half refl_lum = _ReflectColor.r * 0.3 + _ReflectColor.g * 0.59 + _ReflectColor.b * 0.11;
    51.  
    52.     //reflcol *= (_Fresnel * pow(rim,refl_lum));
    53.     //reflcol *= _RimPower;
    54.     reflcol *= tex.a;
    55.    
    56.     o.Emission = reflcol.rgb * _ReflectColor.rgb;
    57.     o.Alpha = reflcol.a * _ReflectColor.a;
    58. }
    59. ENDCG
    60. }
    61.  
    62. FallBack "Legacy Shaders/Reflective/Bumped Diffuse"
    63. }
    64.  
    65.  
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    You haven't declared your variables. line 27 add:

    Code (csharp):
    1. float _Fresnel;
    2. float _RimPower;
    3.  
    You also don't have _RimPower declared in your properties block so you won't get any input options in the inspector.