diff options
| author | yum <yum.food.vr@gmail.com> | 2026-02-24 01:37:59 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-02-24 01:37:59 -0800 |
| commit | 155a8ceecfe64773eb21ba55a2ac286d52589141 (patch) | |
| tree | 4f883048f57d7f61d663eb41acf5187fd054779e | |
| parent | c1709ef4a57ab10e83afd9dfbed7e162e88c06d9 (diff) | |
Rewrite SH9 core, more concise
| -rwxr-xr-x | 3ner.cginc | 1 | ||||
| -rwxr-xr-x | LUTS/dfg_standard.exr.meta | 2 | ||||
| -rwxr-xr-x | interpolators.cginc | 9 | ||||
| -rwxr-xr-x | lighting.cginc | 35 | ||||
| -rwxr-xr-x | pbr.cginc | 12 |
5 files changed, 24 insertions, 35 deletions
@@ -40,7 +40,6 @@ v2f vert(appdata v) { o.objPos_orig = v.vertex; #endif - [branch] if (instance_distance_culling()) { return (v2f) asfloat(-1); } diff --git a/LUTS/dfg_standard.exr.meta b/LUTS/dfg_standard.exr.meta index 107cdd2..4f4711f 100755 --- a/LUTS/dfg_standard.exr.meta +++ b/LUTS/dfg_standard.exr.meta @@ -22,7 +22,7 @@ TextureImporter: normalMapFilter: 0 flipGreenChannel: 0 isReadable: 0 - streamingMipmaps: 0 + streamingMipmaps: 1 streamingMipmapsPriority: 0 vTOnly: 0 ignoreMipmapLimit: 0 diff --git a/interpolators.cginc b/interpolators.cginc index 88a4649..a6a24e9 100755 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -5,16 +5,17 @@ struct appdata { float4 vertex : POSITION; - float2 uv0 : TEXCOORD0; - float2 uv1 : TEXCOORD1; - float2 uv2 : TEXCOORD2; - float2 uv3 : TEXCOORD3; #if defined(_RAY_MARCHING_BAKED_ORIGINS) float4 color : COLOR; // vertex color #endif float3 normal : NORMAL; float4 tangent : TANGENT; + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + float2 uv3 : TEXCOORD3; + UNITY_VERTEX_INPUT_INSTANCE_ID }; diff --git a/lighting.cginc b/lighting.cginc index 2ae7d0d..9a66703 100755 --- a/lighting.cginc +++ b/lighting.cginc @@ -139,36 +139,25 @@ float3 yumSH9(float4 n, float3 worldPos, inout LightIndirect light) { // unity_SHB*: first four of the L2 coefficients // unity_SHC: last L2 coefficient - // Parse out coefficients into a simpler but less efficient format. - float3 L00 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); - float3 L1_1 = float3(unity_SHAr.x, unity_SHAg.x, unity_SHAb.x); - float3 L10 = float3(unity_SHAr.y, unity_SHAg.y, unity_SHAb.y); - float3 L11 = float3(unity_SHAr.z, unity_SHAg.z, unity_SHAb.z); - float3 L2_2 = float3(unity_SHBr.x, unity_SHBg.x, unity_SHBb.x); - float3 L2_1 = float3(unity_SHBr.y, unity_SHBg.y, unity_SHBb.y); - float3 L20 = float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z); - float3 L21 = float3(unity_SHBr.w, unity_SHBg.w, unity_SHBb.w); - float3 L22 = unity_SHC; - // Equation 13 from "An Efficient Representation for Irradiance Environment - // Maps" by Ramamoorthi and Hanrahan. Note that the order of some - // coefficients is different, and normalization constants have been - // premultiplied by Unity. - float3 L0 = L00; - float3 L1 = L1_1 * n.x + L10 * n.y + L11 * n.z; - float3 L2 = - L2_2 * n.x * n.y + - L2_1 * n.y * n.z + - L20 * n.z * n.z + - L21 * n.x * n.z + - L22 * (n.x * n.x - n.y * n.y); + // Maps" by Ramamoorthi and Hanrahan. Normalization constants have been + // premultiplied by Unity into the coefficient buffers. + // + // L0+L1: dot4 per channel (n.w=1 picks up the L0 term from SHA*.w) + // L2: four quadratic terms packed into vB via swizzle multiply, plus L22 + float4 n4 = float4(n.xyz, 1.0); + float3 L0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + float3 L01 = float3(dot(unity_SHAr, n4), dot(unity_SHAg, n4), dot(unity_SHAb, n4)); + float4 vB = n4.xyzz * n4.yzzx; + float3 L2 = float3(dot(unity_SHBr, vB), dot(unity_SHBg, vB), dot(unity_SHBb, vB)) + + unity_SHC * (n.x * n.x - n.y * n.y); light.L00 = L0; light.L01r = unity_SHAr.xyz; light.L01g = unity_SHAg.xyz; light.L01b = unity_SHAb.xyz; - return L0 + L1 + L2; + return L01 + L2; } float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) { @@ -8,6 +8,12 @@ #include "texture_utils.cginc" #include "impostor.cginc" +// From filament: min roughness s.t. MIN_PERCEPTUAL_ROUGHNESS^4 > 0 in target +// precision. Although we use fp32, the higher min roughness gives us a broader +// specular highlight, which is preferable. +#define MIN_PERCEPTUAL_ROUGHNESS 0.045 +#define MIN_ROUGHNESS 0.002025 + struct Pbr { float4 albedo; float3 normal; @@ -33,12 +39,6 @@ struct Pbr { #endif }; -// From filament: min roughness s.t. MIN_PERCEPTUAL_ROUGHNESS^4 > 0 in target -// precision. We use fp32. The smallest non-subnormal is 2^(-126). The 4th -// root of that is ~3.29 * 10^-10. -#define MIN_PERCEPTUAL_ROUGHNESS (3.3E-10) -#define MIN_ROUGHNESS (1.09E-19) - #if defined(_PARALLAX_HEIGHTMAP) float2 parallax_offset(float2 uv, float3 view_dir_world, float3x3 tbn) { float3 view_dir_tangent = mul(tbn, view_dir_world); |
