Search Unity

How do add reflection probe to a surface shader

Discussion in 'Shaders' started by laurentlavigne, Feb 11, 2016.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,330
    How do I add skybox to the shader so the top sphere which is "surface shaded" looks more like the standard shaded sphere at the bottom?
    The unlit area is very dark.



    Code (CSharp):
    1.  
    2. Shader "Opaque" {
    3. Properties {
    4. _Color ("Color",Color) = (1,1,1,1)
    5. _MainTex ("Texture", 2D) = "white" {}
    6. _BumpMap ("Bumpmap", 2D) = "bump" {}
    7. _RimColor ("RimColor", Color) = (0.26,0.19,0.16,0.0)
    8. _RimPower ("RimPower", float) = 3.0
    9. _OutlineColor ("OutlineColor", Color) = (0,0,0,1)
    10. _Outline ("Outlinewidth", float) = .005
    11. }
    12. SubShader {
    13. Tags { "RenderType" = "Opaque" }
    14. CGPROGRAM
    15. #pragma target 3.0
    16. #pragma surface surf WrapLambert vertex:vert nodirlightmap
    17. #include "UnityCG.cginc"
    18.  
    19. float4 _Color;
    20. sampler2D _MainTex;
    21. sampler2D _BumpMap;
    22. uniform float4 _RimColor;
    23. uniform float _RimPower;
    24.  
    25. half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
    26. half NdotL = dot (s.Normal, lightDir);
    27. half diff = NdotL;//*0.5+0.5;
    28. half4 c;
    29. c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
    30. c.a = s.Alpha;
    31. return c;
    32. }
    33.  
    34. struct Input {
    35. float2 uv_MainTex;
    36. float2 uv_BumpMap;
    37. float3 viewDir;
    38. float3 vertexColor;
    39. float3 worldRefl;
    40. float factor;
    41. INTERNAL_DATA
    42. };
    43.  
    44. void vert (inout appdata_full v, out Input o) {
    45. UNITY_INITIALIZE_OUTPUT(Input,o);
    46. o.vertexColor = v.color;
    47. }
    48.  
    49. void surf (Input IN, inout SurfaceOutput o) {
    50. half3 c = tex2D (_MainTex, IN.uv_MainTex).rgb;
    51. c *= IN.vertexColor;
    52. c *= _Color;
    53. //sky
    54. float4 reflection = UNITY_SAMPLE_TEXCUBE(unity_SpecCube1, IN.worldRefl);
    55. float4 sky = 1.0;
    56. sky.rgb = DecodeHDR(reflection, unity_SpecCube1_HDR);
    57. sky.a = 1.0;
    58. o.Albedo = c + sky;
    59.  
    60. o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
    61.  
    62. half rim = 1.0 - saturate(dot (IN.viewDir, o.Normal));
    63. half3 e = _RimColor.rgb * pow (rim, _RimPower);
    64. o.Emission = e + rim*c;
    65. }
    66. ENDCG
    67.  
    68. UsePass "Toon/BasicOutline/OUTLINE"
    69. }
    70. Fallback "Diffuse"
    71. }
    72.