diff options
Diffstat (limited to 'Shaders')
| -rw-r--r-- | Shaders/.gitignore | 4 | ||||
| -rw-r--r-- | Shaders/Motion.cginc | 90 | ||||
| -rw-r--r-- | Shaders/PBS.shader | 65 | ||||
| -rw-r--r-- | Shaders/PBS_lighting.cginc | 322 | ||||
| -rw-r--r-- | Shaders/STT_generated_template.cginc | 19 | ||||
| -rw-r--r-- | Shaders/STT_text.cginc | 165 | ||||
| -rw-r--r-- | Shaders/TaSTT.shader.meta | 9 | ||||
| -rw-r--r-- | Shaders/TaSTT_lighting.cginc | 57 | ||||
| -rw-r--r-- | Shaders/TaSTT_template.shader | 85 | ||||
| -rw-r--r-- | Shaders/aa_sample_algorithm.py | 43 | ||||
| -rw-r--r-- | Shaders/eyes_data.cginc | 24 | ||||
| -rw-r--r-- | Shaders/hg_sdf.cginc | 187 | ||||
| -rw-r--r-- | Shaders/iq_sdf.cginc | 143 | ||||
| -rw-r--r-- | Shaders/math.cginc | 88 | ||||
| -rw-r--r-- | Shaders/pbr.cginc | 91 | ||||
| -rw-r--r-- | Shaders/pema99.cginc | 31 | ||||
| -rw-r--r-- | Shaders/poi.cginc | 60 | ||||
| -rw-r--r-- | Shaders/ray_march.cginc | 361 |
18 files changed, 0 insertions, 1844 deletions
diff --git a/Shaders/.gitignore b/Shaders/.gitignore deleted file mode 100644 index 6f40a98..0000000 --- a/Shaders/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# This should always be an empty file. I regenerate it sometimes but don't want -# to accidently check in those changes. -TaSTT.shader - diff --git a/Shaders/Motion.cginc b/Shaders/Motion.cginc deleted file mode 100644 index d6458e9..0000000 --- a/Shaders/Motion.cginc +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef MOTION_ -#define MOTION_ - -// xyz represent quaternion vector, w represents theta. -typedef float4 Quaternion; - -// Math from here: -// https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation -float3 qrot(in float3 v, in Quaternion q) -{ - float a = q.w; - float b = q.x; - float c = q.y; - float d = q.z; - - float a2 = a*a; - float b2 = b*b; - float c2 = c*c; - float d2 = d*d; - - float3x3 rot = float3x3( - (a2 + b2 - c2) - d2, 2*b*c - 2*a*d, 2*b*d + 2*a*c, - 2*b*c + 2*a*d, (a2 - b2) + (c2 - d2), 2*c*d - 2*a*b, - 2*b*d - 2*a*c, 2*c*d + 2*a*b, ((a2 - b2) - c2) + d2 - ); - - return mul(rot, v); -} - -Quaternion qinv(in Quaternion q) -{ - return Quaternion(q.xyz, -q.w); -} - -// Multiply two quaternions. -// Math from here: https://www.haroldserrano.com/blog/quaternions-in-computer-graphics -Quaternion qmul(in Quaternion a, in Quaternion b) -{ - return Quaternion(a.w * b.xyz + b.w * a.xyz + cross(a.xyz, b.xyz), a.w * b.w - dot(a.xyz, b.xyz)); -} - -float4 affine3(in float3 m) -{ - return float4(m, 1.0); -} - -float4x4 affine3x3(in float3x3 m) -{ - return float4x4( - m[0][0], m[0][1], m[0][2], 0, - m[1][0], m[1][1], m[1][2], 0, - m[2][0], m[2][1], m[2][2], 0, - 0, 0, 0, 1 - ); -} - -float4x4 eye() -{ - return float4x4( - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ); -} - -// Return affine translation matrix. -float4x4 translate(in float dx, in float dy, in float dz) -{ - return float4x4( - 1, 0, 0, dx, - 0, 1, 0, dy, - 0, 0, 1, dz, - 0, 0, 0, 1 - ); -} - -// Return affine scaling matrix. -float4x4 scale(in float sx, in float sy, in float sz) -{ - return float4x4( - sx, 0, 0, 0, - 0, sy, 0, 0, - 0, 0, sz, 0, - 0, 0, 0, 1 - ); -} - -#endif // MOTION_ - diff --git a/Shaders/PBS.shader b/Shaders/PBS.shader deleted file mode 100644 index e0b39da..0000000 --- a/Shaders/PBS.shader +++ /dev/null @@ -1,65 +0,0 @@ -Shader "TaSTT/Simple_PBS"
-{
- Properties
- {
- [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)
-
- [MaterialToggle] Enable_Custom_Cubemap("Enable custom cubemap", float) = 0
- Custom_Cubemap("Custom cubemap", Cube) = "" {}
-
- // %TEMPLATE__UNITY_ROW_COL_PARAMS%
- }
- SubShader
- {
- Pass {
- Tags {
- "RenderType"="Opaque"
- "Queue"="AlphaTest+499"
- "LightMode" = "ForwardBase"
- }
- Blend SrcAlpha OneMinusSrcAlpha
-
- CGPROGRAM
- #pragma target 3.0
-
- #pragma multi_compile _ VERTEXLIGHT_ON
-
- #pragma vertex vert
- #pragma fragment frag
-
- #define FORWARD_BASE_PASS
-
- #include "PBS_lighting.cginc"
- ENDCG
- }
- Pass {
- Tags {
- "RenderType" = "Opaque"
- "LightMode" = "ForwardAdd"
- "Queue"="AlphaTest+499"
- }
- Blend One One
- ZWrite Off
-
- CGPROGRAM
- #pragma target 3.0
-
- #pragma multi_compile_fwdadd
-
- #pragma vertex vert
- #pragma fragment frag
-
- #include "PBS_lighting.cginc"
- ENDCG
- }
- }
-}
-
diff --git a/Shaders/PBS_lighting.cginc b/Shaders/PBS_lighting.cginc deleted file mode 100644 index 13bde82..0000000 --- a/Shaders/PBS_lighting.cginc +++ /dev/null @@ -1,322 +0,0 @@ -#ifndef PBS_LIGHTING -#define PBS_LIGHTING - -#include "AutoLight.cginc" -#include "UnityPBSLighting.cginc" - -struct appdata -{ - float4 position : POSITION; - float2 uv : TEXCOORD0; - float3 normal : NORMAL; -}; - -struct v2f -{ - float4 position : SV_POSITION; - float4 uv : TEXCOORD0; - float3 normal : TEXCOORD1; - float3 worldPos : TEXCOORD2; - - #if defined(VERTEXLIGHT_ON) - float3 vertexLightColor : TEXCOORD3; - #endif -}; - -float BG_Enable; -sampler2D BG_BaseColor; -sampler2D BG_NormalMap; -sampler2D BG_Metallic; -sampler2D BG_Smoothness; -sampler2D BG_Emission_Mask; -float BG_Smoothness_Invert; -float BG_NormalStrength; -float3 BG_Emission_Color; -float4 BG_BaseColor_ST; -float4 BG_NormalMap_ST; -float4 BG_Metallic_ST; -float4 BG_Smoothness_ST; -float4 BG_Emission_Mask_ST; - -float Enable_Custom_Cubemap; -UNITY_DECLARE_TEXCUBE(Custom_Cubemap); - -void getVertexLightColor(inout v2f i) -{ - #if defined(VERTEXLIGHT_ON) - float3 light_pos = float3(unity_4LightPosX0.x, unity_4LightPosY0.x, - unity_4LightPosZ0.x); - float3 light_vec = light_pos - i.worldPos; - float3 light_dir = normalize(light_vec); - float ndotl = DotClamped(i.normal, light_dir); - // Light fills an expanding sphere with surface area 4 * pi * r^2. - // By conservation of energy, this means that at distance r, light intensity - // is proportional to 1/(r^2). - float attenuation = 1 / (1 + dot(light_vec, light_vec) * unity_4LightAtten0.x); - i.vertexLightColor = unity_LightColor[0].rgb * ndotl * attenuation; - - i.vertexLightColor = Shade4PointLights( - unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, - unity_LightColor[0].rgb, - unity_LightColor[1].rgb, - unity_LightColor[2].rgb, - unity_LightColor[3].rgb, - unity_4LightAtten0, i.worldPos, i.normal - ); - #endif -} - -v2f vert(appdata v) -{ - v2f o; - o.position = mul(UNITY_MATRIX_MVP, v.position); - 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; - getVertexLightColor(o); - return o; -} - -fixed sq_dist(fixed2 p0, fixed2 p1) -{ - fixed2 delta = p1 - p0; - return max(abs(delta.x), abs(delta.y)); -} - -float3 HUEtoRGB(in float H) -{ - float R = abs(H * 6 - 3) - 1; - float G = 2 - abs(H * 6 - 2); - float B = 2 - abs(H * 6 - 4); - return saturate(float3(R, G, B)); -} - -float3 HSVtoRGB(in float3 HSV) -{ - float3 RGB = HUEtoRGB(HSV.x); - return ((RGB - 1) * HSV.y + 1) * HSV.z; -} - -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; - - #define PI 3.1415926535 - 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) -{ - return effect_squares(i); -} - -UnityLight GetLight(v2f i) -{ - UNITY_LIGHT_ATTENUATION(attenuation, 0, i.worldPos); - float3 light_color = _LightColor0.rgb * attenuation; - - UnityLight light; - light.color = light_color; - #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) - light.dir = normalize(_WorldSpaceLightPos0.xyz - i.worldPos); - #else - light.dir = _WorldSpaceLightPos0.xyz; - #endif - light.ndotl = DotClamped(i.normal, light.dir); - - return light; -} - -UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { - UnityIndirect indirect; - indirect.diffuse = 0; - indirect.specular = 0; - - #if defined(VERTEXLIGHT_ON) - indirect.diffuse = i.vertexLightColor; - #endif - - #if defined(FORWARD_BASE_PASS) - indirect.diffuse += max(0, ShadeSH9(float4(i.normal, 1))); - float3 reflect_dir = reflect(-view_dir, i.normal); - // There's a nonlinear relationship between mipmap level and roughness. - float roughness = 1 - smoothness; - roughness *= 1.7 - .7 * roughness; - float3 env_sample; - if (Enable_Custom_Cubemap) { - env_sample = UNITY_SAMPLE_TEXCUBE_LOD( - Custom_Cubemap, - reflect_dir, - roughness * UNITY_SPECCUBE_LOD_STEPS); - } else { - env_sample = UNITY_SAMPLE_TEXCUBE_LOD( - unity_SpecCube0, - reflect_dir, - roughness * UNITY_SPECCUBE_LOD_STEPS); - } - indirect.specular = env_sample; - #endif - - return indirect; -} - -void initNormal(inout v2f i) -{ - if (BG_Enable) { - i.normal = UnpackScaleNormal( - tex2Dgrad(BG_NormalMap, i.uv.xy, ddx(i.uv.x), ddy(i.uv.y)), - BG_NormalStrength); - // Swap Y and Z - i.normal = i.normal.xzy; - } - i.normal = normalize(i.normal); -} - -fixed4 light(v2f i, - sampler2D albedo_map, - sampler2D normal_map, - float normal_str, - sampler2D metallic_map, - sampler2D smoothness_map, - float invert_smoothness, - sampler2D emission_mask, - float3 emission_color) -{ - initNormal(i); - - float2 iddx = ddx(i.uv.x); - float2 iddy = ddy(i.uv.y); - fixed4 albedo = tex2Dgrad(albedo_map, i.uv, iddx, iddy); - - fixed3 normal = UnpackScaleNormal( - tex2Dgrad(normal_map, i.uv.xy, iddx, iddy), - normal_str); - // Swap Y and Z - normal = normal.xzy; - - float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); - - float metallic = tex2Dgrad(metallic_map, 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 = tex2Dgrad(smoothness_map, i.uv.xy, iddx, iddy); - if (invert_smoothness) { - smoothness = 1 - smoothness; - } - - fixed3 emission = tex2Dgrad(emission_mask, i.uv.xy, iddx, iddy) * emission_color; - - 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 frag(v2f i) : SV_Target -{ - float2 uv = i.uv.zw; - // 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; - } - - if (BG_Enable) { - return light(i, - BG_BaseColor, - BG_NormalMap, - BG_NormalStrength, - BG_Metallic, - BG_Smoothness, - BG_Smoothness_Invert, - BG_Emission_Mask, - BG_Emission_Color); - } else { - return fixed4(1, 1, 1, 0); - } -} - -#endif // PBS_LIGHTING - diff --git a/Shaders/STT_generated_template.cginc b/Shaders/STT_generated_template.cginc deleted file mode 100644 index 9091e8e..0000000 --- a/Shaders/STT_generated_template.cginc +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __STT_GENERATED_INC__ -#define __STT_GENERATED_INC__ - -// %TEMPLATE__CG_ROW_COL_CONSTANTS% - -// %TEMPLATE__CG_ROW_COL_PARAMS% - -// Get the value of the parameter for the cell we're in. -uint GetLetterParameter(float2 uv) -{ - float CHAR_COL = floor(uv.x * BOARD_NCOLS); - float CHAR_ROW = floor(uv.y * BOARD_NROWS); - int res = 0; - - // %TEMPLATE__CG_LETTER_ACCESSOR% - return res; -} - -#endif // __STT_GENERATED_INC__ diff --git a/Shaders/STT_text.cginc b/Shaders/STT_text.cginc deleted file mode 100644 index 85c4a1b..0000000 --- a/Shaders/STT_text.cginc +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef __STT_TEXT_INC__ -#define __STT_TEXT_INC__ - -#include "stt_generated.cginc" - -float Enable_Dithering; - -SamplerState linear_clamp_sampler; - -Texture2D _Font_0x0000_0x1FFF; -float4 _Font_0x0000_0x1FFF_TexelSize; -Texture2D _Font_0x2000_0x3FFF; -float4 _Font_0x2000_0x3FFF_TexelSize; -Texture2D _Font_0x4000_0x5FFF; -float4 _Font_0x4000_0x5FFF_TexelSize; -Texture2D _Font_0x6000_0x7FFF; -float4 _Font_0x6000_0x7FFF_TexelSize; -Texture2D _Font_0x8000_0x9FFF; -float4 _Font_0x8000_0x9FFF_TexelSize; -Texture2D _Font_0xA000_0xBFFF; -float4 _Font_0xA000_0xBFFF_TexelSize; -Texture2D _Font_0xC000_0xDFFF; -float4 _Font_0xC000_0xDFFF_TexelSize; -Texture2D _Img_0xE000_0xE03F; -float4 _Img_0xE000_0xE03F_TexelSize; - -float2 AddMarginToUV(float2 uv, float2 margin) -{ - float2 lo = float2(-margin.x / 2, -margin.y / 2); - float2 hi = float2(1.0 + margin.x / 2, 1.0 + margin.y / 2); - - return clamp(lerp(lo, hi, uv), 0.0, 1.0); -} - -// Generate a random number on [0, 1]. -float prng(float2 p) -{ - return frac(sin(dot(p, float2(561.0, 885.0))) * 776.2) / 2.0; -} - -bool f3ltf3(float3 a, float3 b) -{ - return (a[0] < b[0]) * - (a[1] < b[1]) * - (a[2] < b[2]); -} - -// Write the nth letter in the current cell and return the value of the -// pixel. -// `texture_rows` and `texture_cols` indicate how many rows and columns are -// in the texture being sampled. -float2 GetLetterUV(float2 uv, int nth_letter, - float texture_cols, float texture_rows, - float board_cols, float board_rows, - float margin) -{ - // UV spans from [0,1] to [0,1]. - // 'U' is horizontal; cols. - // 'V' is vertical; rows. - // - // I want to divide the mesh into an m x n grid. - // I want to know what grid cell I'm in. This is simply u * m, v * n. - - // OK, I know what cell I'm in. Now I need to know how far across it I - // am. Produce a float in the range [0, 1). - float CHAR_FRAC_COL = uv.x * board_cols - floor(uv.x * board_cols); - float CHAR_FRAC_ROW = uv.y * board_rows - floor(uv.y * board_rows); - - // Avoid rendering pixels right on the edge of the slot. If we were to - // do this, then that value would get stretched due to clamping - // (AddMarginToUV), resulting in long lines on the edge of the display. - float lo = margin / 2; - float hi = 1.0 - margin / 2; - bool skip_result = (margin != 0) * - !(CHAR_FRAC_ROW > lo * - CHAR_FRAC_COL > lo * - CHAR_FRAC_ROW < hi * - CHAR_FRAC_COL < hi); - - float LETTER_COL = fmod(nth_letter, floor(texture_cols)); - float LETTER_ROW = floor(texture_rows) - floor(nth_letter / floor(texture_cols)); - - float LETTER_UV_ROW = (LETTER_ROW + CHAR_FRAC_ROW - 1.00) / texture_rows; - float LETTER_UV_COL = (LETTER_COL + CHAR_FRAC_COL) / texture_cols; - - float2 result; - result.x = LETTER_UV_COL; - result.y = LETTER_UV_ROW; - - return lerp(result, -1, skip_result);; -} - -float4 GetLetter(float2 uv) { - uint letter = GetLetterParameter(uv); - - float texture_cols; - float texture_rows; - float2 letter_uv; - bool is_emote = false; - - if (letter < 0xE000) { - letter_uv = GetLetterUV(uv, letter % 0x2000, TEXTURE_NCOLS, TEXTURE_NROWS, BOARD_NCOLS, BOARD_NROWS, /*margin=*/0); - } else { - is_emote = true; - texture_cols = 16.0; - texture_rows = 8.0; - // This will need to be updated if we create multiple emote textures. - letter_uv = GetLetterUV(uv, letter % 0x2000, texture_cols, texture_rows, BOARD_NCOLS, BOARD_NROWS, /*margin=*/0); - } - - bool discard_text = (letter_uv.x == -1) * (letter_uv.y == -1); - - const float iddx = ddx(uv.x); - const float iddy = ddy(uv.y); - - float4 text = float4(0, 0, 0, 0); - int which_texture = (int) floor(letter / (uint) (64 * 128)); - [forcecase] switch (which_texture) - { - case 0: - text = _Font_0x0000_0x1FFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 1: - text = _Font_0x2000_0x3FFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 2: - text = _Font_0x4000_0x5FFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 3: - text = _Font_0x6000_0x7FFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 4: - text = _Font_0x8000_0x9FFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 5: - text = _Font_0xA000_0xBFFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 6: - text = _Font_0xC000_0xDFFF.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - case 7: - text = _Img_0xE000_0xE03F.SampleGrad(linear_clamp_sampler, - letter_uv, iddx, iddy); - break; - default: - // Return some distinctive pattern that will look like a bug. - return float4(1, 0, _SinTime[0], 1); - } - - // The edges of each letter cell can be slightly grey due to mip maps. - // Detect this and shade it as the background. - float3 grey = 0.7; - bool disc = !(!f3ltf3(text.rgb, grey) * !discard_text * !is_emote); - return lerp(float4(text.rgb, 1), 0, disc); -} - -#endif // __STT_TEXT_INC__ - diff --git a/Shaders/TaSTT.shader.meta b/Shaders/TaSTT.shader.meta deleted file mode 100644 index 2b0abac..0000000 --- a/Shaders/TaSTT.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: feba055fa9e7f9543aaae032a30ec878 -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/Shaders/TaSTT_lighting.cginc b/Shaders/TaSTT_lighting.cginc deleted file mode 100644 index bc3f3f3..0000000 --- a/Shaders/TaSTT_lighting.cginc +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef TASTT_LIGHTING -#define TASTT_LIGHTING - -#include "AutoLight.cginc" -#include "UnityPBSLighting.cginc" -#include "ray_march.cginc" -#include "pbr.cginc" -#include "poi.cginc" -#include "stt_generated.cginc" -#include "stt_text.cginc" - -void getVertexLightColor(inout v2f i) -{ - #if defined(VERTEXLIGHT_ON) - float3 light_pos = float3(unity_4LightPosX0.x, unity_4LightPosY0.x, - unity_4LightPosZ0.x); - float3 light_vec = light_pos - i.worldPos; - float3 light_dir = normalize(light_vec); - float ndotl = DotClamped(i.normal, light_dir); - // Light fills an expanding sphere with surface area 4 * pi * r^2. - // By conservation of energy, this means that at distance r, light intensity - // is proportional to 1/(r^2). - float attenuation = 1 / (1 + dot(light_vec, light_vec) * unity_4LightAtten0.x); - i.vertexLightColor = unity_LightColor[0].rgb * ndotl * attenuation; - - i.vertexLightColor = Shade4PointLights( - unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, - unity_LightColor[0].rgb, - unity_LightColor[1].rgb, - unity_LightColor[2].rgb, - unity_LightColor[3].rgb, - unity_4LightAtten0, i.worldPos, i.normal - ); - #endif -} - -v2f vert(appdata v) -{ - v2f o; - o.position = UnityObjectToClipPos(v.position); - o.worldPos = mul(unity_ObjectToWorld, v.position); - o.normal = UnityObjectToWorldNormal(v.normal); - - o.uv = v.uv; - getVertexLightColor(o); - - return o; -} - -fixed4 frag(v2f i, out float depth : SV_DepthLessEqual) : SV_Target -{ - depth = -1000.0; - - return stt_ray_march(i, depth); -} - -#endif // TASTT_LIGHTING diff --git a/Shaders/TaSTT_template.shader b/Shaders/TaSTT_template.shader deleted file mode 100644 index e3e9a5d..0000000 --- a/Shaders/TaSTT_template.shader +++ /dev/null @@ -1,85 +0,0 @@ -Shader "TaSTT/Chatbox"
-{
- Properties
- {
- _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] _Ellipsis("Show ellipsis", float) = 0
-
- _Font_0x0000_0x1FFF ("_Font 0 (unicode 0x0000 - 0x1FFFF)", 2D) = "white" {}
- _Font_0x2000_0x3FFF ("_Font 1 (unicode 0x2000 - 0x3FFFF)", 2D) = "white" {}
- _Font_0x4000_0x5FFF ("_Font 2 (unicode 0x4000 - 0x5FFFF)", 2D) = "white" {}
- _Font_0x6000_0x7FFF ("_Font 3 (unicode 0x6000 - 0x7FFFF)", 2D) = "white" {}
- _Font_0x8000_0x9FFF ("_Font 4 (unicode 0x8000 - 0x9FFFF)", 2D) = "white" {}
- _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" {}
-
- // %TEMPLATE__UNITY_ROW_COL_PARAMS%
- }
- SubShader
- {
- Pass {
- Tags {
- "RenderType"="Opaque"
- "Queue"="AlphaTest+499"
- "LightMode" = "ForwardBase"
- }
- Blend SrcAlpha OneMinusSrcAlpha
- Cull Back
- ZWrite On
- ZTest LEqual
-
- CGPROGRAM
- #pragma target 5.0
-
- #pragma multi_compile _ VERTEXLIGHT_ON
-
- #pragma vertex vert
- #pragma fragment frag
-
- #define FORWARD_BASE_PASS
-
- #include "TaSTT_lighting.cginc"
- ENDCG
- }
- Pass {
- Tags {
- "RenderType" = "Opaque"
- "LightMode" = "ForwardAdd"
- "Queue"="AlphaTest+499"
- }
- Blend One One
- Cull Back
- ZWrite On
- ZTest LEqual
-
- CGPROGRAM
- #pragma target 5.0
-
- #pragma multi_compile_fwdadd
-
- #pragma vertex vert
- #pragma fragment frag
-
- #include "TaSTT_lighting.cginc"
- ENDCG
- }
- }
- //CustomEditor "TaSTTShaderGUI"
-}
-
diff --git a/Shaders/aa_sample_algorithm.py b/Shaders/aa_sample_algorithm.py deleted file mode 100644 index 779e159..0000000 --- a/Shaders/aa_sample_algorithm.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -# This is the algorithm that the anti-aliasing logic inside -# TaSTT_lighting_template.cginc uses. - -from math import fmod - -x = .5 -y = .1 -aa = 10 - -# This lets us handle values smaller than 1. We're creating an m*n rectangle -# and walking a path left-to-right, top-to-bottom through it. -x_cap = max(x, 1.0 / x) -y_cap = max(y, 1.0 / y) - -print(f"{x_cap} {y_cap}") - -def lerp(lo, hi, fract): - return lo + (hi - lo) * fract - -for i in range(0, aa): - # We want to subdivide an x*y area into `aa` evenly spaced pieces. - region = x_cap * y_cap - - stride = region / aa - - region_i = i * stride + stride/2 - region_x = region_i / y_cap - region_y = fmod(region_i, y_cap) - - print(f"{region_x} {region_y}") - - region_x = lerp(0, x, region_x / x_cap) - region_y = lerp(0, y, region_y / y_cap) - - print(f"{region_x} {region_y}") - - assert(region_x >= 0) - assert(region_x <= x) - assert(region_y >= 0) - assert(region_y <= y) - diff --git a/Shaders/eyes_data.cginc b/Shaders/eyes_data.cginc deleted file mode 100644 index 0ab3127..0000000 --- a/Shaders/eyes_data.cginc +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __EYES_DATA_INC__ -#define __EYES_DATA_INC__ - -struct appdata -{ - float4 position : POSITION; - float2 uv : TEXCOORD0; - float3 normal : NORMAL; -}; - -struct v2f -{ - float4 position : SV_POSITION; - float2 uv : TEXCOORD0; - float3 normal : TEXCOORD1; - float3 worldPos : TEXCOORD2; - - #if defined(VERTEXLIGHT_ON) - float3 vertexLightColor : TEXCOORD3; - #endif -}; - -#endif // __EYES_DATA_INC__ - diff --git a/Shaders/hg_sdf.cginc b/Shaders/hg_sdf.cginc deleted file mode 100644 index b1de0b0..0000000 --- a/Shaders/hg_sdf.cginc +++ /dev/null @@ -1,187 +0,0 @@ -#ifndef __HG_SDF__ -#define __HG_SDF__ - -#include "pema99.cginc" - -//////////////////////////////////////////////////////////////// -// -// HG_SDF -// -// GLSL LIBRARY FOR BUILDING SIGNED DISTANCE BOUNDS -// -// version 2021-07-28 -// -// Check https://mercury.sexy/hg_sdf for updates -// and usage examples. Send feedback to spheretracing@mercury.sexy. -// -// Brought to you by MERCURY https://mercury.sexy/ -// -// -// -// Released dual-licensed under -// Creative Commons Attribution-NonCommercial (CC BY-NC) -// or -// MIT License -// at your choice. -// -// SPDX-License-Identifier: MIT OR CC-BY-NC-4.0 -// -// ///// -// -// CC-BY-NC-4.0 -// https://creatifloatommons.org/licenses/by-nc/4.0/legalcode -// https://creatifloatommons.org/licenses/by-nc/4.0/ -// -// ///// -// -// MIT License -// -// Copyright (c) 2011-2021 Mercury Demogroup -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// ///// -// -//////////////////////////////////////////////////////////////// -// -// How to use this: -// -// 1. Build some system to #include glsl files in each other. -// Include this one at the very start. Or just paste everywhere. -// 2. Build a sphere tracer. See those papers: -// * "Sphere Tracing" https://link.springer.com/article/10.1007%2Fs003710050084 -// * "Enhanced Sphere Tracing" http://diglib.eg.org/handle/10.2312/stag.20141233.001-008 -// * "Improved Ray Casting of Procedural Distance Bounds" https://www.bibsonomy.org/bibtex/258e85442234c3ace18ba4d89de94e57d -// The Raymnarching Toolbox Thread on pouet can be helpful as well -// http://www.pouet.net/topic.php?which=7931&page=1 -// and contains links to many more resources. -// 3. Use the tools in this library to build your distance bound f(). -// 4. ??? -// 5. Win a compo. -// -// (6. Buy us a beer or a good vodka or something, if you like.) -// -//////////////////////////////////////////////////////////////// -// -// Table of Contents: -// -// * Helper functions and macros -// * Collection of some primitive objects -// * Domain Manipulation operators -// * Object combination operators -// -//////////////////////////////////////////////////////////////// -// -// Why use this? -// -// The point of this lib is that everything is structured according -// to patterns that we ended up using when building geometry. -// It makes it more easy to write code that is reusable and that somebody -// else can actually understand. Especially code on Shadertoy (which seems -// to be what everybody else is looking at for "inspiration") tends to be -// really ugly. So we were forced to do something about the situation and -// release this lib ;) -// -// Everything in here can probably be done in some better way. -// Please experiment. We'd love some feedback, especially if you -// use it in a scene production. -// -// The main patterns for building geometry this way are: -// * Stay Lipschitz continuous. That means: don't have any distance -// gradient larger than 1. Try to be as close to 1 as possible - -// Distances are euclidean distances, don't fudge around. -// Underestimating distances will happen. That's why calling -// it a "distance bound" is more correct. Don't ever multiply -// distances by some value to "fix" a Lipschitz continuity -// violation. The invariant is: each fSomething() function returns -// a correct distance bound. -// * Use very few primitives and combine them as building blocks -// using combine opertors that preserve the invariant. -// * Multiply objects by repeating the domain (space). -// If you are using a loop inside your distance function, you are -// probably doing it wrong (or you are building boring fractals). -// * At right-angle intersections between objects, build a new local -// coordinate system from the two distances to combine them in -// interesting ways. -// * As usual, there are always times when it is best to not follow -// specific patterns. -// -//////////////////////////////////////////////////////////////// -// -// FAQ -// -// Q: Why is there no sphere tracing code in this lib? -// A: Because our system is way too complex and always changing. -// This is the constant part. Also we'd like everyone to -// explore for themselves. -// -// Q: This does not work when I paste it into Shadertoy!!!! -// A: Yes. It is GLSL, not GLSL ES. We like real OpenGL -// because it has way more features and is more likely -// to work compared to browser-based WebGL. We recommend -// you consider using OpenGL for your productions. Most -// of this can be ported easily though. -// -// Q: How do I material? -// A: We recommend something like this: -// Write a material ID, the distance and the local coordinate -// p into some global variables whenever an object's distance is -// smaller than the stored distance. Then, at the end, evaluate -// the material to get color, roughness, etc., and do the shading. -// -// Q: I found an error. Or I made some function that would fit in -// in this lib. Or I have some suggestion. -// A: Awesome! Drop us a mail at spheretracing@mercury.sexy. -// -// Q: Why is this not on github? -// A: Because we were too lazy. If we get bugged about it enough, -// we'll do it. -// -// Q: Your license sucks for me. -// A: Oh. What should we change it to? -// -// Q: I have trouble understanding what is going on with my distances. -// A: Some visualization of the distance field helps. Try drawing a -// plane that you can sweep through your scene with some color -// representation of the distance field at each point and/or iso -// lines at regular intervals. Visualizing the length of the -// gradient (or better: how much it deviates from being equal to 1) -// is immensely helpful for understanding which parts of the -// distance field are broken. -// -//////////////////////////////////////////////////////////////// - -#define PI 3.14159265 - -// Repeat around the origin by a fixed angle. -// For easier use, num of repetitions is use to specify the angle. -float pModPolar(inout float2 p, float repetitions) { - float angle = 2*PI/repetitions; - float a = atan2(p.y, p.x) + angle/2.; - float r = length(p); - float c = floor(a/angle); - a = glsl_mod(a,angle) - angle/2.; - p = float2(cos(a), sin(a))*r; - // For an odd number of repetitions, fix cell index of the cell in -x direction - // (cell index would be e.g. -5 and 5 in the two halves of the cell): - if (abs(c) >= (repetitions/2)) c = abs(c); - return c; -} - -#endif // __HG_SDF__ diff --git a/Shaders/iq_sdf.cginc b/Shaders/iq_sdf.cginc deleted file mode 100644 index 7951261..0000000 --- a/Shaders/iq_sdf.cginc +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef __IQ_SDF_INC__ -#define __IQ_SDF_INC__ - -#include "pema99.cginc" - -// The MIT License -// Copyright © 2020 Inigo Quilez -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -float distance_from_octahedron(in float3 p) -{ - float s = 1.0; - float3 pp = abs(p); - float m = pp.x+pp.y+pp.z-s; - float3 q; - if( 3.0*pp.x < m ) q = pp.xyz; - else if( 3.0*pp.y < m ) q = pp.yzx; - else if( 3.0*pp.z < m ) q = pp.zxy; - else return m*0.57735027; - - float k = clamp(0.5*(q.z-q.y+s),0.0,s); - return length(float3(q.x,q.y-s+k,q.z-k)); -} - -float distance_from_sphere(float3 p) -{ - return length(p); -} - -float distance_from_sphere(float3 p, float3 c, float r) -{ - return length(p - c) - r; -} - -float distance_from_cut_sphere( in float3 p, in float r, in float h ) -{ - float w = sqrt(r*r-h*h); // constant for a given shape - - float2 q = float2( length(p.xz), p.y ); - - float s = max( (h-r)*q.x*q.x+w*w*(h+r-2.0*q.y), h*q.x-w*q.y ); - - return (s<0.0) ? length(q)-r : - (q.x<w) ? h - q.y : - length(q-float2(w,h)); -} - -float distance_from_cut_hollow_sphere( float3 p, float r, float h, float t ) -{ - float2 q = float2( length(p.xz), p.y ); - - float w = sqrt(r*r-h*h); - - return ((h*q.x<w*q.y) ? length(q-float2(w,h)) : - abs(length(q)-r) ) - t; -} - -float distance_from_box(float3 p, float3 b) -{ - float3 q = abs(p) - b; - return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0); -} - -float distance_from_box_frame(float3 p, float3 b, float e) -{ - p = abs(p)-b; - float3 q = abs(p+e)-e; - - return min(min( - length(max(float3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0), - length(max(float3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)), - length(max(float3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0)); -} - -float distance_from_pyramid(float3 p, float h, bool invert) -{ - float m2 = h*h + 0.25; - - // symmetry - p.xz = abs(p.xz); // do p=abs(p) instead for double pyramid - p.xz = (p.z>p.x) ? p.zx : p.xz; - p.xz -= 0.5; - - // project into face plane (2D) - float3 q = float3( p.z, h*p.y-0.5*p.x, h*p.x+0.5*p.y); - - float s = max(-q.x,0.0); - float t = clamp( (q.y-0.5*q.x)/(m2+0.25), 0.0, 1.0 ); - - float a = m2*(q.x+s)*(q.x+s) + q.y*q.y; - float b = m2*(q.x+0.5*t)*(q.x+0.5*t) + (q.y-m2*t)*(q.y-m2*t); - - float d2 = max(-q.y,q.x*m2+q.y*0.5) < 0.0 ? 0.0 : min(a,b); - - // recover 3D and scale, and add sign - return sqrt( (d2+q.z*q.z)/m2 ) * sign(max(q.z,-p.y));; -} - -float distance_from_plane(float3 p, float3 n, float h) -{ - // n must be normalized - return dot(p,n) + h; -} - -float distance_from_torus( float3 p, float2 t ) -{ - float2 q = float2(length(p.xz)-t.x,p.y); - return length(q)-t.y; -} - -float distance_from_capped_torus( float3 p, float2 sc, float ra, float rb) -{ - p.x = abs(p.x); - float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy); - return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb; -} - -float3 op_rep(in float3 p, in float3 c) -{ - return glsl_mod(p+0.5*c,c)-0.5*c; -} - -float smoothstep_cubic(float x) -{ - return x * x * (3.0 - 2.0 * x); -} - -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/math.cginc b/Shaders/math.cginc deleted file mode 100644 index 061d4c0..0000000 --- a/Shaders/math.cginc +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __MATH_INC -#define __MATH_INC - -#include "pema99.cginc" - -#define PI 3.14159265 - -// Differentiable approximation of the standard `max` function. -float dmax(float a, float b, float k) -{ - return log2(exp2(k * a) + exp2(k * b)) / k; -} - -// Differentiable approximation of the standard `min` function. -float dmin(float a, float b, float k) -{ - return -1.0 * dmax(-1.0 * a, -1.0 * b, k); -} - -// Generate a random number on [0, 1]. -float rand2(float3 p) -{ - return glsl_mod(sin(dot(p, float2(561.0, 885.0))) * 776.2, 1.0); -} - -// Generate a random number on [0, 1]. -float rand3(float3 p) -{ - return glsl_mod(sin(dot(p, float3(897.0, 367.0, 197.0))) * 1073.6, 1.0); -} - -// 3 dimensional value noise. `p` is assumed to be a point inside a unit cube. -// Theory: https://en.wikipedia.org/wiki/Value_noise -float vnoise3d(float3 p) -{ - float3 pu = floor(p); - float3 pv = glsl_mod(p, 1.0); - - // Assign random numbers to the corner of a cube. - float n000 = rand3(pu + float3(0,0,0)); - float n001 = rand3(pu + float3(0,0,1)); - float n010 = rand3(pu + float3(0,1,0)); - float n011 = rand3(pu + float3(0,1,1)); - float n100 = rand3(pu + float3(1,0,0)); - float n101 = rand3(pu + float3(1,0,1)); - float n110 = rand3(pu + float3(1,1,0)); - float n111 = rand3(pu + float3(1,1,1)); - - float n00 = lerp(n000, n001, pv.z); - float n01 = lerp(n010, n011, pv.z); - float n10 = lerp(n100, n101, pv.z); - float n11 = lerp(n110, n111, pv.z); - - float n0 = lerp(n00, n01, pv.y); - float n1 = lerp(n10, n11, pv.y); - - float n = lerp(n0, n1, pv.x); - - return n; -} - -float fbm(float3 p, const int n_octaves, float w) -{ - float g = exp2(-w); - float a = 1.0; - float p_scale = 1.0; - - float res = 0.0; - for (int i = 0; i < n_octaves; i++) { - res += a * vnoise3d(p * p_scale); - - p_scale /= w; - a *= g; - } - - // On average, vnoise3d returns 0.5. - // Sum of any geometric series is, for growth parameter r and constant a, - // a / (1 - r). - // We want to map onto [0, 1], so divide by this expected sum. - // Use a = 1, to account for the worst-case possibility that every call to - // vnoise3d() returns 1. - res /= (1 / (1 - g)); - - return res; -} - -#endif // __MATH_INC - diff --git a/Shaders/pbr.cginc b/Shaders/pbr.cginc deleted file mode 100644 index 9b46f8e..0000000 --- a/Shaders/pbr.cginc +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef __PBR_INC__ -#define __PBR_INC__ - -#include "AutoLight.cginc" -#include "eyes_data.cginc" -#include "UnityPBSLighting.cginc" - -static float BG_Effect_Bias = 0.0; -static float BG_Effect_Weight = 1.0; - -UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { - UnityIndirect indirect; - indirect.diffuse = 0; - indirect.specular = 0; - - #if defined(VERTEXLIGHT_ON) - indirect.diffuse = i.vertexLightColor; - #endif - - #if defined(FORWARD_BASE_PASS) - indirect.diffuse += max(0, ShadeSH9(float4(i.normal, 1))); - float3 reflect_dir = reflect(-view_dir, i.normal); - // There's a nonlinear relationship between mipmap level and roughness. - float roughness = 1 - smoothness; - roughness *= 1.7 - .7 * roughness; - float3 env_sample; - env_sample = UNITY_SAMPLE_TEXCUBE_LOD( - unity_SpecCube0, - reflect_dir, - roughness * UNITY_SPECCUBE_LOD_STEPS); - indirect.specular = env_sample; - #endif - - return indirect; -} - -UnityLight GetLight(v2f i) -{ - UNITY_LIGHT_ATTENUATION(attenuation, 0, i.worldPos); - float3 light_color = _LightColor0.rgb * attenuation; - - UnityLight light; - light.color = light_color; - #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) - light.dir = normalize(_WorldSpaceLightPos0.xyz - i.worldPos); - #else - light.dir = _WorldSpaceLightPos0.xyz; - #endif - light.ndotl = DotClamped(i.normal, light.dir); - - return light; -} - -void initNormal(inout v2f i) -{ - i.normal = normalize(i.normal); -} - -float4 light(inout v2f i, - float4 albedo, - float metallic, - float smoothness) -{ - initNormal(i); - - float3 specular_tint; - float one_minus_reflectivity; - albedo.rgb = DiffuseAndSpecularFromMetallic( - albedo, metallic, specular_tint, one_minus_reflectivity); - - float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); - float3 pbr = UNITY_BRDF_PBS(albedo, - specular_tint, - one_minus_reflectivity, - smoothness, - i.normal, - view_dir, - GetLight(i), - GetIndirect(i, view_dir, smoothness)).rgb; - - return float4(saturate(pbr), albedo.a); -} - -float getWorldSpaceDepth(in float3 world_pos) -{ - float4 clip_pos = mul(UNITY_MATRIX_VP, float4(world_pos, 1.0)); - return clip_pos.z / clip_pos.w; -} - -#endif // __PBR_INC__ - diff --git a/Shaders/pema99.cginc b/Shaders/pema99.cginc deleted file mode 100644 index c895a48..0000000 --- a/Shaders/pema99.cginc +++ /dev/null @@ -1,31 +0,0 @@ -/* -MIT License - -Copyright (c) 2022 Pema Malling - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef __PEMA99_INC__ -#define __PEMA99_INC__ - -#define glsl_mod(x,y) (((x)-(y)*floor((x)/(y)))) - -#endif // __PEMA99_INC__ - diff --git a/Shaders/poi.cginc b/Shaders/poi.cginc deleted file mode 100644 index 87382bb..0000000 --- a/Shaders/poi.cginc +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __POI_INC__ -#define __POI_INC__ - -/* -MIT License - -Copyright (c) 2018 King Arthur - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -static const float Epsilon = 1e-10; -float3 RGBtoHCV(in float3 RGB) -{ - // Based on work by Sam Hocevar and Emil Persson - float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0 / 3.0) : float4(RGB.gb, 0.0, -1.0 / 3.0); - float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx); - float C = Q.x - min(Q.w, Q.y); - float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z); - return float3(H, C, Q.x); -} - -float3 RGBtoHSV(in float3 RGB) -{ - float3 HCV = RGBtoHCV(RGB); - float S = HCV.y / (HCV.z + Epsilon); - return float3(HCV.x, S, HCV.z); -} - -float3 HUEtoRGB(in float H) -{ - float R = abs(H * 6 - 3) - 1; - float G = 2 - abs(H * 6 - 2); - float B = 2 - abs(H * 6 - 4); - return saturate(float3(R, G, B)); -} - -float3 HSVtoRGB(in float3 HSV) -{ - float3 RGB = HUEtoRGB(HSV.x); - return ((RGB - 1) * HSV.y + 1) * HSV.z; -} - -#endif // __POI_INC__ diff --git a/Shaders/ray_march.cginc b/Shaders/ray_march.cginc deleted file mode 100644 index bdedc8b..0000000 --- a/Shaders/ray_march.cginc +++ /dev/null @@ -1,361 +0,0 @@ -#ifndef __RAY_MARCH_INC__ -#define __RAY_MARCH_INC__ - -#include "eyes_data.cginc" -#include "iq_sdf.cginc" -#include "math.cginc" -#include "Motion.cginc" -#include "pbr.cginc" -#include "pema99.cginc" -#include "poi.cginc" -#include "stt_text.cginc" - -float _Emerge; -float _Ellipsis; - -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; - -#define MY_COORD_SCALE 100 -#define MY_COORD_SCALE_INV 1.0 / MY_COORD_SCALE -#define OBJ_SPACE_TO_MINE \ - float4x4( \ - MY_COORD_SCALE, 0, 0, 0, \ - 0, MY_COORD_SCALE, 0, 0, \ - 0, 0, MY_COORD_SCALE, 0, \ - 0, 0, 0, MY_COORD_SCALE \ - ) -#define WORLD_SPACE_TO_MINE \ - mul(unity_WorldToObject, OBJ_SPACE_TO_MINE) -#define MY_SPACE_TO_OBJ \ - float4x4( \ - MY_COORD_SCALE_INV, 0, 0, 0, \ - 0, MY_COORD_SCALE_INV, 0, 0, \ - 0, 0, MY_COORD_SCALE_INV, 0, \ - 0, 0, 0, MY_COORD_SCALE_INV \ - ) -#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`. -// -// A few examples: -// get_phase_fraction(0.9, 0, 2) = 1.0 -// get_phase_fraction(0.9, 1, 2) = 0.8 -// get_phase_fraction(0.5, 0, 3) = 1.0 -// get_phase_fraction(0.5, 1, 3) = 0.5 -// get_phase_fraction(0.5, 2, 3) = 0.0 -// -// So if `r` is past the slice we're looking at, it returns 1; if it's before -// the slice we're looking at, it returns 0; if it's on the slice we're looking -// at, it gets remapped onto [0,1]. -float get_phase_fraction(float r, float nth_phase, float n_phases) { - float stride = 1.0 / n_phases; - - // Prevent boundary condition where saturated values get set to 0 by the - // glsl_mod below. - r = min(.9999 * (nth_phase + 1) * stride, r); - - float r0 = clamp(r, nth_phase * stride, (nth_phase + 1) * stride); - r0 = glsl_mod(r0, stride); - - return r0 / stride; -} - -// d = base edge length -// h = height -// e = frame thickness -// Pyramid base is on xy plane. -float distance_from_rect_pyramid_frame(float3 p, float dx, float dy, float h, float e, float skew) -{ - float3 p0 = float3(dx/2, dy/2, 0); - float3 p1 = float3(dx/2, -dy/2, 0); - float3 p3 = float3(-dx/2, dy/2, 0); - float3 p4 = float3(skew, 0, h); - - float3 pp = p; - // Symmetry - pp.x = abs(pp.x); - float d01 = distance_from_line_segment(pp, p0, p1, e); - - pp = p; - pp.y = abs(pp.y); - float d03 = distance_from_line_segment(pp, p0, p3, e); - float d04 = distance_from_line_segment(pp, p0, p4, e); - float d14 = distance_from_line_segment(pp, p3, p4, e); - - float dist = 1000; - dist = min(dist, d01); - dist = min(dist, d04); - dist = min(dist, d03); - dist = min(dist, d14); - - return dist; -} - -#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) -{ - obj_id = OBJ_ID_NONE; - - 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) * MY_COORD_SCALE; - float3 box_center_g = float3(.020, 0, .0122) * MY_COORD_SCALE; - { - float3 pp = p; - pp -= box_center_g; - - float box_thck = .0002 * MY_COORD_SCALE; - - float3 box_sz = float3(6, .5, 3) * .003 * box_scale_g; - - // Use this to make the box grow out of the bottom left corner instead of the - // middle. - float3 emerge_offset = 0; - emerge_offset.x = lerp(box_sz.x, box_thck, p1r); - emerge_offset.z = lerp(box_sz.z, box_thck, p2r); - pp += emerge_offset; - - box_sz.y = lerp(box_thck, box_sz.y, p0r) * p0r; - box_sz.x = lerp(box_thck, box_sz.x, p1r) * p0r; - box_sz.z = lerp(box_thck, box_sz.z, p2r) * p0r; - - float d = distance_from_box_frame(pp, box_sz, box_thck); - - obj_id = lerp(obj_id, OBJ_ID_FRAME, d < dist); - dist = min(dist, d); - } - { - float3 pp = p; - pp -= box_center_g; - //pp -= float3(-0.00018, .0013, -.0002) * MY_COORD_SCALE; - pp -= float3(-0.00018, 0, -.0002) * MY_COORD_SCALE; - - float3 box_scale = float3(10, 0.1, 4.9) * .00175 * box_scale_g; - float3 box_pad = float3(.001, 0, .001) * MY_COORD_SCALE; - box_scale -= box_pad; - - // Use this to make the board grow out of the left edge instead of from the - // center. - float3 emerge_offset = 0; - emerge_offset.x = lerp(box_scale.x, 0, p3r); - pp += emerge_offset; - - box_scale.x = lerp(0, box_scale.x, p3r); - box_scale.y *= ceil(p3r); - box_scale.z *= ceil(p3r); - - // Only use calculation when in phase 3. - float d = lerp(1000, distance_from_box(pp, box_scale), ceil(p3r)); - - text_uv = (clamp(pp.xz, -1 * box_scale.xz, box_scale.xz) / box_scale.xz); - text_uv = (text_uv + 1) / 2; - - 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); - - obj_id = lerp(obj_id, OBJ_ID_BG, d < dist); - dist = min(dist, d); - } - { - float3 pp = p; - - pp -= box_center_g - float3(6, 0, 3) * .003 * box_scale_g; - - float scale = .0025 + .0002; - scale *= MY_COORD_SCALE; - pp.x -= scale/2; - - float edgex = 1 * scale; - float edgey = 1 * scale; - float height = -1.3 * scale; - float r = .06 * scale; - float skew = -.75 * scale; - - pp.z += lerp(0, .0008 * MY_COORD_SCALE, p0r) * p0r; - r = lerp(0, r, p0r) * p0r; - edgey = lerp(0, edgey, p0r) * p0r; - - pp.x += lerp(edgex/2, 0, p1r); - edgex = lerp(0, edgex, p1r); - - height = lerp(0, height, p2r); - 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); - } - if (_Ellipsis > 0.1 && _Emerge > .99) { - float3 pp = p; - - float3 xoff = float3(.003, 0, 0) * MY_COORD_SCALE; - - float r_small = .0005 * MY_COORD_SCALE; - float r_big = .001 * MY_COORD_SCALE; - float r_phase = glsl_mod(_Time[1], 1.0); - - float r0_p0r = get_phase_fraction(r_phase, 0, 8); - float r0_p2r = get_phase_fraction(r_phase, 3, 8); - float r1_p0r = get_phase_fraction(glsl_mod(r_phase + .25, 1.0), 0, 8); - float r1_p2r = get_phase_fraction(glsl_mod(r_phase + .25, 1.0), 3, 8); - float r2_p0r = get_phase_fraction(glsl_mod(r_phase + .50, 1.0), 0, 8); - float r2_p2r = get_phase_fraction(glsl_mod(r_phase + .50, 1.0), 3, 8); - - float r0 = lerp(r_small, r_big, r0_p0r * (1 - r0_p2r)); - float r1 = lerp(r_small, r_big, r1_p0r * (1 - r1_p2r)); - float r2 = lerp(r_small, r_big, r2_p0r * (1 - r2_p2r)); - - pp -= box_center_g; - - float d = distance_from_sphere(pp - xoff, 0, r0); - d = min(d, distance_from_sphere(pp, 0, r1)); - d = min(d, distance_from_sphere(pp + xoff, 0, r2)); - - obj_id = lerp(obj_id, OBJ_ID_FRAME, d < dist); - dist = min(dist, d); - } - - return dist; -} - -// Calculate normals for ray-marched STT structure. -float3 stt_calculate_normal(in float3 p) -{ - 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. - 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); - 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); - - return normalize(normal); -} - -float get_letter_mask(float2 text_uv, bool mirror) -{ - float epsilon = .005; - 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, mirror); - text_uv = AddMarginToUV(1.0 - text_uv, .01); - return GetLetter(text_uv); - } - return 0; -} - -float3 stt_march(float3 ro, float3 rd, out int obj_id, out float2 text_uv, int steps) -{ - float total_distance_traveled = 0.0; - float3 current_position = 0; - float distance_to_closest = 1; - - #define STT_RAY_MARCH_STEPS 48 - for (int i = 0; (i < steps) * - (distance_to_closest > MINIMUM_HIT_DISTANCE/4) * - (total_distance_traveled < MAXIMUM_TRACE_DISTANCE); i++) - { - current_position = ro + total_distance_traveled * rd; - distance_to_closest = stt_map(current_position, obj_id, text_uv); - total_distance_traveled += distance_to_closest; - } - 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; - - float letter_mask = get_letter_mask(text_uv, ((normal.y + 1) / 2) > .01); - - 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); - - frame += _Frame_Color * _Frame_Emissive; - frame = clamp(frame, 0, 1); - - // TODO(yum) restore - //depth = getWorldSpaceDepth(v2f_i.worldPos); - - [forcecase] - switch (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) -{ - float4 ray_march_color; - { - float3 camera_position = mul(WORLD_SPACE_TO_MINE, float4(_WorldSpaceCameraPos, 1.0)).xyz; - float3 ro = camera_position; - float3 rd = normalize(mul(WORLD_SPACE_TO_MINE, float4(v2f_i.worldPos, 1.0)).xyz - ro); - float3 old_normal = v2f_i.normal; - ray_march_color = stt_ray_march(ro, rd, v2f_i, depth); - //v2f_i.normal = old_normal; - } - - return ray_march_color; -} - -#endif // __RAY_MARCH_INC__ - |
