yum-archive/SoggyShaders
Old Unity shaders.
git clone https://git.yummers.dev/yum-archive/SoggyShaders
03368f2
master
1#ifndef __PBR_INC 2#define __PBR_INC 3 4#include "UnityPBSLighting.cginc" 5 6UNITY_DECLARE_TEXCUBE(_Cubemap); 7 8struct v2f 9{ 10 float4 clipPos : SV_POSITION; 11 float2 uv : TEXCOORD0; 12 float3 normal : TEXCOORD1; 13 float3 worldPos : TEXCOORD2; 14 15 float3 objPos : TEXCOORD3; 16 17 #if defined(VERTEXLIGHT_ON) 18 float3 vertexLightColor : TEXCOORD3; 19 #endif 20}; 21 22UnityLight GetLight(v2f i, float3 worldPos, float3 normal) 23{ 24 UNITY_LIGHT_ATTENUATION(attenuation, 0, worldPos); 25 float3 light_color = _LightColor0.rgb * attenuation; 26 27 UnityLight light; 28 light.color = light_color; 29 #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 30 light.dir = normalize(_WorldSpaceLightPos0.xyz - worldPos); 31 #else 32 light.dir = _WorldSpaceLightPos0.xyz; 33 #endif 34 light.ndotl = DotClamped(normal, light.dir); 35 36 return light; 37} 38 39UnityIndirect GetIndirect(v2f i, float3 view_dir, float3 normal, 40 float smoothness, bool custom_cubemap) { 41 UnityIndirect indirect; 42 indirect.diffuse = 0; 43 indirect.specular = 0; 44 45 #if defined(VERTEXLIGHT_ON) 46 indirect.diffuse = i.vertexLightColor; 47 #endif 48 49 #if defined(FORWARD_BASE_PASS) 50 indirect.diffuse += max(0, ShadeSH9(float4(normal, 1))); 51 float3 reflect_dir = reflect(-view_dir, normal); 52 // There's a nonlinear relationship between mipmap level and roughness. 53 float roughness = 1 - smoothness; 54 roughness *= 1.7 - .7 * roughness; 55 if (custom_cubemap) { 56 float3 env_sample = UNITY_SAMPLE_TEXCUBE_LOD( 57 _Cubemap, 58 reflect_dir, 59 roughness * UNITY_SPECCUBE_LOD_STEPS); 60 indirect.specular = env_sample; 61 } else { 62 float3 env_sample = UNITY_SAMPLE_TEXCUBE_LOD( 63 unity_SpecCube0, 64 reflect_dir, 65 roughness * UNITY_SPECCUBE_LOD_STEPS); 66 indirect.specular = env_sample; 67 } 68 #endif 69 70 return indirect; 71} 72 73float4 getLitColor(v2f i, float4 albedo, float3 worldPos, float3 normal, 74 float metallic, float smoothness, 75 bool custom_cubemap) 76{ 77 float3 specular_tint; 78 float one_minus_reflectivity; 79 albedo.rgb = DiffuseAndSpecularFromMetallic( 80 albedo, metallic, specular_tint, one_minus_reflectivity); 81 82 float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); 83 84 float3 pbr = UNITY_BRDF_PBS(albedo, specular_tint, 85 one_minus_reflectivity, smoothness, 86 view_dir, normal, 87 GetLight(i, worldPos, normal), 88 GetIndirect(i, view_dir, normal, smoothness, custom_cubemap)).rgb; 89 90 return float4(saturate(pbr), albedo.a); 91} 92 93#endif // __PBR_INC