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