diff options
| author | yum <yum.food.vr@gmail.com> | 2023-08-10 18:22:03 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-08-10 18:22:03 -0700 |
| commit | f7fbd1965543f47596eae491bbe8947bf44d1518 (patch) | |
| tree | e1cd568d74f2f2a63fd5b2ff5b86eae099bcf80e | |
| parent | e9a8b991552d08823b0f44b238f4afaede53c54e (diff) | |
Add basic PBR parameters to new shader
No UVs for raymarched geometry yet, so drop textures. Also drop most
old shader settings.
| -rw-r--r-- | Animations/TaSTT_Emerge_000.anim | 4 | ||||
| -rw-r--r-- | Animations/TaSTT_Emerge_100.anim | 4 | ||||
| -rw-r--r-- | Scripts/generate_params.py | 2 | ||||
| -rw-r--r-- | Shaders/TaSTT_lighting.cginc | 364 | ||||
| -rw-r--r-- | Shaders/TaSTT_template.shader | 45 | ||||
| -rw-r--r-- | Shaders/eyes_data.cginc | 2 | ||||
| -rw-r--r-- | Shaders/iq_sdf.cginc | 7 | ||||
| -rw-r--r-- | Shaders/ray_march.cginc | 95 | ||||
| -rw-r--r-- | UnityAssets/Materials/TaSTT_Text.mat | 111 |
9 files changed, 95 insertions, 539 deletions
diff --git a/Animations/TaSTT_Emerge_000.anim b/Animations/TaSTT_Emerge_000.anim index 4cfce83..97576e1 100644 --- a/Animations/TaSTT_Emerge_000.anim +++ b/Animations/TaSTT_Emerge_000.anim @@ -32,7 +32,7 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: material.Ray_March_Emerge + attribute: material._Emerge path: World Constraint/Container/TaSTT classID: 23 script: {fileID: 0} @@ -88,7 +88,7 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: material.Ray_March_Emerge + attribute: material._Emerge path: World Constraint/Container/TaSTT classID: 23 script: {fileID: 0} diff --git a/Animations/TaSTT_Emerge_100.anim b/Animations/TaSTT_Emerge_100.anim index 493225f..e33cdda 100644 --- a/Animations/TaSTT_Emerge_100.anim +++ b/Animations/TaSTT_Emerge_100.anim @@ -32,7 +32,7 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: material.Ray_March_Emerge + attribute: material._Emerge path: World Constraint/Container/TaSTT classID: 23 script: {fileID: 0} @@ -114,7 +114,7 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: material.Ray_March_Emerge + attribute: material._Emerge path: World Constraint/Container/TaSTT classID: 23 script: {fileID: 0} diff --git a/Scripts/generate_params.py b/Scripts/generate_params.py index badccc2..317a4d5 100644 --- a/Scripts/generate_params.py +++ b/Scripts/generate_params.py @@ -65,7 +65,7 @@ def generate(): result += generate_utils.replaceMacros(BOOL_PARAM, params) params["PARAM_NAME"] = generate_utils.getScaleParam() - params["DEFAULT_FLOAT"] = "0.1" + params["DEFAULT_FLOAT"] = "0.05" result += generate_utils.replaceMacros(FLOAT_PARAM, params) params["DEFAULT_FLOAT"] = "0" diff --git a/Shaders/TaSTT_lighting.cginc b/Shaders/TaSTT_lighting.cginc index 10bfd0c..651d331 100644 --- a/Shaders/TaSTT_lighting.cginc +++ b/Shaders/TaSTT_lighting.cginc @@ -11,38 +11,8 @@ SamplerState linear_repeat_sampler; -float BG_Enable; -Texture2D BG_BaseColor; -Texture2D BG_NormalMap; -Texture2D BG_Metallic; -Texture2D BG_Smoothness; -float BG_Smoothness_Invert; -float BG_NormalStrength; -float4 BG_BaseColor_ST; -float4 BG_NormalMap_ST; -float4 BG_Metallic_ST; -float4 BG_Smoothness_ST; - -fixed4 Text_Color; -fixed4 Background_Color; -fixed4 Margin_Color; - -float Metallic; -float Smoothness; -float Emissive; - -float Render_Margin; -float Render_Visual_Indicator; -float Margin_Scale; -float Margin_Rounding_Scale; -float Enable_Margin_Effect_Squares; -float Enable_Ray_March; - float _TaSTT_Indicator_0; float _TaSTT_Indicator_1; -static const float3 TaSTT_Indicator_Color_0 = HSVtoRGB(float3(0.00, 0.7, 1.0)); -static const float3 TaSTT_Indicator_Color_1 = HSVtoRGB(float3(0.07, 0.7, 1.0)); -static const float3 TaSTT_Indicator_Color_2 = HSVtoRGB(float3(0.30, 0.7, 1.0)); fixed4 float3tofixed4(in float3 f3, in float alpha) { @@ -85,347 +55,17 @@ v2f vert(appdata v) o.worldPos = mul(unity_ObjectToWorld, v.position); o.normal = UnityObjectToWorldNormal(v.normal); - o.uv.xy = TRANSFORM_TEX(v.uv, BG_BaseColor); - o.uv.zw = 1.0 - v.uv; + o.uv = v.uv; getVertexLightColor(o); return o; } -// dist = sqrt(dx^2 + dy^2) = sqrt(<dx,dy> * <dx,dy>) -bool InRadius2(float2 uv, float2 pos, float radius2) -{ - float2 delta = uv - pos; - return dot(delta, delta) < radius2; -} - -bool InMargin(float2 uv, float2 margin) -{ - bool b0 = uv.x < margin.x; - bool b1 = uv.x > 1 - margin.x; - bool b2 = uv.y < margin.y; - bool b3 = uv.y > 1 - margin.y; - - // De Morgan's law: - // a OR b = !(!a AND !b) - return !(!b0 * !b1 * !b2 * !b3); -} - -bool InSpeechIndicator(float2 uv, float2 margin) -{ - // Margin is uv_margin/2 wide/tall. - // We want a circle whose radius is ~80% of that. - float radius_factor = 0.95; - float radius = margin.x * radius_factor; - // We want this circle to be centered halfway through the margin - // vertically, and at 1.5x the margin width horizontally. - float2 indicator_center = float2(margin.x + radius, margin.y * 0.5); - // Finally, translate it to the top of the board instead of the - // bottom. - indicator_center.y = 1.0 - indicator_center.y; - - return Render_Visual_Indicator && InRadius2(uv, indicator_center, radius * radius); -} - -bool InMarginRounding(float2 uv, float2 margin, float rounding, bool interior) -{ - if (!interior) { - rounding += margin.x; - margin = float2(0, 0); - float err_margin = 0.001; - if (uv.x < err_margin || uv.x > 1.0 - err_margin || - uv.y < err_margin || uv.y > 1.0 - err_margin) { - return true; - } - } - - // This is the center of a circle whose perimeter touches the - // upper left corner of the margin. - float2 c0 = float2(rounding + margin.x, rounding + margin.y); - if (uv.x < c0.x && uv.y < c0.y && uv.x > margin.x && uv.y > margin.y && !InRadius2(uv, c0, rounding * rounding)) { - return true; - } - c0 = float2(rounding + margin.x, 1 - (rounding + margin.y)); - if (uv.x < c0.x && uv.y > c0.y && uv.x > margin.x && uv.y < 1 - margin.y && !InRadius2(uv, c0, rounding * rounding)) { - return true; - } - c0 = float2(1 - (rounding + margin.x), 1 - (rounding + margin.y)); - if (uv.x > c0.x && uv.y > c0.y && uv.x < 1 - margin.x && uv.y < 1 - margin.y && !InRadius2(uv, c0, rounding * rounding)) { - return true; - } - c0 = float2(1 - (rounding + margin.x), rounding + margin.y); - if (uv.x > c0.x && uv.y < c0.y && uv.x < 1 - margin.x && uv.y > margin.y && !InRadius2(uv, c0, rounding * rounding)) { - return true; - } - - return false; -} - -fixed sq_dist(fixed2 p0, fixed2 p1) -{ - fixed2 delta = p1 - p0; - //return abs(delta.x) + abs(delta.y); - return max(abs(delta.x), abs(delta.y)); -} - -fixed4 effect_squares (v2f i) -{ - float2 uv = i.uv.zw; - uv.y *= 2; // Text box has 2:1 aspect ratio - const fixed time = _Time.y; - - fixed theta = PI/4 + sin(time / 4) * 0.1; - fixed2x2 rot = - fixed2x2(cos(theta), -1 * sin(theta), - sin(theta), cos(theta)); - - #define NSQ_X 9.0 - #define NSQ_Y 5.0 - - // Map uv from [0, 1] to [-.5, .5]. - fixed2 p = uv - 0.5; - p *= fixed2(NSQ_X, NSQ_Y); - p = mul(rot, p); - p -= 0.5; - - // See how far we are from the nearest grid point - fixed2 intra_pos = frac(p); - fixed2 intra_center = fixed2(0.5, 0.5); - fixed intra_dist = sq_dist(intra_pos, intra_center); - - fixed st0 = (sin(time) + 1) / 2; - fixed st1 = (sin(time + PI/8) + 1) / 2; - fixed st2 = (sin(time + PI/2) + 1) / 2; - fixed st3 = (sin(time + PI/2 + PI/8) + 1) / 2; - - fixed2 center = fixed2(0, 0); - center = mul(rot, center); - center -= 0.5; - fixed2 rot_lim = fixed2(NSQ_X, NSQ_Y); - rot_lim = mul(rot, rot_lim); - rot_lim -= 0.5; - - float v = 0; - float x = 0; - - if (intra_dist > 0.5 * (0.5 + sin(time * 1.5) * 0.1)) { - v = intra_dist; - } else { - v = 0; - } - - fixed extra_dist = sq_dist(p, center); - fixed check = max(rot_lim.x, rot_lim.y) / 2; - if (extra_dist > check * st0) { - v = 1.0 - v; - } - if (extra_dist > check * st1) { - v = 1.0 - v; - } - if (extra_dist > check * st2) { - v = 1.0 - v; - } - if (extra_dist > check * st3) { - v = 1.0 - v; - } else { - x = 0.50; - } - - fixed3 hsv; - hsv[0] = (v * 0.2 * (1 - x * .8) + 0.55) - x; - hsv[1] = 0.7; - hsv[2] = 0.8; - - fixed3 col = HSVtoRGB(hsv); - - return fixed4(col, 1.0); -} - -fixed4 margin_effect(v2f i) -{ - if (Enable_Margin_Effect_Squares) { - return effect_squares(i); - } else { - return Margin_Color; - } -} - -fixed4 light(v2f i, - Texture2D albedo_map, - Texture2D normal_map, - float normal_str, - Texture2D metallic_map, - Texture2D smoothness_map, - float invert_smoothness, - Texture2D emission_mask, - float3 emission_color, - out float depth) -{ - initNormal(i); - - depth = getWorldSpaceDepth(i.worldPos); - - float2 iddx = ddx(i.uv.x); - float2 iddy = ddy(i.uv.y); - fixed4 albedo = albedo_map.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - - fixed3 normal = UnpackScaleNormal( - normal_map.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy), - normal_str); - // Swap Y and Z - normal = normal.xzy; - - float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); - - float metallic = metallic_map.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - - float3 specular_tint; - float one_minus_reflectivity; - albedo.rgb = DiffuseAndSpecularFromMetallic( - albedo, metallic, specular_tint, one_minus_reflectivity); - - UnityIndirect indirect_light; - indirect_light.diffuse = 0; - indirect_light.specular = 0; - - float smoothness = smoothness_map.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - if (invert_smoothness) { - smoothness = 1 - smoothness; - } - - fixed3 emission = emission_mask.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - - fixed3 pbr = UNITY_BRDF_PBS(albedo, specular_tint, - one_minus_reflectivity, smoothness, - i.normal, view_dir, GetLight(i), GetIndirect(i, view_dir, smoothness)).rgb; - pbr.rgb += emission; - - return fixed4(pbr, albedo.a); -} - -fixed4 light(v2f i, fixed4 unlit, out float depth) -{ - depth = getWorldSpaceDepth(i.worldPos); - - // Get color in spherical harmonics - fixed3 albedo = unlit.rgb; - - float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); - - float3 specular_tint; - float one_minus_reflectivity; - albedo = DiffuseAndSpecularFromMetallic( - albedo, Metallic, specular_tint, one_minus_reflectivity); - - UnityIndirect indirect_light; - indirect_light.diffuse = 0; - indirect_light.specular = 0; - - fixed3 pbr = UNITY_BRDF_PBS(albedo, specular_tint, - one_minus_reflectivity, Smoothness, - i.normal, view_dir, GetLight(i), GetIndirect(i, view_dir, Smoothness)).rgb; - - pbr = lerp(pbr.rgb, unlit.rgb, Emissive); - - return fixed4(pbr, unlit.a); -} - fixed4 frag(v2f i, out float depth : SV_DepthLessEqual) : SV_Target { - float2 uv = i.uv.zw; depth = -1000.0; - if (Enable_Ray_March) { - return stt_ray_march(i, depth); - } - - // Fix text orientation - uv.y = 0.5 - uv.y; - uv.x = 1.0 - uv.x; - uv.y *= 2; // Text box has 2:1 aspect ratio - - // Derived from github.com/pema99/shader-knowledge (MIT license). - if (unity_CameraProjection[2][0] != 0.0 || - unity_CameraProjection[2][1] != 0.0) { - uv.x = 1.0 - uv.x; - } - - float2 uv_margin = float2(Margin_Scale, Margin_Scale * 2) / 2; - if (Render_Margin) { - if (Margin_Rounding_Scale > 0.0) { - if (InMarginRounding(uv, uv_margin, Margin_Rounding_Scale, /*interior=*/true)) { - return light(i, margin_effect(i), depth); - } - if (InMarginRounding(uv, uv_margin, Margin_Rounding_Scale, /*interior=*/false)) { - return fixed4(0, 0, 0, 0); - } - } - if (InMargin(uv, uv_margin)) { - if (InSpeechIndicator(uv, uv_margin)) { - if (floor(_TaSTT_Indicator_0) == 1.0) { - // Actively speaking - return light(i, float3tofixed4(TaSTT_Indicator_Color_2, 1.0), depth); - } else if (floor(_TaSTT_Indicator_1) == 1.0) { - // Done speaking, waiting for paging. - return light(i, float3tofixed4(TaSTT_Indicator_Color_1, 1.0), depth); - } else { - // Neither speaking nor paging. - return light(i, float3tofixed4(TaSTT_Indicator_Color_0, 1.0), depth); - } - } - - if (Render_Margin) { - return light(i, margin_effect(i), depth); - } - } - } - - uv_margin *= 4; - float2 uv_with_margin = AddMarginToUV(uv, uv_margin); - - fixed4 text = GetLetter(uv_with_margin); - - if (text.a == 0) { - fixed4 bg; - if (BG_Enable) { - -#if 0 -fixed4 light(inout v2f i, - fixed4 albedo, - float metallic, - float smoothness) -#endif - - const float iddx = ddx(i.uv.x); - const float iddy = ddy(i.uv.y); - fixed4 albedo = BG_BaseColor.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - float metallic = BG_Metallic.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - float smoothness = BG_Smoothness.SampleGrad(linear_repeat_sampler, i.uv.xy, - iddx, iddy); - - bg = light(i, - albedo, metallic, smoothness); - } else { - bg = light(i, Background_Color, depth); - } - // Hack: If alpha (text.w) is less than 0.5, don't render it. This - // eliminates outlines around simple emotes with transparent backgrounds. - if (text.w > 0.5) { - // Use emote alpha to mix emote color with background color (compositing). - text.rgb = lerp(bg.rgb, text.rgb, text.w); - bg = light(i, fixed4(text.rgb, 1.0), depth); - } - return bg; - } else { - return light(i, Text_Color, depth); - } + return stt_ray_march(i, depth); } #endif // TASTT_LIGHTING diff --git a/Shaders/TaSTT_template.shader b/Shaders/TaSTT_template.shader index 3a6dd2b..cf658ea 100644 --- a/Shaders/TaSTT_template.shader +++ b/Shaders/TaSTT_template.shader @@ -2,35 +2,22 @@ {
Properties
{
- Text_Color ("Text Color", Color) = (1, 1, 1, 1)
- Background_Color ("Background Color", Color) = (0, 0, 0, 1)
- Margin_Color ("Margin color", Color) = (1, 1, 1, 1)
-
- [Gamma] Metallic("Metallic", Range(0, 1)) = 0.5
- Smoothness("Smoothness", Range(0, 1)) = 0.2
- Emissive("Emissive", Range(0, 1)) = 0.1
-
- [MaterialToggle] Render_Margin("Render margin", float) = 1
- [MaterialToggle] Render_Visual_Indicator("Render visual speech indicator", float) = 1
- Margin_Scale("Margin scale", float) = 0.03
- Margin_Rounding_Scale("Margin rounding scale", float) = 0.03
- [MaterialToggle] Enable_Margin_Effect_Squares(
- "Enable margin effect: Squares", float) = 0
- [MaterialToggle] Enable_Ray_March(
- "Enable ray marching", float) = 0
- Ray_March_Emerge("Ray march emerge", Range(0, 1)) = 1.0
-
- [MaterialToggle] Enable_Dithering("Enable dithering", float) = 1
-
- [MaterialToggle] BG_Enable("Enable custom background", float) = 0
- BG_BaseColor("Background base color", 2D) = "black" {}
- [NoScaleOffset] BG_NormalMap ("Background normal map", 2D) = "bump" {}
- BG_NormalStrength ("Background normal strength", Float) = 1
- BG_Smoothness("Background smoothness", 2D) = "black" {}
- [MaterialToggle]BG_Smoothness_Invert("Invert background smoothness", float) = 1
- BG_Metallic("Background metallic", 2D) = "black" {}
- BG_Emission_Mask("Background emission mask", 2D) = "black" {}
- BG_Emission_Color("Background emission color", Color) = (0, 0, 0)
+ _Text_Color ("Text color", Color) = (1, 1, 1, 1)
+ _Text_Metallic ("Text metallic", Range(0, 1)) = 0
+ _Text_Smoothness ("Text smoothness", Range(0, 1)) = 0
+ _Text_Emissive ("Text emission", Range(0, 1)) = 0.2
+
+ _BG_Color ("Background color", Color) = (0, 0, 0, 1)
+ _BG_Metallic ("Background metallic", Range(0, 1)) = 0
+ _BG_Smoothness ("Background smoothness", Range(0, 1)) = 0
+ _BG_Emissive ("Background emission", Range(0, 1)) = 0.2
+
+ _Frame_Color ("Frame color", Color) = (1, 1, 1, 1)
+ _Frame_Metallic ("Frame metallic", Range(0, 1)) = 0
+ _Frame_Smoothness ("Frame smoothness", Range(0, 1)) = 0
+ _Frame_Emissive ("Frame emission", Range(0, 1)) = 0.2
+
+ _Emerge("Emerge animation time", Range(0, 1)) = 1.0
[MaterialToggle] Enable_Custom_Cubemap("Enable custom cubemap", float) = 0
Custom_Cubemap("Custom cubemap", Cube) = "" {}
diff --git a/Shaders/eyes_data.cginc b/Shaders/eyes_data.cginc index d789116..0ab3127 100644 --- a/Shaders/eyes_data.cginc +++ b/Shaders/eyes_data.cginc @@ -11,7 +11,7 @@ struct appdata struct v2f { float4 position : SV_POSITION; - float4 uv : TEXCOORD0; + float2 uv : TEXCOORD0; float3 normal : TEXCOORD1; float3 worldPos : TEXCOORD2; diff --git a/Shaders/iq_sdf.cginc b/Shaders/iq_sdf.cginc index d82e24c..7951261 100644 --- a/Shaders/iq_sdf.cginc +++ b/Shaders/iq_sdf.cginc @@ -130,6 +130,13 @@ float smoothstep_quintic(float x) return x*x*x*(x*(x*6.0-15.0)+10.0); } +float distance_from_line_segment( float3 p, float3 a, float3 b, float r ) +{ + float3 pa = p - a, ba = b - a; + float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); + return length( pa - ba*h ) - r; +} + // End licensed section #endif // __IQ_SDF_INC__ diff --git a/Shaders/ray_march.cginc b/Shaders/ray_march.cginc index 0fd5c78..e149d0b 100644 --- a/Shaders/ray_march.cginc +++ b/Shaders/ray_march.cginc @@ -10,7 +10,22 @@ #include "poi.cginc" #include "stt_text.cginc" -float Ray_March_Emerge; +float _Emerge; + +float4 _Text_Color; +float _Text_Metallic; +float _Text_Smoothness; +float _Text_Emissive; + +float4 _BG_Color; +float _BG_Metallic; +float _BG_Smoothness; +float _BG_Emissive; + +float4 _Frame_Color; +float _Frame_Metallic; +float _Frame_Smoothness; +float _Frame_Emissive; // Allows us to divide [0,1] into `n_phases` equal-sized slices and remap `r` // onto the `nth_phase`. @@ -63,18 +78,18 @@ float distance_from_rect_pyramid_frame(float3 p, float dx, float dy, float h, fl return dist; } -float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, out float2 text_uv) +#define OBJ_ID_NONE 0 +#define OBJ_ID_FRAME 1 +#define OBJ_ID_BG 2 + +float stt_map(float3 p, out int obj_id, out float2 text_uv) { - hsv[0] = 0; - hsv[1] = 1; - hsv[2] = 1; - smoothness = 0.3; - alpha = 0; + obj_id = OBJ_ID_NONE; - float p0r = get_phase_fraction(Ray_March_Emerge, 0, 4); - float p1r = get_phase_fraction(Ray_March_Emerge, 1, 4); - float p2r = get_phase_fraction(Ray_March_Emerge, 2, 4); - float p3r = get_phase_fraction(Ray_March_Emerge, 3, 4); + float p0r = get_phase_fraction(_Emerge, 0, 4); + float p1r = get_phase_fraction(_Emerge, 1, 4); + float p2r = get_phase_fraction(_Emerge, 2, 4); + float p3r = get_phase_fraction(_Emerge, 3, 4); float dist = 1000 * 1000 * 1000; float3 box_scale_g = float3(1, 1, .85); @@ -100,7 +115,7 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o float d = distance_from_box_frame(pp, box_sz, box_thck); - alpha = (d < dist) * 1 + (d >= dist) * alpha; + obj_id = lerp(obj_id, OBJ_ID_FRAME, d < dist); dist = min(dist, d); } { @@ -129,9 +144,7 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o bool in_mirror = !(unity_CameraProjection[2][0] == 0.0 && unity_CameraProjection[2][1] == 0.0); text_uv = lerp(text_uv, float2(1.0 - text_uv.x, text_uv.y), in_mirror); - alpha = (d < dist) * 1 + (d >= dist) * alpha; - hsv[1] = (d < dist) * 0 + (d >= dist) * hsv[1]; - hsv[2] = (d < dist) * 0 + (d >= dist) * hsv[2]; + obj_id = lerp(obj_id, OBJ_ID_BG, d < dist); dist = min(dist, d); } { @@ -159,6 +172,7 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o skew = lerp(0, skew, p3r); float d = distance_from_rect_pyramid_frame(pp, edgex, edgey, height, r, skew); + obj_id = lerp(obj_id, OBJ_ID_FRAME, d < dist); dist = min(dist, d); } @@ -173,13 +187,11 @@ float3 stt_calculate_normal(in float3 p) // Calculate the 3D gradient. By definition, the gradient is orthogonal // (normal) to the surface. - float3 hsv; - float smoothness; - float alpha; + float obj_id; float2 text_uv; - float gradient_x = stt_map(p + small_step.xyy, hsv, smoothness, alpha, text_uv) - stt_map(p - small_step.xyy, hsv, smoothness, alpha, text_uv); - float gradient_y = stt_map(p + small_step.yxy, hsv, smoothness, alpha, text_uv) - stt_map(p - small_step.yxy, hsv, smoothness, alpha, text_uv); - float gradient_z = stt_map(p + small_step.yyx, hsv, smoothness, alpha, text_uv) - stt_map(p - small_step.yyx, hsv, smoothness, alpha, text_uv); + float gradient_x = stt_map(p + small_step.xyy, obj_id, text_uv) - stt_map(p - small_step.xyy, obj_id, text_uv); + float gradient_y = stt_map(p + small_step.yxy, obj_id, text_uv) - stt_map(p - small_step.yxy, obj_id, text_uv); + float gradient_z = stt_map(p + small_step.yyx, obj_id, text_uv) - stt_map(p - small_step.yyx, obj_id, text_uv); float3 normal = float3(gradient_x, gradient_y, gradient_z); @@ -195,11 +207,7 @@ float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth) float distance_to_closest = 1; #define STT_RAY_MARCH_STEPS 32 - float4 color = 0; - float metallic = 0.5; - float smoothness; - float alpha; - float3 hsv; + float obj_id; float2 text_uv; for (int i = 0; i < STT_RAY_MARCH_STEPS && @@ -207,33 +215,48 @@ float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth) total_distance_traveled < MAXIMUM_TRACE_DISTANCE; i++) { current_position = ro + total_distance_traveled * rd; - distance_to_closest = stt_map(current_position, hsv, smoothness, alpha, text_uv); + distance_to_closest = stt_map(current_position, obj_id, text_uv); total_distance_traveled += distance_to_closest; } + obj_id = lerp(0, obj_id, distance_to_closest < MINIMUM_HIT_DISTANCE); float3 normal = stt_calculate_normal(current_position); v2f_i.normal = normalize(mul(unity_ObjectToWorld, normal)); float epsilon = .005; + float letter_mask = 0; if (text_uv.x > epsilon && text_uv.x < 1 - epsilon && text_uv.y > epsilon && text_uv.y < 1 - epsilon) { text_uv.y = 1.0 - text_uv.y; // Make backside render left-to-right. text_uv.x = lerp(text_uv.x, 1.0 - text_uv.x, (normal.y + 1) / 2); - hsv[0] = 0; text_uv = AddMarginToUV(1.0 - text_uv, .01); - hsv[1] = 0; - hsv[2] = GetLetter(text_uv); + letter_mask = GetLetter(text_uv); } + float4 text = light(v2f_i, _Text_Color, _Text_Metallic, _Text_Smoothness); + text += _Text_Color * _Text_Emissive; + text = clamp(text, 0, 1); + + float4 bg = light(v2f_i, _BG_Color, _BG_Metallic, _BG_Smoothness); + bg += _BG_Color * _BG_Emissive; + bg = clamp(bg, 0, 1); + + float4 frame = light(v2f_i, _Frame_Color, _Frame_Metallic, _Frame_Smoothness); + frame += _Frame_Color * _Frame_Emissive; + frame = clamp(frame, 0, 1); + depth = getWorldSpaceDepth(mul(unity_ObjectToWorld, float4(current_position, 1.0)).xyz); - color.xyz = HSVtoRGB(hsv); - color.w = alpha; - depth = lerp(-1000, depth, distance_to_closest < MINIMUM_HIT_DISTANCE); - fixed4 lit_color = light(v2f_i, color, metallic, smoothness); - fixed4 shaded_color = lerp(lit_color, color, 0.2); - return lerp(0, shaded_color, distance_to_closest < MINIMUM_HIT_DISTANCE); + switch ((int) obj_id) { + case OBJ_ID_NONE: + depth = -1000; + return 0; + case OBJ_ID_FRAME: + return frame; + case OBJ_ID_BG: + return lerp(bg, text, letter_mask); + } } float4 stt_ray_march(inout v2f v2f_i, inout float depth) diff --git a/UnityAssets/Materials/TaSTT_Text.mat b/UnityAssets/Materials/TaSTT_Text.mat index c7da6e2..3e28c5a 100644 --- a/UnityAssets/Materials/TaSTT_Text.mat +++ b/UnityAssets/Materials/TaSTT_Text.mat @@ -7,9 +7,9 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: STTExperiment + m_Name: TaSTT_Chatbox m_Shader: {fileID: 4800000, guid: feba055fa9e7f9543aaae032a30ec878, type: 3} - m_ShaderKeywords: BG_SMOOTHNESS_INVERT_ON ENABLE_DITHERING_ON ENABLE_RAY_MARCH_ON + m_ShaderKeywords: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -19,50 +19,6 @@ Material: m_SavedProperties: serializedVersion: 3 m_TexEnvs: - - BG_BaseColor: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - BG_Emission_Mask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - BG_Metallic: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - BG_NormalMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - BG_Smoothness: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - Custom_Cubemap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _BumpMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailAlbedoMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailNormalMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _EmissionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - _Font_0x0000_0x1FFF: m_Texture: {fileID: 2800000, guid: 0417deb9fee97e24e9099569bed34c6c, type: 3} m_Scale: {x: 1, y: 1} @@ -91,63 +47,6 @@ Material: m_Texture: {fileID: 2800000, guid: e8c2974f31efa7a4e9e7588c90561a85, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - _Img_0xE000_0xE03F: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MainTex: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MetallicGlossMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _OcclusionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _ParallaxMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - - BG_Enable: 0 - - BG_NormalStrength: 1 - - BG_Smoothness_Invert: 1 - - Emissive: 0.1 - - Enable_Custom_Cubemap: 0 - - Enable_Dithering: 1 - - Enable_Margin_Effect_Squares: 0 - - Enable_Ray_March: 1 - - Margin_Rounding_Scale: 0.15 - - Margin_Scale: 0.1 - - Metallic: 0.5 - - Render_Margin: 0 - - Render_Visual_Indicator: 0 - - Smoothness: 0.2 - - _BumpScale: 1 - - _Cutoff: 0.5 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _TaSTT_Indicator_0: 0 - - _TaSTT_Indicator_1: 0 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - BG_Emission_Color: {r: 0, g: 0, b: 0, a: 1} - - Background_Color: {r: 0, g: 0, b: 0, a: 1} - - Margin_Color: {r: 1, g: 1, b: 1, a: 1} - - Text_Color: {r: 1, g: 1, b: 1, a: 1} - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_Floats: [] + m_Colors: [] + |
