summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Shaders/TaSTT_lighting.cginc14
-rw-r--r--Shaders/TaSTT_template.shader2
-rw-r--r--Shaders/pbr.cginc8
-rw-r--r--Shaders/ray_march.cginc39
4 files changed, 28 insertions, 35 deletions
diff --git a/Shaders/TaSTT_lighting.cginc b/Shaders/TaSTT_lighting.cginc
index 651d331..bc3f3f3 100644
--- a/Shaders/TaSTT_lighting.cginc
+++ b/Shaders/TaSTT_lighting.cginc
@@ -9,20 +9,6 @@
#include "stt_generated.cginc"
#include "stt_text.cginc"
-SamplerState linear_repeat_sampler;
-
-float _TaSTT_Indicator_0;
-float _TaSTT_Indicator_1;
-
-fixed4 float3tofixed4(in float3 f3, in float alpha)
-{
- return fixed4(
- f3.r,
- f3.g,
- f3.b,
- alpha);
-}
-
void getVertexLightColor(inout v2f i)
{
#if defined(VERTEXLIGHT_ON)
diff --git a/Shaders/TaSTT_template.shader b/Shaders/TaSTT_template.shader
index d97bf1e..e3e9a5d 100644
--- a/Shaders/TaSTT_template.shader
+++ b/Shaders/TaSTT_template.shader
@@ -28,8 +28,6 @@
_Font_0xA000_0xBFFF ("_Font 5 (unicode 0xA000 - 0xBFFFF)", 2D) = "white" {}
_Font_0xC000_0xDFFF ("_Font 6 (unicode 0xC000 - 0xDFFFF)", 2D) = "white" {}
_Img_0xE000_0xE03F ("_Images", 2D) = "white" {}
- _TaSTT_Indicator_0("_TaSTT_Indicator_0", float) = 0
- _TaSTT_Indicator_1("_TaSTT_Indicator_1", float) = 0
// %TEMPLATE__UNITY_ROW_COL_PARAMS%
}
diff --git a/Shaders/pbr.cginc b/Shaders/pbr.cginc
index c890034..9b46f8e 100644
--- a/Shaders/pbr.cginc
+++ b/Shaders/pbr.cginc
@@ -56,8 +56,8 @@ void initNormal(inout v2f i)
i.normal = normalize(i.normal);
}
-fixed4 light(inout v2f i,
- fixed4 albedo,
+float4 light(inout v2f i,
+ float4 albedo,
float metallic,
float smoothness)
{
@@ -69,7 +69,7 @@ fixed4 light(inout v2f i,
albedo, metallic, specular_tint, one_minus_reflectivity);
float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos);
- fixed3 pbr = UNITY_BRDF_PBS(albedo,
+ float3 pbr = UNITY_BRDF_PBS(albedo,
specular_tint,
one_minus_reflectivity,
smoothness,
@@ -78,7 +78,7 @@ fixed4 light(inout v2f i,
GetLight(i),
GetIndirect(i, view_dir, smoothness)).rgb;
- return fixed4(saturate(pbr), albedo.a);
+ return float4(saturate(pbr), albedo.a);
}
float getWorldSpaceDepth(in float3 world_pos)
diff --git a/Shaders/ray_march.cginc b/Shaders/ray_march.cginc
index 529418a..bdedc8b 100644
--- a/Shaders/ray_march.cginc
+++ b/Shaders/ray_march.cginc
@@ -49,6 +49,9 @@ float _Frame_Emissive;
#define MY_SPACE_TO_WORLD \
mul(MY_SPACE_TO_OBJ, unity_ObjectToWorld)
+#define MINIMUM_HIT_DISTANCE .00002 * MY_COORD_SCALE
+#define MAXIMUM_TRACE_DISTANCE 2 * MY_COORD_SCALE
+
// Allows us to divide [0,1] into `n_phases` equal-sized slices and remap `r`
// onto the `nth_phase`.
//
@@ -243,13 +246,11 @@ float stt_map(float3 p, out int obj_id, out float2 text_uv)
// Calculate normals for ray-marched STT structure.
float3 stt_calculate_normal(in float3 p)
{
- // Setting a very low value makes the surface normals look noisy. In this
- // case. that's desired, since it produces a glittery effect.
const float3 small_step = float3(0.0001, 0.0, 0.0);
// Calculate the 3D gradient. By definition, the gradient is orthogonal
// (normal) to the surface.
- float obj_id;
+ int obj_id;
float2 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);
@@ -274,23 +275,14 @@ float get_letter_mask(float2 text_uv, bool mirror)
return 0;
}
-float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth)
+float3 stt_march(float3 ro, float3 rd, out int obj_id, out float2 text_uv, int steps)
{
float total_distance_traveled = 0.0;
- const float MINIMUM_HIT_DISTANCE = .00002 * MY_COORD_SCALE;
- const float MAXIMUM_TRACE_DISTANCE = 2 * MY_COORD_SCALE;
float3 current_position = 0;
float distance_to_closest = 1;
- // TODO(yum) remove
- float3 old_world_pos = v2f_i.worldPos;
- depth = getWorldSpaceDepth(old_world_pos);
-
#define STT_RAY_MARCH_STEPS 48
- float obj_id;
- float2 text_uv;
-
- for (int i = 0; (i < STT_RAY_MARCH_STEPS) *
+ for (int i = 0; (i < steps) *
(distance_to_closest > MINIMUM_HIT_DISTANCE/4) *
(total_distance_traveled < MAXIMUM_TRACE_DISTANCE); i++)
{
@@ -300,6 +292,20 @@ float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth)
}
obj_id = lerp(OBJ_ID_NONE, obj_id, distance_to_closest < MINIMUM_HIT_DISTANCE);
+ return current_position;
+}
+
+float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth)
+{
+
+ // TODO(yum) remove
+ float3 old_world_pos = v2f_i.worldPos;
+ depth = getWorldSpaceDepth(old_world_pos);
+
+ int obj_id;
+ float2 text_uv;
+ float3 current_position = stt_march(ro, rd, obj_id, text_uv, /*steps=*/48);
+
float3 normal = stt_calculate_normal(current_position);
v2f_i.normal = normalize(mul(MY_SPACE_TO_WORLD, normal));
v2f_i.worldPos = mul(MY_SPACE_TO_WORLD, float4(current_position, 1.0)).xyz;
@@ -318,11 +324,14 @@ float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth)
frame += _Frame_Color * _Frame_Emissive;
frame = clamp(frame, 0, 1);
+ frame += _Frame_Color * _Frame_Emissive;
+ frame = clamp(frame, 0, 1);
+
// TODO(yum) restore
//depth = getWorldSpaceDepth(v2f_i.worldPos);
[forcecase]
- switch ((int) obj_id) {
+ switch (obj_id) {
case OBJ_ID_NONE:
depth = -1000;
return 0;