summaryrefslogtreecommitdiffstats
path: root/Shaders
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-08-10 18:22:03 -0700
committeryum <yum.food.vr@gmail.com>2023-08-10 18:22:03 -0700
commitf7fbd1965543f47596eae491bbe8947bf44d1518 (patch)
treee1cd568d74f2f2a63fd5b2ff5b86eae099bcf80e /Shaders
parente9a8b991552d08823b0f44b238f4afaede53c54e (diff)
Add basic PBR parameters to new shader
No UVs for raymarched geometry yet, so drop textures. Also drop most old shader settings.
Diffstat (limited to 'Shaders')
-rw-r--r--Shaders/TaSTT_lighting.cginc364
-rw-r--r--Shaders/TaSTT_template.shader45
-rw-r--r--Shaders/eyes_data.cginc2
-rw-r--r--Shaders/iq_sdf.cginc7
-rw-r--r--Shaders/ray_march.cginc95
5 files changed, 85 insertions, 428 deletions
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)