Guest User

UnlitCubeMap

a guest
Aug 13th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Shader "Unlit/UnlitCubemap"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _Cube("Cube Map", Cube) = "" {}
  7. _CubeStrength("Cube Strength", Range(0,1)) = 0.5
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType"="Opaque" }
  12. LOD 100
  13.  
  14. Pass
  15. {
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. // make fog work
  20. #pragma multi_compile_fog
  21.  
  22. #include "UnityCG.cginc"
  23.  
  24. struct appdata
  25. {
  26. float4 vertex : POSITION;
  27. float2 uv : TEXCOORD0;
  28. float3 normal : NORMAL;
  29.  
  30. };
  31.  
  32. struct v2f
  33. {
  34. float2 uv : TEXCOORD0;
  35. UNITY_FOG_COORDS(1)
  36. float4 vertex : SV_POSITION;
  37. float3 normal : TEXCOORD2;
  38. float3 viewDir : TEXCOORD3;
  39. };
  40.  
  41. sampler2D _MainTex;
  42. float4 _MainTex_ST;
  43. uniform samplerCUBE _Cube;
  44. uniform float _CubeStrength;
  45.  
  46. v2f vert (appdata v)
  47. {
  48. v2f o;
  49. o.vertex = UnityObjectToClipPos(v.vertex);
  50. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  51. o.normal = normalize(mul(float4(v.normal, 0.0), unity_WorldToObject).xyz);
  52. o.viewDir = mul(unity_ObjectToWorld, v.vertex).xyz - _WorldSpaceCameraPos;
  53. UNITY_TRANSFER_FOG(o,o.vertex);
  54. return o;
  55. }
  56.  
  57. fixed4 frag (v2f i) : SV_Target
  58. {
  59. fixed4 col = tex2D(_MainTex, i.uv);
  60. float3 reflectedDir = reflect(i.viewDir, normalize(i.normal));
  61. fixed4 colCube = texCUBE(_Cube, reflectedDir);
  62.  
  63. //additive
  64. col = col + colCube * _CubeStrength;
  65. //multiplicative
  66. //col = col * colCube * _CubeStrength;
  67. //lerp
  68. //col = lerp(col,colCube,_CubeStrength);
  69.  
  70. UNITY_APPLY_FOG(i.fogCoord, col);
  71. return col;
  72. }
  73. ENDCG
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment