diff options
| author | yum <yum.food.vr@gmail.com> | 2025-10-28 17:15:36 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-10-28 17:19:39 -0700 |
| commit | 6a10c50359aa62405118a78c69dccef0394f8591 (patch) | |
| tree | 59c7c55ec3d37780319bc066fd473e1b24b632ff | |
| parent | fd370eab7e4959895763514526efc878e53d4886 (diff) | |
add machinery for multiple uv channels
| -rw-r--r-- | 3ner.cginc | 8 | ||||
| -rw-r--r-- | 3ner.shader | 15 | ||||
| -rw-r--r-- | features.cginc | 8 | ||||
| -rw-r--r-- | globals.cginc | 5 | ||||
| -rw-r--r-- | interpolators.cginc | 24 | ||||
| -rw-r--r-- | pbr.cginc | 8 | ||||
| -rw-r--r-- | texture_utils.cginc | 32 |
7 files changed, 86 insertions, 14 deletions
@@ -30,7 +30,10 @@ v2f vert(appdata v) { #if defined(_TESSELLATION) o.tpos = v.vertex; #endif - o.uv0 = v.uv0; + o.uv01.xy = v.uv0; + o.uv01.zw = v.uv1; + o.uv23.xy = v.uv2; + o.uv23.zw = v.uv3; o.objPos = v.vertex; #if defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || defined(_VERTEX_DEFORMATION_TESSELLATION) o.objPos_orig = v.vertex; @@ -160,7 +163,8 @@ v2f domain( patch[1].fieldName * baryc.y + \ patch[2].fieldName * baryc.z - o.uv0 = DOMAIN_INTERP(uv0); + o.uv01 = DOMAIN_INTERP(uv01); + o.uv23 = DOMAIN_INTERP(uv23); #if defined(_TESSELLATION) o.objPos = DOMAIN_INTERP(tpos); #else diff --git a/3ner.shader b/3ner.shader index 457168b..58d4d23 100644 --- a/3ner.shader +++ b/3ner.shader @@ -52,6 +52,21 @@ Shader "yum_food/3ner" //endex [HideInInspector] m_end_Geometry_Shader("Geometry Shader", Float) = 0 //endex + + //ifex _Ray_Marching_Enabled==0 + [HideInInspector] m_start_Ray_Marching("Ray Marching", Float) = 0 + [ThryToggle(_RAY_MARCHING)] _Ray_Marching_Enabled("Enable", Float) = 0 + + //ifex _Ray_Marching_Baked_Origins_Enabled==0 + [HideInInspector] m_start_Ray_Marching_Baked_Origins("Baked Origins", Float) = 0 + [ThryToggle(_RAY_MARCHING_BAKED_ORIGINS)] _Ray_Marching_Baked_Origins_Enabled("Enable", Float) = 0 + + [IntRange] _Baked_Origins_UV_Channel_Index("UV Channel Index", Range(0, 3)) = 0 + [HideInInspector] m_end_Ray_Marching_Baked_Origins("Baked Origins", Float) = 0 + //endex + + [HideInInspector] m_end_Ray_Marching("Ray Marching", Float) = 0 + //endex //ifex _Logical_Time_Enabled==0 [HideInInspector] m_start_Logical_Time("Logical Time", Float) = 0 diff --git a/features.cginc b/features.cginc index def13bd..b5c7e64 100644 --- a/features.cginc +++ b/features.cginc @@ -68,4 +68,12 @@ #pragma shader_feature_local _LOGICAL_TIME //endex +//ifex _Ray_Marching_Enabled==0 +#pragma shader_feature_local _RAY_MARCHING +//endex + +//ifex _Ray_Marching_Baked_Origins_Enabled==0 +#pragma shader_feature_local _RAY_MARCHING_BAKED_ORIGINS +//endex + #endif // __FEATURES_INC diff --git a/globals.cginc b/globals.cginc index ed76917..a9f8f30 100644 --- a/globals.cginc +++ b/globals.cginc @@ -114,4 +114,9 @@ float getTime() { #endif // _LOGICAL_TIME } + +#if defined(_RAY_MARCHING_BAKED_ORIGINS) +int _Baked_Origins_UV_Channel_Index; +#endif // _RAY_MARCHING_BAKED_ORIGINS + #endif // __GLOBALS_INC diff --git a/interpolators.cginc b/interpolators.cginc index 842861a..77b96a8 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -6,6 +6,9 @@ struct appdata { float4 vertex : POSITION; float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + float2 uv3 : TEXCOORD3; float4 color : COLOR; // vertex color float3 normal : NORMAL; float4 tangent : TANGENT; @@ -18,15 +21,20 @@ struct v2f { float4 tpos : INTERNALTESSPOS; #endif linear noperspective centroid float4 pos : SV_POSITION; - float2 uv0 : TEXCOORD0; - float3 objPos : TEXCOORD1; - float3 worldPos : TEXCOORD2; - float4 eyeVec : TEXCOORD3; // eyeVec.xyz | fogCoord - float3 normal : TEXCOORD4; - float4 tangent : TEXCOORD5; - UNITY_LIGHTING_COORDS(6,7) + float4 uv01 : TEXCOORD0; + float4 uv23 : TEXCOORD1; + float3 objPos : TEXCOORD2; + float3 worldPos : TEXCOORD3; + float4 eyeVec : TEXCOORD4; // eyeVec.xyz | fogCoord + float3 normal : TEXCOORD5; + float4 tangent : TEXCOORD6; + UNITY_LIGHTING_COORDS(7,8) + // TODO figure out some metaprogramming or preprocessor to better allocate optional texcoords :( #if defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || defined(_VERTEX_DEFORMATION_TESSELLATION) - float3 objPos_orig : TEXCOORD8; + float3 objPos_orig : TEXCOORD9; +#endif +#if defined(_RAYMARCH_BAKED_ORIGIN) + float3 color : TEXCOORD10; #endif UNITY_VERTEX_INPUT_INSTANCE_ID @@ -54,21 +54,21 @@ Pbr getPbr(v2f i) { Pbr pbr = (Pbr) 0; #if defined(_UV_SCROLL) - i.uv0 += getTime() * _UV_Scroll_Speed; + i.uv01.xy += getTime() * _UV_Scroll_Speed; #endif // _UV_SCROLL - pbr.albedo = _MainTex.Sample(aniso16_trilinear_repeat_s, i.uv0 * _MainTex_ST.xy + _MainTex_ST.zw); + pbr.albedo = _MainTex.Sample(aniso16_trilinear_repeat_s, i.uv01.xy * _MainTex_ST.xy + _MainTex_ST.zw); pbr.albedo *= _Color; apply_marble(i.worldPos, pbr.albedo.xyz); - float3 normal_tangent = UnpackNormal(_BumpMap.Sample(aniso16_trilinear_repeat_s, i.uv0 * _BumpMap_ST.xy)); + float3 normal_tangent = UnpackNormal(_BumpMap.Sample(aniso16_trilinear_repeat_s, i.uv01.xy * _BumpMap_ST.xy)); normal_tangent.xy *= _BumpScale; // Map from tangent space to world space. float3 bitangent = cross(i.normal, i.tangent.xyz) * i.tangent.w; pbr.tbn = float3x3(i.tangent.xyz, bitangent, i.normal); pbr.normal = normalize(mul(normal_tangent, pbr.tbn)); - float4 metallic_gloss = _MetallicGlossMap.Sample(aniso16_trilinear_repeat_s, i.uv0 * _MetallicGlossMap_ST.xy); + float4 metallic_gloss = _MetallicGlossMap.Sample(aniso16_trilinear_repeat_s, i.uv01.xy * _MetallicGlossMap_ST.xy); pbr.smoothness = metallic_gloss.a * _Glossiness; pbr.metallic = metallic_gloss.r * _Metallic; #if defined(_CLEARCOAT) diff --git a/texture_utils.cginc b/texture_utils.cginc new file mode 100644 index 0000000..9d7bf2f --- /dev/null +++ b/texture_utils.cginc @@ -0,0 +1,32 @@ +#ifndef __TEXTURE_UTILS_INC +#define __TEXTURE_UTILS_INC + +#include "interpolators.cginc" + +float2 get_uv_by_channel(v2f i, uint which_channel) { + [forcecase] + switch (which_channel) { + case 0: + return i.uv01.xy; + break; + case 1: + return i.uv01.zw; + break; + case 2: + return i.uv23.xy; + break; + case 3: + return i.uv23.zw; + break; + default: + return 0; + break; + } +} + +#define UV_SCOFF_IMPL(uv, tex_st) (uv) * (tex_st).xy + (tex_st).zw + +#define UV_SCOFF(i, tex_st, which_channel) UV_SCOFF_IMPL(get_uv_by_channel(i, round(which_channel)), tex_st) + +#endif // __TEXTURE_UTILS_INC + |
