yum-slop/TaSTT
Free self-hosted STT for VRChat.
git clone https://git.yummers.dev/yum-slop/TaSTT
323eeba
v0.20.0
1#ifndef __PBR_INC__ 2#define __PBR_INC__ 3 4#include "AutoLight.cginc" 5#include "eyes_data.cginc" 6#include "UnityPBSLighting.cginc" 7 8static float BG_Effect_Bias = 0.0; 9static float BG_Effect_Weight = 1.0; 10 11UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { 12 UnityIndirect indirect; 13 indirect.diffuse = 0; 14 indirect.specular = 0; 15 16 #if defined(VERTEXLIGHT_ON) 17 indirect.diffuse = i.vertexLightColor; 18 #endif 19 20 #if defined(FORWARD_BASE_PASS) 21 indirect.diffuse += max(0, ShadeSH9(float4(i.normal, 1))); 22 float3 reflect_dir = reflect(-view_dir, i.normal); 23 // There's a nonlinear relationship between mipmap level and roughness. 24 float roughness = 1 - smoothness; 25 roughness *= 1.7 - .7 * roughness; 26 float3 env_sample; 27 env_sample = UNITY_SAMPLE_TEXCUBE_LOD( 28 unity_SpecCube0, 29 reflect_dir, 30 roughness * UNITY_SPECCUBE_LOD_STEPS); 31 indirect.specular = env_sample; 32 #endif 33 34 return indirect; 35} 36 37UnityLight GetLight(v2f i) 38{ 39 UNITY_LIGHT_ATTENUATION(attenuation, 0, i.worldPos); 40 float3 light_color = _LightColor0.rgb * attenuation; 41 42 UnityLight light; 43 light.color = light_color; 44 #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 45 light.dir = normalize(_WorldSpaceLightPos0.xyz - i.worldPos); 46 #else 47 light.dir = _WorldSpaceLightPos0.xyz; 48 #endif 49 light.ndotl = DotClamped(i.normal, light.dir); 50 51 return light; 52} 53 54void initNormal(inout v2f i) 55{ 56 i.normal = normalize(i.normal); 57} 58 59float4 light(inout v2f i, 60 float4 albedo, 61 float metallic, 62 float smoothness) 63{ 64 initNormal(i); 65 66 float3 specular_tint; 67 float one_minus_reflectivity; 68 albedo.rgb = DiffuseAndSpecularFromMetallic( 69 albedo, metallic, specular_tint, one_minus_reflectivity); 70 71 float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); 72 float3 pbr = UNITY_BRDF_PBS(albedo, 73 specular_tint, 74 one_minus_reflectivity, 75 smoothness, 76 i.normal, 77 view_dir, 78 GetLight(i), 79 GetIndirect(i, view_dir, smoothness)).rgb; 80 81 return float4(saturate(pbr), albedo.a); 82} 83 84float getWorldSpaceDepth(in float3 world_pos) 85{ 86 float4 clip_pos = mul(UNITY_MATRIX_VP, float4(world_pos, 1.0)); 87 return clip_pos.z / clip_pos.w; 88} 89 90#endif // __PBR_INC__ 91