You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.4 KiB

  1. Shader "Hidden/IndirectDiffuseLight"
  2. {
  3. Properties
  4. {
  5. _Intensity ("Intensity", Float) = 1
  6. }
  7. SubShader
  8. {
  9. Pass
  10. {
  11. CGPROGRAM
  12. #pragma vertex vert_img
  13. #pragma fragment frag
  14. #include "UnityCG.cginc"
  15. #include "Lighting.cginc"
  16. #include "UnityPBSLighting.cginc"
  17. float _Intensity;
  18. float4 frag(v2f_img i) : SV_Target
  19. {
  20. float2 xy = 2 * i.uv - 1;
  21. float z = -sqrt(1-saturate(dot(xy,xy)));
  22. float3 worldNormal = normalize(float3(xy, z));
  23. float3 vertexPos = float3(xy, z);
  24. float3 worldPos = mul(unity_ObjectToWorld, float4(vertexPos,1)).xyz;
  25. float4 back = lerp(float4(0.4117,0.3843,0.3647,1),float4(0.4117,0.5059,0.6470,1),worldPos.y * 0.5 + 0.5);
  26. return float4(GammaToLinearSpace(back.rgb * _Intensity),1);
  27. }
  28. ENDCG
  29. }
  30. Pass
  31. {
  32. CGPROGRAM
  33. #pragma vertex vert_img
  34. #pragma fragment frag
  35. #include "UnityCG.cginc"
  36. #include "Lighting.cginc"
  37. #include "UnityPBSLighting.cginc"
  38. float _Intensity;
  39. sampler2D _A;
  40. float4 frag(v2f_img i) : SV_Target
  41. {
  42. float2 xy = 2 * i.uv - 1;
  43. float z = -sqrt(1-saturate(dot(xy,xy)));
  44. float3 vertexPos = float3(xy, z);
  45. float3 normal = normalize(vertexPos);
  46. float3 worldNormal = UnityObjectToWorldNormal(normal);
  47. float3 tangent = normalize(float3( -z, xy.y*0.01, xy.x ));
  48. float3 worldPos = mul(unity_ObjectToWorld, float4(vertexPos,1)).xyz;
  49. float3 worldTangent = UnityObjectToWorldDir(tangent);
  50. float tangentSign = -1;
  51. float3 worldBinormal = normalize( cross(worldNormal, worldTangent) * tangentSign);
  52. float4 tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x);
  53. float4 tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
  54. float4 tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
  55. float2 sphereUVs = i.uv;
  56. sphereUVs.x = (atan2(vertexPos.x, -vertexPos.z) / (UNITY_PI) + 0.5);
  57. // Needs further checking
  58. //float3 tangentNormal = tex2Dlod(_A, float4(sphereUVs,0,0)).xyz;
  59. float3 tangentNormal = tex2D(_A, sphereUVs).xyz;
  60. worldNormal = fixed3( dot( tSpace0.xyz, tangentNormal ), dot( tSpace1.xyz, tangentNormal ), dot( tSpace2.xyz, tangentNormal ) );
  61. float4 back = lerp(float4(0.4117,0.3843,0.3647,1),float4(0.4117,0.5059,0.6470,1),worldNormal.y * 0.5 + 0.5);
  62. return float4(GammaToLinearSpace(back.rgb * _Intensity),1);
  63. }
  64. ENDCG
  65. }
  66. }
  67. }