From b753776c288668ddfa7cd38b108752be30fb1d9b Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Sat, 25 Jan 2025 10:26:17 +0000 Subject: [PATCH] Copy dissolve/completion control across from plugin scripting branch --- .../Brushes/Basic/Bubbles/Bubbles.shader | 300 ++-- .../Brushes/Basic/CelVinyl/CelVinyl.shader | 212 +-- .../Basic/ChromaticWave/ChromaticWave.shader | 250 ++-- .../Brushes/Basic/Comet/Comet.shader | 283 ++-- .../Basic/DanceFloor/DanceFloor.shader | 260 ++-- .../Basic/DiamondHull/DiamondHull.shader | 387 ++--- .../Brushes/Basic/Disco/Disco.shader | 226 +-- .../Resources/Brushes/Basic/Dots/Dots.shader | 274 ++-- .../DiffuseNoTextureDoubleSided.shader | 176 +-- .../DoubleTaperedMarker.shader | 209 +-- .../Basic/Electricity/Electricity.shader | 472 +++--- .../Brushes/Basic/Embers/Embers.shader | 381 ++--- .../Brushes/Basic/FacetedTube/FacetedTube.mat | 13 +- .../Resources/Brushes/Basic/Fire/Fire.shader | 310 ++-- .../Basic/Highlighter/AdditiveCutout.shader | 203 +-- .../Brushes/Basic/HyperGrid/HyperGrid.shader | 264 ++-- .../Hypercolor/HypercolorDoubleSided.mat | 14 +- .../Hypercolor/HypercolorDoubleSided.shader | 280 ++-- .../Hypercolor/HypercolorSingleSided.shader | 216 +-- .../Brushes/Basic/LightWire/LightWire.shader | 259 ++-- .../Brushes/Basic/Petal/Petal.shader | 159 ++- .../Brushes/Basic/Plasma/Plasma.shader | 344 ++--- .../Brushes/Basic/Rainbow/Rainbow.shader | 459 +++--- .../Brushes/Basic/Smoke/Smoke.shader | 295 ++-- .../Resources/Brushes/Basic/Snow/Snow.shader | 271 ++-- .../SoftHighlighter/SoftHighlighter.shader | 213 +-- .../Brushes/Basic/Stars/Stars.shader | 251 ++-- .../Brushes/Basic/Streamers/Streamers.shader | 318 +++-- .../Resources/Brushes/Basic/Toon/Toon.shader | 345 ++--- .../TubeToonInverted/TubeToonInverted.shader | 243 ++-- .../Brushes/Basic/VelvetInk/VelvetInk.shader | 210 +-- .../Brushes/Basic/Waveform/Waveform.shader | 250 ++-- .../Basic/WaveformFFT/WaveformFFT.shader | 238 ++-- .../WaveformParticles.shader | 266 ++-- .../Basic/WaveformPulse/NeonPulse.shader | 206 +-- .../Basic/WaveformTube/WaveformTube.shader | 207 +-- .../WigglyGraphiteDoubleSided.shader | 208 +-- .../WigglyGraphiteSingleSided.shader | 154 +- .../Brushes/Basic/Wireframe/Wireframe.shader | 201 +-- .../Brushes/Shared/Shaders/Additive.shader | 211 +-- .../Brushes/Shared/Shaders/Bloom.shader | 258 ++-- .../Shared/Shaders/DiffuseDoubleSided.shader | 293 ++-- .../Shaders/DiffuseOpaqueDoubleSided.shader | 163 ++- .../Shaders/DiffuseOpaqueSingleSided.shader | 140 +- .../Shared/Shaders/DiffuseSingleSided.shader | 243 ++-- .../Shared/Shaders/Multiplicative.shader | 191 +-- .../Shaders/Special/AdditiveScrolling.shader | 209 +-- .../Shared/Shaders/Special/Faceted.shader | 186 +-- .../Shared/Shaders/StandardDoubleSided.shader | 1261 +++++++++-------- .../Shared/Shaders/StandardSingleSided.shader | 837 ++++++----- .../Brushes/Shared/Shaders/Unlit.shader | 206 +-- .../X/Brushes/BubbleWand/BubbleWand.shader | 256 ++-- .../X/Brushes/Digital/Digital.shader | 385 ++--- .../X/Brushes/Drafting/Drafting.shader | 188 +-- Assets/Resources/X/Brushes/Fairy/Fairy.shader | 342 ++--- .../Resources/X/Brushes/Fire 2/Fire2.shader | 324 +++-- .../X/Brushes/KeijiroTube/KeijiroTube.shader | 167 ++- .../X/Brushes/Lacewing/Lacewing.shader | 253 ++-- .../X/Brushes/LeakyPen/LeakyPen.shader | 167 ++- .../LoftedHueShift/LoftedHueShift.shader | 165 ++- .../MarbledRainbow/MarbledRainbow.shader | 209 +-- .../X/Brushes/MylarTube/MylarTube.mat | 14 +- .../X/Brushes/MylarTube/MylarTube.shader | 209 +-- Assets/Resources/X/Brushes/Race/Race.shader | 385 ++--- Assets/Resources/X/Brushes/Rain/Rain.shader | 348 ++--- .../X/Brushes/RisingBubbles/RisingBubbles.mat | 15 +- .../RisingBubbles/RisingBubbles.shader | 333 +++-- Assets/Resources/X/Brushes/Slice/Slice.shader | 214 +-- Assets/Resources/X/Brushes/Space/Space.shader | 310 ++-- .../Resources/X/Brushes/Sparks/Sparks.shader | 366 ++--- .../TaperedHueShift/TaperedHueShift.shader | 223 +-- Assets/Resources/X/Brushes/Wind/Wind.shader | 213 +-- 72 files changed, 10461 insertions(+), 8650 deletions(-) diff --git a/Assets/Resources/Brushes/Basic/Bubbles/Bubbles.shader b/Assets/Resources/Brushes/Basic/Bubbles/Bubbles.shader index 424d6cd6a2..b5aa4080f9 100644 --- a/Assets/Resources/Brushes/Basic/Bubbles/Bubbles.shader +++ b/Assets/Resources/Brushes/Basic/Bubbles/Bubbles.shader @@ -1,138 +1,162 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/Bubbles" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 - _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend One One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma target 3.0 - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _ScrollRate; - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - float3 _WorldSpaceRootCameraPosition; - float _SpreadRate; - - float3 computeDisplacement(float3 seed, float timeOffset) { - float3 jitter; { - float t = _Time.y * _ScrollRate + timeOffset; - jitter.x = sin(t + _Time.y + seed.z * _ScrollJitterFrequency); - jitter.z = cos(t + _Time.y + seed.x * _ScrollJitterFrequency); - jitter.y = cos(t * 1.2 + _Time.y + seed.x * _ScrollJitterFrequency); - jitter *= _ScrollJitterIntensity; - } - - float3 curl; { - float3 v = (seed + jitter) * .1 + _Time.x * 5; - float d = 30; - curl = float3(curlX(v, d), curlY(v, d), curlZ(v, d)) * 10; - } - - return (jitter + curl) * kDecimetersToWorldUnits; - } - - v2f vert (ParticleVertexWithSpread_t v) { - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - v.color = TbVertToSrgb(v.color); - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float spreadProgress = SpreadProgress(birthTime, _SpreadRate); - float4 center = SpreadParticle(v, spreadProgress); - PrepForOds(center); - - float3 displacement_SS = spreadProgress * computeDisplacement(center, 1); - float3 displacement_WS = mul(xf_CS, float4(displacement_SS, 0)); - float3 displacement_OS = mul(unity_WorldToObject, float4(displacement_WS, 0)); - center.xyz += displacement_OS; - float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); - o.vertex = UnityObjectToClipPos(corner); - - // Brighten up the bubbles - o.color = v.color; - o.color.a = 1; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - - return o; - } - - fixed4 frag (v2f i) : SV_Target - { - float4 tex = tex2D(_MainTex, i.texcoord); - - // RGB Channels of the texture are affected by color - float3 basecolor = i.color * tex.rgb; - - // Alpha channel of the texture is not affected by color. It is the fake "highlight" bubble effect. - float3 highlightcolor = tex.a; - - float4 color = float4(basecolor + highlightcolor, 1); - color = SrgbToNative(color); - -#if SELECTION_ON - color.rgb = GetSelectionColor() * tex.r; - color.a = tex.a; -#endif - - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/Bubbles" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend One One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma target 3.0 + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _ScrollRate; + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + float3 _WorldSpaceRootCameraPosition; + float _SpreadRate; + + float3 computeDisplacement(float3 seed, float timeOffset) { + float3 jitter; { + float t = GetTime().y * _ScrollRate + timeOffset; + jitter.x = sin(t + GetTime().y + seed.z * _ScrollJitterFrequency); + jitter.z = cos(t + GetTime().y + seed.x * _ScrollJitterFrequency); + jitter.y = cos(t * 1.2 + GetTime().y + seed.x * _ScrollJitterFrequency); + jitter *= _ScrollJitterIntensity; + } + + float3 curl; { + float3 v = (seed + jitter) * .1 + GetTime().x * 5; + float d = 30; + curl = float3(curlX(v, d), curlY(v, d), curlZ(v, d)) * 10; + } + + return (jitter + curl) * kDecimetersToWorldUnits; + } + + v2f vert (ParticleVertexWithSpread_t v) { + + + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + v.color = TbVertToSrgb(v.color); + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float spreadProgress = SpreadProgress(birthTime, _SpreadRate); + float4 center = SpreadParticle(v, spreadProgress); + PrepForOds(center); + + float3 displacement_SS = spreadProgress * computeDisplacement(center, 1); + float3 displacement_WS = mul(xf_CS, float4(displacement_SS, 0)); + float3 displacement_OS = mul(unity_WorldToObject, float4(displacement_WS, 0)); + center.xyz += displacement_OS; + float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); + o.vertex = UnityObjectToClipPos(corner); + + // Brighten up the bubbles + o.color = v.color; + o.color.a = 1; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + o.id = v.id; + + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 tex = tex2D(_MainTex, i.texcoord); + + // RGB Channels of the texture are affected by color + float3 basecolor = i.color * tex.rgb; + + // Alpha channel of the texture is not affected by color. It is the fake "highlight" bubble effect. + float3 highlightcolor = tex.a; + + float4 color = float4(basecolor + highlightcolor, 1); + color = SrgbToNative(color); + +#if SELECTION_ON + color.rgb = GetSelectionColor() * tex.r; + color.a = tex.a; +#endif + + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/CelVinyl/CelVinyl.shader b/Assets/Resources/Brushes/Basic/CelVinyl/CelVinyl.shader index c5420d8b58..3e930a69a7 100644 --- a/Assets/Resources/Brushes/Basic/CelVinyl/CelVinyl.shader +++ b/Assets/Resources/Brushes/Basic/CelVinyl/CelVinyl.shader @@ -1,98 +1,114 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/CelVinyl" { - Properties{ - _MainTex("MainTex", 2D) = "white" {} - _Color("Color", Color) = (1,1,1,1) - _Cutoff ("Alpha Cutoff", Range (0,1)) = 0.5 - } - - SubShader{ - Pass { - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout"} - - Lighting Off - Cull Off - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile_fog - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - #pragma target 3.0 - - sampler2D _MainTex; - float4 _MainTex_ST; - fixed4 _Color; - float _Cutoff; - - struct appdata_t { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - UNITY_FOG_COORDS(1) - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = v.texcoord; - o.color = TbVertToNative(v.color); - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - fixed4 tex = tex2D(_MainTex, i.texcoord) * i.color; - UNITY_APPLY_FOG(i.fogCoord, tex); - - // Discard transparent pixels. - if (tex.a < _Cutoff) { - discard; - } - tex.a = 1; - FRAG_MOBILESELECT(tex) - return tex; - } - - ENDCG - } - } - - Fallback "Unlit/Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/CelVinyl" { + Properties{ + _MainTex("MainTex", 2D) = "white" {} + _Color("Color", Color) = (1,1,1,1) + _Cutoff ("Alpha Cutoff", Range (0,1)) = 0.5 + + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader{ + Pass { + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout"} + + Lighting Off + Cull Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile_fog + #pragma multi_compile __ SELECTION_ON + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + #pragma target 3.0 + + sampler2D _MainTex; + float4 _MainTex_ST; + fixed4 _Color; + float _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + uint id : TEXCOORD2; + UNITY_FOG_COORDS(1) + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = v.texcoord; + o.color = TbVertToNative(v.color); + o.id = (float2)v.id; + UNITY_TRANSFER_FOG(o, o.pos); + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, i.texcoord) * i.color; + UNITY_APPLY_FOG(i.fogCoord, tex); + + // Discard transparent pixels. + if (tex.a < _Cutoff) { + discard; + } + tex.a = 1; + FRAG_MOBILESELECT(tex) + return tex; + } + + ENDCG + } + } + + Fallback "Unlit/Diffuse" +} diff --git a/Assets/Resources/Brushes/Basic/ChromaticWave/ChromaticWave.shader b/Assets/Resources/Brushes/Basic/ChromaticWave/ChromaticWave.shader index d83130bd96..ea67c29abf 100644 --- a/Assets/Resources/Brushes/Basic/ChromaticWave/ChromaticWave.shader +++ b/Assets/Resources/Brushes/Basic/ChromaticWave/ChromaticWave.shader @@ -1,115 +1,135 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/RainbowTube" { -Properties { - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One //SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - float _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 unbloomedColor : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = v.texcoord; - o.color = bloomColor(v.color, _EmissionGain); - o.unbloomedColor = v.color; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - // Envelope - float envelope = sin(i.texcoord.x * 3.14159); - i.texcoord.y += i.texcoord.x * 3 + _BeatOutputAccum.b*3; -#ifdef AUDIO_REACTIVE - float waveform_r = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r - .5f); - float waveform_g = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x*1.8,0)).r - .5f); - float waveform_b = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x*2.4,0)).r - .5f); -#else - float waveform_r = .15 * sin( -20 * i.unbloomedColor.r * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.r); - float waveform_g = .15 * sin( -30 * i.unbloomedColor.g * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.g); - float waveform_b = .15 * sin( -40 * i.unbloomedColor.b * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.b); -#endif - i.texcoord.y = fmod(i.texcoord.y + i.texcoord.x, 1); - float procedural_line_r = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_r)); - float procedural_line_g = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_g)); - float procedural_line_b = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_b)); - float4 color = procedural_line_r * float4(1,0,0,0) + procedural_line_g * float4(0,1,0,0) + procedural_line_b * float4(0,0,1,0); - color.w = 1; - color = i.color * color; - - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - FRAG_MOBILESELECT(color) - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/RainbowTube" { +Properties { + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One //SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 unbloomedColor : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = v.texcoord; + o.color = bloomColor(v.color, _EmissionGain); + o.unbloomedColor = v.color; + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + // Envelope + float envelope = sin(i.texcoord.x * 3.14159); + i.texcoord.y += i.texcoord.x * 3 + _BeatOutputAccum.b*3; +#ifdef AUDIO_REACTIVE + float waveform_r = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r - .5f); + float waveform_g = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x*1.8,0)).r - .5f); + float waveform_b = .5*(tex2D(_WaveFormTex, float2(i.texcoord.x*2.4,0)).r - .5f); +#else + float waveform_r = .15 * sin( -20 * i.unbloomedColor.r * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.r); + float waveform_g = .15 * sin( -30 * i.unbloomedColor.g * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.g); + float waveform_b = .15 * sin( -40 * i.unbloomedColor.b * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.b); +#endif + i.texcoord.y = fmod(i.texcoord.y + i.texcoord.x, 1); + float procedural_line_r = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_r)); + float procedural_line_g = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_g)); + float procedural_line_b = saturate(1 - 40*abs(i.texcoord.y - .5 + waveform_b)); + float4 color = procedural_line_r * float4(1,0,0,0) + procedural_line_g * float4(0,1,0,0) + procedural_line_b * float4(0,0,1,0); + color.w = 1; + color = i.color * color; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Comet/Comet.shader b/Assets/Resources/Brushes/Basic/Comet/Comet.shader index 0347d2d8ec..3d6239657d 100644 --- a/Assets/Resources/Brushes/Basic/Comet/Comet.shader +++ b/Assets/Resources/Brushes/Basic/Comet/Comet.shader @@ -1,130 +1,153 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Comet" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _AlphaMask("Alpha Mask", 2D) = "white" {} - _Speed ("Animation Speed", Range (0,1)) = 1 - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - sampler2D _AlphaMask; - float4 _MainTex_ST; - float4 _AlphaMask_ST; - float _Speed; - half _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float3 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = TbVertToNative(v.color); - -#ifdef AUDIO_REACTIVE - float3 displacement = _BeatOutput.y * v.normal * - saturate((1.0 - smoothstep(0, .3, v.texcoord.x)) * v.texcoord.z); - v.vertex.xyz += displacement; -#endif - o.pos = UnityObjectToClipPos(v.vertex); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - // Set up some staggered scrolling for "fire" effect -#ifdef AUDIO_REACTIVE - float time = (_Time.x * 2 + _BeatOutputAccum.w) * -_Speed; -#else - float time = _Time.y * -_Speed; -#endif - fixed2 scrollUV = i.texcoord; - fixed2 scrollUV2 = i.texcoord; - fixed2 scrollUV3 = i.texcoord; - scrollUV.y += time; // a little twisting motion - scrollUV.x += time; - scrollUV2.x += time * 1.5; - scrollUV3.x += time * 0.5; - - // Each channel has its own tileable pattern which we want to scroll against one another - // at different rates. We pack 'em into channels because it's more performant than - // using 3 different texture lookups. - float r = tex2D(_MainTex, scrollUV).r; - float g = tex2D(_MainTex, scrollUV2).g; - float b = tex2D(_MainTex, scrollUV3).b; - - // Combine all channels - float gradient_lookup_value = (r + g + b) / 3.0; - gradient_lookup_value *= (1 - i.texcoord.x); // rescales the lookup value from start to finish - gradient_lookup_value = (pow(gradient_lookup_value, 2) + 0.125) * 3; - - float falloff = max((0.2 - i.texcoord.x) * 5, 0); - float tex = tex2D(_AlphaMask, saturate(gradient_lookup_value + falloff)).r; - - float4 color = encodeHdr ((tex * i.color).rgb ); - FRAG_MOBILESELECT(color) - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Comet" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _AlphaMask("Alpha Mask", 2D) = "white" {} + _Speed ("Animation Speed", Range (0,1)) = 1 + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + sampler2D _AlphaMask; + float4 _MainTex_ST; + float4 _AlphaMask_ST; + float _Speed; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float3 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = TbVertToNative(v.color); + +#ifdef AUDIO_REACTIVE + float3 displacement = _BeatOutput.y * v.normal * + saturate((1.0 - smoothstep(0, .3, v.texcoord.x)) * v.texcoord.z); + v.vertex.xyz += displacement; +#endif + o.pos = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + // Set up some staggered scrolling for "fire" effect +#ifdef AUDIO_REACTIVE + float time = (GetTime().x * 2 + _BeatOutputAccum.w) * -_Speed; +#else + float time = GetTime().y * -_Speed; +#endif + fixed2 scrollUV = i.texcoord; + fixed2 scrollUV2 = i.texcoord; + fixed2 scrollUV3 = i.texcoord; + scrollUV.y += time; // a little twisting motion + scrollUV.x += time; + scrollUV2.x += time * 1.5; + scrollUV3.x += time * 0.5; + + // Each channel has its own tileable pattern which we want to scroll against one another + // at different rates. We pack 'em into channels because it's more performant than + // using 3 different texture lookups. + float r = tex2D(_MainTex, scrollUV).r; + float g = tex2D(_MainTex, scrollUV2).g; + float b = tex2D(_MainTex, scrollUV3).b; + + // Combine all channels + float gradient_lookup_value = (r + g + b) / 3.0; + gradient_lookup_value *= (1 - i.texcoord.x); // rescales the lookup value from start to finish + gradient_lookup_value = (pow(gradient_lookup_value, 2) + 0.125) * 3; + + float falloff = max((0.2 - i.texcoord.x) * 5, 0); + float tex = tex2D(_AlphaMask, saturate(gradient_lookup_value + falloff)).r; + + float4 color = encodeHdr ((tex * i.color).rgb ); + FRAG_MOBILESELECT(color) + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/DanceFloor/DanceFloor.shader b/Assets/Resources/Brushes/Basic/DanceFloor/DanceFloor.shader index 117dee7c82..73a6880fa8 100644 --- a/Assets/Resources/Brushes/Basic/DanceFloor/DanceFloor.shader +++ b/Assets/Resources/Brushes/Basic/DanceFloor/DanceFloor.shader @@ -1,119 +1,141 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/DanceFloor" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} -} - -Category { - //Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - //Blend One One - //BlendOp Add, Min - //AlphaTest Greater .01 -// ColorMask RGBA - Cull Off Lighting Off ZWrite On Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma glsl - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 texcoord1 : TEXCOORD1; - float3 normal : NORMAL; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float4 worldPos = mul(unity_ObjectToWorld, v.vertex); - float waveform = 0; - - float lifetime = _Time.y - v.texcoord1.w; - float release = saturate(lifetime); - - -#ifdef AUDIO_REACTIVE - //worldPos.y -= release * fmod(_BeatOutputAccum.x * 2 - v.texcoord1.w, 5); - //worldPos.y += .3 * release * pow(sin(_BeatOutputAccum.x * 5 + worldPos.x),5); - lifetime = v.texcoord1.w * 10 + _BeatOutputAccum.x; - o.color += tex2Dlod(_WaveFormTex, float4(lifetime * 5,0, 0, 0)).r - .5; - -#endif - - v.color.xyz = pow(fmod(lifetime,1),3) * v.color.xyz; // * saturate(sin(lifetime * 10)) + v.color.zxy * saturate(cos(lifetime * 7)); - - // Quantize vertices - float q = 5; - float3 quantPos = ceil(worldPos.xyz * q) / q; - worldPos.xyz = quantPos; - worldPos.xyz += v.normal * pow(fmod(lifetime,1),3) * .1; - o.vertex = mul(UNITY_MATRIX_VP, worldPos); - o.color = 2 * v.color + v.color.yzxw * _BeatOutput.x; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.worldPos = worldPos.xyz; - return o; - } - - fixed4 frag (v2f i) : SV_Target - { - - //float waveform = tex2D(_WaveFormTex, float2(fmod(i.worldPos.x * 0.1f + _Time.y,1),0) ).r - .5f; - //i.texcoord.y += waveform; - float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); - return encodeHdr(c.rgb * c.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/DanceFloor" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + //Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + //Blend One One + //BlendOp Add, Min + //AlphaTest Greater .01 +// ColorMask RGBA + Cull Off Lighting Off ZWrite On Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma glsl + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float3 normal : NORMAL; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float3 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float4 worldPos = mul(unity_ObjectToWorld, v.vertex); + float waveform = 0; + + float lifetime = GetTime().y - v.texcoord1.w; + float release = saturate(lifetime); + + +#ifdef AUDIO_REACTIVE + //worldPos.y -= release * fmod(_BeatOutputAccum.x * 2 - v.texcoord1.w, 5); + //worldPos.y += .3 * release * pow(sin(_BeatOutputAccum.x * 5 + worldPos.x),5); + lifetime = v.texcoord1.w * 10 + _BeatOutputAccum.x; + o.color += tex2Dlod(_WaveFormTex, float4(lifetime * 5,0, 0, 0)).r - .5; + +#endif + + v.color.xyz = pow(fmod(lifetime,1),3) * v.color.xyz; // * saturate(sin(lifetime * 10)) + v.color.zxy * saturate(cos(lifetime * 7)); + + // Quantize vertices + float q = 5; + float3 quantPos = ceil(worldPos.xyz * q) / q; + worldPos.xyz = quantPos; + worldPos.xyz += v.normal * pow(fmod(lifetime,1),3) * .1; + o.vertex = mul(UNITY_MATRIX_VP, worldPos); + o.color = 2 * v.color + v.color.yzxw * _BeatOutput.x; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.worldPos = worldPos.xyz; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + //float waveform = tex2D(_WaveFormTex, float2(fmod(i.worldPos.x * 0.1f + GetTime().y,1),0) ).r - .5f; + //i.texcoord.y += waveform; + float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); + c = encodeHdr(c.rgb * c.a); + return c; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/DiamondHull/DiamondHull.shader b/Assets/Resources/Brushes/Basic/DiamondHull/DiamondHull.shader index 579209190a..275946fd19 100644 --- a/Assets/Resources/Brushes/Basic/DiamondHull/DiamondHull.shader +++ b/Assets/Resources/Brushes/Basic/DiamondHull/DiamondHull.shader @@ -1,173 +1,214 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/DiamondHull" { - Properties { - _MainTex("Texture", 2D) = "white" {} - } - - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - Cull off ZWrite Off - Fog{ Mode Off } - - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert nofog - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct Input { - float4 color : Color; - float2 tex : TEXCOORD0; - float3 viewDir; - float3 worldPos; - float3 worldNormal; - INTERNAL_DATA - }; - - // Amplitude reflection coefficient (s-polarized) - float rs(float n1, float n2, float cosI, float cosT) { - return (n1 * cosI - n2 * cosT) / (n1 * cosI + n2 * cosT); - } - - // Amplitude reflection coefficient (p-polarized) - float rp(float n1, float n2, float cosI, float cosT) { - return (n2 * cosI - n1 * cosT) / (n1 * cosT + n2 * cosI); - } - - // Amplitude transmission coefficient (s-polarized) - float ts(float n1, float n2, float cosI, float cosT) { - return 2 * n1 * cosI / (n1 * cosI + n2 * cosT); - } - - // Amplitude transmission coefficient (p-polarized) - float tp(float n1, float n2, float cosI, float cosT) { - return 2 * n1 * cosI / (n1 * cosT + n2 * cosI); - } - - // cosI is the cosine of the incident angle, that is, cos0 = dot(view angle, normal) - // lambda is the wavelength of the incident light (e.g. lambda = 510 for green) - // http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/thin-film-interference-for-computer-graphics-r2962 - float thinFilmReflectance(float cos0, float lambda, float thickness, float n0, float n1, float n2) { - float PI = 3.1415926536; - - // Phase change terms. - const float d10 = lerp(PI, 0, n1 > n0); - const float d12 = lerp(PI, 0, n1 > n2); - const float delta = d10 + d12; - - // Cosine of the reflected angle. - const float sin1 = pow(n0 / n1, 2) * (1 - pow(cos0, 2)); - - // Total internal reflection. - if (sin1 > 1) return 1.0; - const float cos1 = sqrt(1 - sin1); - - // Cosine of the final transmitted angle, i.e. cos(theta_2) - // This angle is for the Fresnel term at the bottom interface. - const float sin2 = pow(n0 / n2, 2) * (1 - pow(cos0, 2)); - - // Total internal reflection. - if (sin2 > 1) return 1.0; - - const float cos2 = sqrt(1 - sin2); - - // Reflection transmission amplitude Fresnel coefficients. - // rho_10 * rho_12 (s-polarized) - const float alpha_s = rs(n1, n0, cos1, cos0) * rs(n1, n2, cos1, cos2); - // rho_10 * rho_12 (p-polarized) - const float alpha_p = rp(n1, n0, cos1, cos0) * rp(n1, n2, cos1, cos2); - - // tau_01 * tau_12 (s-polarized) - const float beta_s = ts(n0, n1, cos0, cos1) * ts(n1, n2, cos1, cos2); - // tau_01 * tau_12 (p-polarized) - const float beta_p = tp(n0, n1, cos0, cos1) * tp(n1, n2, cos1, cos2); - - // Compute the phase term (phi). - const float phi = (2 * PI / lambda) * (2 * n1 * thickness * cos1) + delta; - - // Evaluate the transmitted intensity for the two possible polarizations. - const float ts = pow(beta_s, 2) / (pow(alpha_s, 2) - 2 * alpha_s * cos(phi) + 1); - const float tp = pow(beta_p, 2) / (pow(alpha_p, 2) - 2 * alpha_p * cos(phi) + 1); - - // Take into account conservation of energy for transmission. - const float beamRatio = (n2 * cos2) / (n0 * cos0); - - // Calculate the average transmitted intensity (polarization distribution of the - // light source here. If unknown, 50%/50% average is generally used) - const float t = beamRatio * (ts + tp) / 2; - - // Derive the reflected intensity. - return 1 - t; - } - - float3 GetDiffraction(float3 thickTex, float3 I, float3 N) { - const float thicknessMin = 250; - const float thicknessMax = 400; - const float nmedium = 1; - const float nfilm = 1.3; - const float ninternal = 1; - - const float cos0 = abs(dot(I, N)); - - //float3 thickTex = texture(thickness, u, v); - const float t = (thickTex[0] + thickTex[1] + thickTex[2]) / 3.0; - const float thick = thicknessMin*(1.0 - t) + thicknessMax*t; - - const float red = thinFilmReflectance(cos0, 650, thick, nmedium, nfilm, ninternal); - const float green = thinFilmReflectance(cos0, 510, thick, nmedium, nfilm, ninternal); - const float blue = thinFilmReflectance(cos0, 475, thick, nmedium, nfilm, ninternal); - - return float3(red, green, blue); - } - - void vert (inout appdata_full v, out Input o) { - PrepForOds(v.vertex); - o.color = TbVertToSrgb(o.color); - UNITY_INITIALIZE_OUTPUT(Input, o); - o.tex = v.texcoord.xy; - } - - // Input color is srgb - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - // Hardcode some shiny specular values - o.Smoothness = .8; - o.Albedo = IN.color * .2; - - // Calculate rim - half rim = 1.0 - abs(dot(normalize(IN.viewDir), IN.worldNormal)); - rim *= 1-pow(rim,5); - - const float3 I = (_WorldSpaceCameraPos - IN.worldPos); - rim = lerp(rim, 150, - 1 - saturate(abs(dot(normalize(I), IN.worldNormal)) / .1)); - - float3 diffraction = tex2D(_MainTex, half2(rim + _Time.x * .3 + o.Normal.x, rim + o.Normal.y)).xyz; - diffraction = GetDiffraction(diffraction, o.Normal, normalize(IN.viewDir)); - - o.Emission = rim * IN.color * diffraction * .5 + rim * diffraction * .25; - SURF_FRAG_MOBILESELECT(o); - o.Specular = SrgbToNative(IN.color).rgb * clamp(diffraction, .0, 1); - } - ENDCG - } -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/DiamondHull" { + Properties { + _MainTex("Texture", 2D) = "white" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + Cull off ZWrite Off + Fog{ Mode Off } + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert nofog + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct Input { + float4 vertex : SV_POSITION; + float4 color : Color; + float2 tex : TEXCOORD0; + float3 viewDir; + float3 worldPos; + float3 worldNormal; + uint id : SV_VertexID; + INTERNAL_DATA + }; + + // Amplitude reflection coefficient (s-polarized) + float rs(float n1, float n2, float cosI, float cosT) { + return (n1 * cosI - n2 * cosT) / (n1 * cosI + n2 * cosT); + } + + // Amplitude reflection coefficient (p-polarized) + float rp(float n1, float n2, float cosI, float cosT) { + return (n2 * cosI - n1 * cosT) / (n1 * cosT + n2 * cosI); + } + + // Amplitude transmission coefficient (s-polarized) + float ts(float n1, float n2, float cosI, float cosT) { + return 2 * n1 * cosI / (n1 * cosI + n2 * cosT); + } + + // Amplitude transmission coefficient (p-polarized) + float tp(float n1, float n2, float cosI, float cosT) { + return 2 * n1 * cosI / (n1 * cosT + n2 * cosI); + } + + // cosI is the cosine of the incident angle, that is, cos0 = dot(view angle, normal) + // lambda is the wavelength of the incident light (e.g. lambda = 510 for green) + // http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/thin-film-interference-for-computer-graphics-r2962 + float thinFilmReflectance(float cos0, float lambda, float thickness, float n0, float n1, float n2) { + float PI = 3.1415926536; + + // Phase change terms. + const float d10 = lerp(PI, 0, n1 > n0); + const float d12 = lerp(PI, 0, n1 > n2); + const float delta = d10 + d12; + + // Cosine of the reflected angle. + const float sin1 = pow(n0 / n1, 2) * (1 - pow(cos0, 2)); + + // Total internal reflection. + if (sin1 > 1) return 1.0; + const float cos1 = sqrt(1 - sin1); + + // Cosine of the final transmitted angle, i.e. cos(theta_2) + // This angle is for the Fresnel term at the bottom interface. + const float sin2 = pow(n0 / n2, 2) * (1 - pow(cos0, 2)); + + // Total internal reflection. + if (sin2 > 1) return 1.0; + + const float cos2 = sqrt(1 - sin2); + + // Reflection transmission amplitude Fresnel coefficients. + // rho_10 * rho_12 (s-polarized) + const float alpha_s = rs(n1, n0, cos1, cos0) * rs(n1, n2, cos1, cos2); + // rho_10 * rho_12 (p-polarized) + const float alpha_p = rp(n1, n0, cos1, cos0) * rp(n1, n2, cos1, cos2); + + // tau_01 * tau_12 (s-polarized) + const float beta_s = ts(n0, n1, cos0, cos1) * ts(n1, n2, cos1, cos2); + // tau_01 * tau_12 (p-polarized) + const float beta_p = tp(n0, n1, cos0, cos1) * tp(n1, n2, cos1, cos2); + + // Compute the phase term (phi). + const float phi = (2 * PI / lambda) * (2 * n1 * thickness * cos1) + delta; + + // Evaluate the transmitted intensity for the two possible polarizations. + const float ts = pow(beta_s, 2) / (pow(alpha_s, 2) - 2 * alpha_s * cos(phi) + 1); + const float tp = pow(beta_p, 2) / (pow(alpha_p, 2) - 2 * alpha_p * cos(phi) + 1); + + // Take into account conservation of energy for transmission. + const float beamRatio = (n2 * cos2) / (n0 * cos0); + + // Calculate the average transmitted intensity (polarization distribution of the + // light source here. If unknown, 50%/50% average is generally used) + const float t = beamRatio * (ts + tp) / 2; + + // Derive the reflected intensity. + return 1 - t; + } + + float3 GetDiffraction(float3 thickTex, float3 I, float3 N) { + const float thicknessMin = 250; + const float thicknessMax = 400; + const float nmedium = 1; + const float nfilm = 1.3; + const float ninternal = 1; + + const float cos0 = abs(dot(I, N)); + + //float3 thickTex = texture(thickness, u, v); + const float t = (thickTex[0] + thickTex[1] + thickTex[2]) / 3.0; + const float thick = thicknessMin*(1.0 - t) + thicknessMax*t; + + const float red = thinFilmReflectance(cos0, 650, thick, nmedium, nfilm, ninternal); + const float green = thinFilmReflectance(cos0, 510, thick, nmedium, nfilm, ninternal); + const float blue = thinFilmReflectance(cos0, 475, thick, nmedium, nfilm, ninternal); + + return float3(red, green, blue); + } + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id v, out Input o) { + PrepForOds(v.vertex); + o.color = TbVertToSrgb(o.color); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.tex = v.texcoord.xy; + o.id = v.id; + } + + // Input color is srgb + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.vertex.xy) >= _Dissolve) discard; + #endif + + // Hardcode some shiny specular values + o.Smoothness = .8; + o.Albedo = IN.color * .2; + + // Calculate rim + half rim = 1.0 - abs(dot(normalize(IN.viewDir), IN.worldNormal)); + rim *= 1-pow(rim,5); + + const float3 I = (_WorldSpaceCameraPos - IN.worldPos); + rim = lerp(rim, 150, + 1 - saturate(abs(dot(normalize(I), IN.worldNormal)) / .1)); + + float3 diffraction = tex2D(_MainTex, half2(rim + GetTime().x * .3 + o.Normal.x, rim + o.Normal.y)).xyz; + diffraction = GetDiffraction(diffraction, o.Normal, normalize(IN.viewDir)); + + o.Emission = rim * IN.color * diffraction * .5 + rim * diffraction * .25; + // SURF_FRAG_MOBILESELECT(o); + o.Specular = SrgbToNative(IN.color).rgb * clamp(diffraction, .0, 1); + o.Emission *= _Opacity; + o.Albedo *= _Opacity; + o.Specular *= _Opacity; + } + ENDCG + } +} diff --git a/Assets/Resources/Brushes/Basic/Disco/Disco.shader b/Assets/Resources/Brushes/Basic/Disco/Disco.shader index 8398911aee..cdef87b6f9 100644 --- a/Assets/Resources/Brushes/Basic/Disco/Disco.shader +++ b/Assets/Resources/Brushes/Basic/Disco/Disco.shader @@ -1,94 +1,132 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Disco" { - Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - } - SubShader { - Cull Back - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert noshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - float3 worldPos; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full v, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); - float t, uTileRate, waveIntensity; - - float radius = v.texcoord.z; - -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.z * 5; - uTileRate = 5; - waveIntensity = (_PeakBandLevels.y * .8 + .5); - float waveform = tex2Dlod(_WaveFormTex, float4(v.texcoord.x * 2, 0, 0, 0)).b - .5f; - v.vertex.xyz += waveform * v.normal.xyz * .2; -#else - t = _Time.z; - uTileRate = 10; - waveIntensity = .6; -#endif - // Ensure the t parameter wraps (1.0 becomes 0.0) to avoid cracks at the seam. - float theta = fmod(v.texcoord.y, 1); - v.vertex.xyz += pow(1 -(sin(t + v.texcoord.x * uTileRate + theta * 10) + 1),2) - * v.normal.xyz * waveIntensity - * radius; - } - - // Input color is _native_ - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; - o.Smoothness = _Shininess; - o.Specular = _SpecColor * IN.color.rgb; - o.Normal = float3(0,0,1); - - // XXX need to convert world normal to tangent space normal somehow... - float3 worldNormal = normalize(cross(ddy(IN.worldPos), ddx(IN.worldPos))); - o.Normal = -cross(cross(o.Normal, worldNormal), worldNormal); - o.Normal = normalize(o.Normal); - - // Add a fake "disco ball" hot spot - float fakeLight = pow( abs(dot(worldNormal, float3(0,1,0))),100); - o.Emission = IN.color.rgb * fakeLight * 200; - SURF_FRAG_MOBILESELECT(o); - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Disco" { + Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("_Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader { + Cull Back + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert noshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "Assets/Shaders/Include/Brush.cginc" + + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + float3 worldPos; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + float t, uTileRate, waveIntensity; + + float radius = v.texcoord.z; + +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.z * 5; + uTileRate = 5; + waveIntensity = (_PeakBandLevels.y * .8 + .5); + float waveform = tex2Dlod(_WaveFormTex, float4(v.texcoord.x * 2, 0, 0, 0)).b - .5f; + v.vertex.xyz += waveform * v.normal.xyz * .2; +#else + t = GetTime().z; + uTileRate = 10; + waveIntensity = .6; +#endif + // Ensure the t parameter wraps (1.0 becomes 0.0) to avoid cracks at the seam. + float theta = fmod(v.texcoord.y, 1); + v.vertex.xyz += pow(1 -(sin(t + v.texcoord.x * uTileRate + theta * 10) + 1),2) + * v.normal.xyz * waveIntensity + * radius; + o.id = v.id; + } + + // Input color is _native_ + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; + o.Smoothness = _Shininess; + o.Specular = _SpecColor * IN.color.rgb; + o.Normal = float3(0,0,1); + + // XXX need to convert world normal to tangent space normal somehow... + float3 worldNormal = normalize(cross(ddy(IN.worldPos), ddx(IN.worldPos))); + o.Normal = -cross(cross(o.Normal, worldNormal), worldNormal); + o.Normal = normalize(o.Normal); + + // Add a fake "disco ball" hot spot + float fakeLight = pow( abs(dot(worldNormal, float3(0,1,0))),100); + o.Emission = IN.color.rgb * fakeLight * 200; + SURF_FRAG_MOBILESELECT(o); + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Basic/Dots/Dots.shader b/Assets/Resources/Brushes/Basic/Dots/Dots.shader index 12e0f7013a..198434dd2a 100644 --- a/Assets/Resources/Brushes/Basic/Dots/Dots.shader +++ b/Assets/Resources/Brushes/Basic/Dots/Dots.shader @@ -1,129 +1,145 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/Dots" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _WaveformFreq("Waveform Freq", Float) = 1 - _WaveformIntensity("Waveform Intensity", Vector) = (0,1,0,0) - _BaseGain("Base Gain", Float) = 0 - _EmissionGain("Emission Gain", Float) = 0 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma glsl - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float waveform : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _WaveformFreq; - float4 _WaveformIntensity; - float _EmissionGain; - float _BaseGain; - - v2f vert (ParticleVertex_t v) - { - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float4 center = float4(v.center.xyz, 1); - PrepForOds(center); - float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); - float waveform = 0; - // TODO: displacement should happen before orientation -#ifdef AUDIO_REACTIVE - float4 dispVec = float4(0,0,0,0); - float4 corner_WS = mul(unity_ObjectToWorld, corner); - // TODO: worldspace is almost certainly incorrect: use scene or object? - waveform = tex2Dlod(_FFTTex, float4(fmod(corner_WS.x * _WaveformFreq + _BeatOutputAccum.z*.5,1),0,0,0) ).b * .25; - dispVec.xyz += waveform * _WaveformIntensity.xyz; - corner = corner + dispVec; -#endif - o.vertex = UnityObjectToClipPos(corner); - o.color = v.color * _BaseGain; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - o.waveform = waveform * 15; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : SV_Target - { -#ifdef AUDIO_REACTIVE - // Deform uv's by waveform displacement amount vertically - // Envelop by "V" UV to keep the edges clean - float vDistance = abs(i.texcoord.y - .5)*2; - float vStretched = (i.texcoord.y - 0.5) * (.5 - abs(i.waveform)) * 2 + 0.5; - i.texcoord.y = lerp(vStretched, i.texcoord.y, vDistance); -#endif - float4 tex = tex2D(_MainTex, i.texcoord); - float4 c = i.color * _TintColor * tex; - - // Only alpha channel receives emission boost - c.rgb += c.rgb * c.a * _EmissionGain; - c.a = 1; - c = SrgbToNative(c); - c = encodeHdr(c.rgb); -#if SELECTION_ON - c.rgb = GetSelectionColor() * tex.r; -#endif - return c; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/Dots" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _WaveformFreq("Waveform Freq", Float) = 1 + _WaveformIntensity("Waveform Intensity", Vector) = (0,1,0,0) + _BaseGain("Base Gain", Float) = 0 + _EmissionGain("Emission Gain", Float) = 0 + + _Dissolve("_Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma glsl + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float waveform : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _WaveformFreq; + float4 _WaveformIntensity; + float _EmissionGain; + float _BaseGain; + + v2f vert (ParticleVertex_t v) + { + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float4 center = float4(v.center.xyz, 1); + PrepForOds(center); + float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); + float waveform = 0; + // TODO: displacement should happen before orientation +#ifdef AUDIO_REACTIVE + float4 dispVec = float4(0,0,0,0); + float4 corner_WS = mul(unity_ObjectToWorld, corner); + // TODO: worldspace is almost certainly incorrect: use scene or object? + waveform = tex2Dlod(_FFTTex, float4(fmod(corner_WS.x * _WaveformFreq + _BeatOutputAccum.z*.5,1),0,0,0) ).b * .25; + dispVec.xyz += waveform * _WaveformIntensity.xyz; + corner = corner + dispVec; +#endif + o.vertex = UnityObjectToClipPos(corner); + o.color = v.color * _BaseGain; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + o.waveform = waveform * 15; + o.id = v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + #ifdef AUDIO_REACTIVE + // Deform uv's by waveform displacement amount vertically + // Envelop by "V" UV to keep the edges clean + float vDistance = abs(i.texcoord.y - .5)*2; + float vStretched = (i.texcoord.y - 0.5) * (.5 - abs(i.waveform)) * 2 + 0.5; + i.texcoord.y = lerp(vStretched, i.texcoord.y, vDistance); +#endif + float4 tex = tex2D(_MainTex, i.texcoord); + float4 c = i.color * _TintColor * tex; + + // Only alpha channel receives emission boost + c.rgb += c.rgb * c.a * _EmissionGain; + c.a = 1; + c = SrgbToNative(c); + c = encodeHdr(c.rgb); +#if SELECTION_ON + c.rgb = GetSelectionColor() * tex.r; +#endif + return c * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/DoubleTaperedFlat/DiffuseNoTextureDoubleSided.shader b/Assets/Resources/Brushes/Basic/DoubleTaperedFlat/DiffuseNoTextureDoubleSided.shader index 5e97b0e7c4..5cab63c61f 100644 --- a/Assets/Resources/Brushes/Basic/DoubleTaperedFlat/DiffuseNoTextureDoubleSided.shader +++ b/Assets/Resources/Brushes/Basic/DoubleTaperedFlat/DiffuseNoTextureDoubleSided.shader @@ -1,79 +1,97 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/DiffuseNoTextureDoubleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) -} - -SubShader { - Cull Off - Tags{ "DisableBatching" = "True" } - - CGPROGRAM - #pragma surface surf Lambert vertex:vert addshadow - #pragma target 3.0 - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - fixed4 _Color; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float4 tangent : TANGENT; - float2 texcoord0 : TEXCOORD0; - float3 texcoord1 : TEXCOORD1; - float4 texcoord2 : TEXCOORD2; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - - struct Input { - float2 uv_MainTex; - float4 color : COLOR; - fixed vface : VFACE; - }; - - void vert (inout appdata_t v, out Input o) { - PrepForOds(v.vertex); - - // - // XXX - THIS TAPERING CODE SHOULD BE REMOVED ONCE THE TAPERING IS DONE IN THE GEOMETRY GENERATION - // THE SHADER WILL REMAIN AS A SIMPLE "DiffuseNoTextureDoubleSided" SHADER. - // - - UNITY_INITIALIZE_OUTPUT(Input, o); - float envelope = sin(v.texcoord0.x * 3.14159); - float widthMultiplier = 1 - envelope; - v.vertex.xyz += -v.texcoord1 * widthMultiplier; - v.color = TbVertToNative(v.color); - } - - void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = _Color; - o.Normal = float3(0,0,IN.vface); - o.Albedo = c.rgb * IN.color.rgb; - SURF_FRAG_MOBILESELECT(o); - } - ENDCG -} - -Fallback "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/DiffuseNoTextureDoubleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Cull Off + Tags{ "DisableBatching" = "True" } + + CGPROGRAM + #pragma surface surf Lambert vertex:vert addshadow + #pragma target 3.0 + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + fixed4 _Color; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float2 texcoord0 : TEXCOORD0; + float3 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + + struct Input { + float2 uv_MainTex; + float4 color : COLOR; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 screenPos; + }; + + void vert (inout appdata_t v, out Input o) { + PrepForOds(v.vertex); + + // + // XXX - THIS TAPERING CODE SHOULD BE REMOVED ONCE THE TAPERING IS DONE IN THE GEOMETRY GENERATION + // THE SHADER WILL REMAIN AS A SIMPLE "DiffuseNoTextureDoubleSided" SHADER. + // + + UNITY_INITIALIZE_OUTPUT(Input, o); + float envelope = sin(v.texcoord0.x * 3.14159); + float widthMultiplier = 1 - envelope; + v.vertex.xyz += -v.texcoord1 * widthMultiplier; + v.color = TbVertToNative(v.color); + o.id = v.id; + } + + void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = _Color; + o.Normal = float3(0,0,IN.vface); + o.Albedo = c.rgb * IN.color.rgb; + SURF_FRAG_MOBILESELECT(o); + } + ENDCG +} + +Fallback "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Basic/DoubleTaperedMarker/DoubleTaperedMarker.shader b/Assets/Resources/Brushes/Basic/DoubleTaperedMarker/DoubleTaperedMarker.shader index a8f7d4e6f3..9f0afa5589 100644 --- a/Assets/Resources/Brushes/Basic/DoubleTaperedMarker/DoubleTaperedMarker.shader +++ b/Assets/Resources/Brushes/Basic/DoubleTaperedMarker/DoubleTaperedMarker.shader @@ -1,97 +1,112 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/DoubleTaperedMarker" { -Properties { -} - -Category { - Cull Off Lighting Off - - SubShader { - Tags{ "DisableBatching" = "True" } - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile_fog - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord0 : TEXCOORD0; - float3 texcoord1 : TEXCOORD1; //per vert offset vector - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - UNITY_FOG_COORDS(1) - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - // - // XXX - THIS SHADER SHOULD BE DELETED AFTER TAPERING IS DONE IN THE GEOMETRY GENERATION - // - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float envelope = sin(v.texcoord0.x * 3.14159); - float widthMultiplier = 1 - envelope; - v.vertex.xyz += -v.texcoord1 * widthMultiplier; - o.pos = UnityObjectToClipPos(v.vertex); - o.color = TbVertToNative(v.color); - o.texcoord = v.texcoord0; - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - UNITY_APPLY_FOG(i.fogCoord, i.color.rgb); - float4 color = float4(i.color.rgb, 1); - FRAG_MOBILESELECT(color) - return color; - } - - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/DoubleTaperedMarker" { +Properties { + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Cull Off Lighting Off + + SubShader { + Tags{ "DisableBatching" = "True" } + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile_fog + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord0 : TEXCOORD0; + float3 texcoord1 : TEXCOORD1; //per vert offset vector + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + UNITY_FOG_COORDS(1) + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + // + // XXX - THIS SHADER SHOULD BE DELETED AFTER TAPERING IS DONE IN THE GEOMETRY GENERATION + // + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float envelope = sin(v.texcoord0.x * 3.14159); + float widthMultiplier = 1 - envelope; + v.vertex.xyz += -v.texcoord1 * widthMultiplier; + o.pos = UnityObjectToClipPos(v.vertex); + o.color = TbVertToNative(v.color); + o.texcoord = v.texcoord0; + o.id = (float2)v.id; + UNITY_TRANSFER_FOG(o, o.pos); + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + UNITY_APPLY_FOG(i.fogCoord, i.color.rgb); + float4 color = float4(i.color.rgb, 1); + FRAG_MOBILESELECT(color) + return color; + } + + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Electricity/Electricity.shader b/Assets/Resources/Brushes/Basic/Electricity/Electricity.shader index f8f3f9c877..ba0559ba9c 100644 --- a/Assets/Resources/Brushes/Basic/Electricity/Electricity.shader +++ b/Assets/Resources/Brushes/Basic/Electricity/Electricity.shader @@ -1,224 +1,248 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Electricity" { -Properties { - _MainTex ("Color", 2D) = "white" {} - _DisplacementIntensity("Displacement", Float) = .1 - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -CGINCLUDE - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - #ifdef SHADER_API_D3D11 - # define SHARP_AND_BLOOMY 1 - #else - # define SHARP_AND_BLOOMY 0 - #endif - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float3 tangent : TANGENT; - float2 texcoord0 : TEXCOORD0; - float3 texcoord1 : TEXCOORD1; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - sampler2D _MainTex; - half _DisplacementIntensity; - half _EmissionGain; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float3 displacement(float3 pos, float mod) { - // Noise - float time = _Time.w; - float d = 30; - float freq = .1 + mod; - float3 disp = float3(1,0,0) * curlX(pos * freq + time, d); - disp += float3(0,1,0) * curlY(pos * freq + time, d); - disp += float3(0,0,1) * curlZ(pos * freq + time, d); - - time = _Time.w*1.777; - d = 100; - freq = .2 + mod; - float3 disp2 = float3(1,0,0) * curlX(pos * freq + time, d); - disp2 += float3(0,1,0) * curlY(pos * freq + time, d); - disp2 += float3(0,0,1) * curlZ(pos * freq + time, d); - disp = disp * 3 + disp2 * 7; - return disp; - } - - - v2f vertModulated (appdata_t v, float mod, float dir) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float envelope = sin(v.texcoord0.x * (3.14159)); - float envelopePow = (1-pow(1 - envelope, 10)); - - float3 offsetFromMiddleToEdge_CS = v.texcoord1; - float widthiness_CS = length(offsetFromMiddleToEdge_CS) / .02; - float3 midpointPos_CS = v.vertex.xyz - offsetFromMiddleToEdge_CS; - float3 disp = displacement(midpointPos_CS / widthiness_CS, mod); - disp *= widthiness_CS; - - float waveform = 0; -#ifdef AUDIO_REACTIVE - disp *= (_BeatOutput.x * 1 + .5); - waveform = (tex2Dlod(_WaveFormTex, float4(v.texcoord0.x,0,0,0)).r - .5f); - disp.y += waveform * .1; - v.color = v.color*.5 + v.color*_BeatOutput.z*.5; -#endif - - // Slightly thicken the line on mobile to accommodate the softer interior line. This reduces artifacts - // from the low resolution. -#if SHARP_AND_BLOOMY - float widthScale = 1.0; -#else - float widthScale = 1.6; -#endif - - // This recreates the standard ribbon position with some tapering at edges - v.vertex.xyz = midpointPos_CS + offsetFromMiddleToEdge_CS * envelopePow * widthScale; - - // This adds curl noise - v.vertex.xyz += disp * _DisplacementIntensity * envelopePow; - - o.vertex = UnityObjectToClipPos(v.vertex); - // TODO(b/123094204) bloom is turned off on mobile as it completely broke the shader - // for still-unknown reasons. -#if SHARP_AND_BLOOMY - o.color = bloomColor(v.color, _EmissionGain); -#else - o.color = v.color; -#endif - o.texcoord = v.texcoord0; - return o; - } - - v2f vert_1 (appdata_t v) - { - return vertModulated(v, 1, 1); - } - - v2f vert_2 (appdata_t v) - { - return vertModulated(v, 1.333, -1); - } - - v2f vert_3 (appdata_t v) - { - return vertModulated(v, 1.77, -1); - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - // interior procedural line -#if SHARP_AND_BLOOMY - // Step function: 3 in [.4, .6], 1 elsewhere - float procedural = ( abs(i.texcoord.y - 0.5) < .1 ) ? 3 : 1; -#else - // The lack of AA and low resolution on mobile is really visible, so instead use a - // softer interior line. This has a lot more brightness, so it's good that the - // vertex color isn't also blown out. - - float edginess = ( abs(i.texcoord.y - 0.5) * 2.0 ); // in [0, 1] - // Smooth ramp from 2 in the middle to 1 on the edge - float procedural = lerp(2.0, 1.0, edginess); -#endif - - // Ignore incoming i.color.a -#if SELECTION_ON - float3 unencoded = GetSelectionColor() * (0.5 * procedural); -#else - float3 unencoded = i.color.rgb * (procedural * procedural); -#endif - - // It doesn't matter which of these is first since they can't both be active at the same time; - // but only one ordering will compile because of the return types. - return SrgbToNative(encodeHdr(unencoded)); - } -ENDCG - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One //SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - - SubShader { - Pass { - CGPROGRAM - #pragma vertex vert_1 - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - ENDCG - } - - Pass { - CGPROGRAM - #pragma vertex vert_2 - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - ENDCG - } - - Pass { - CGPROGRAM - #pragma vertex vert_3 - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Electricity" { +Properties { + _MainTex ("Color", 2D) = "white" {} + _DisplacementIntensity("Displacement", Float) = .1 + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +CGINCLUDE + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + #ifdef SHADER_API_D3D11 + # define SHARP_AND_BLOOMY 1 + #else + # define SHARP_AND_BLOOMY 0 + #endif + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float3 tangent : TANGENT; + float2 texcoord0 : TEXCOORD0; + float3 texcoord1 : TEXCOORD1; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + sampler2D _MainTex; + half _DisplacementIntensity; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float3 displacement(float3 pos, float mod) { + // Noise + float time = GetTime().w; + float d = 30; + float freq = .1 + mod; + float3 disp = float3(1,0,0) * curlX(pos * freq + time, d); + disp += float3(0,1,0) * curlY(pos * freq + time, d); + disp += float3(0,0,1) * curlZ(pos * freq + time, d); + + time = GetTime().w*1.777; + d = 100; + freq = .2 + mod; + float3 disp2 = float3(1,0,0) * curlX(pos * freq + time, d); + disp2 += float3(0,1,0) * curlY(pos * freq + time, d); + disp2 += float3(0,0,1) * curlZ(pos * freq + time, d); + disp = disp * 3 + disp2 * 7; + return disp; + } + + + v2f vertModulated (appdata_t v, float mod, float dir) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float envelope = sin(v.texcoord0.x * (3.14159)); + float envelopePow = (1-pow(1 - envelope, 10)); + + float3 offsetFromMiddleToEdge_CS = v.texcoord1; + float widthiness_CS = length(offsetFromMiddleToEdge_CS) / .02; + float3 midpointPos_CS = v.vertex.xyz - offsetFromMiddleToEdge_CS; + float3 disp = displacement(midpointPos_CS / widthiness_CS, mod); + disp *= widthiness_CS; + + float waveform = 0; +#ifdef AUDIO_REACTIVE + disp *= (_BeatOutput.x * 1 + .5); + waveform = (tex2Dlod(_WaveFormTex, float4(v.texcoord0.x,0,0,0)).r - .5f); + disp.y += waveform * .1; + v.color = v.color*.5 + v.color*_BeatOutput.z*.5; +#endif + + // Slightly thicken the line on mobile to accommodate the softer interior line. This reduces artifacts + // from the low resolution. +#if SHARP_AND_BLOOMY + float widthScale = 1.0; +#else + float widthScale = 1.6; +#endif + + // This recreates the standard ribbon position with some tapering at edges + v.vertex.xyz = midpointPos_CS + offsetFromMiddleToEdge_CS * envelopePow * widthScale; + + // This adds curl noise + v.vertex.xyz += disp * _DisplacementIntensity * envelopePow; + + o.vertex = UnityObjectToClipPos(v.vertex); + // TODO(b/123094204) bloom is turned off on mobile as it completely broke the shader + // for still-unknown reasons. +#if SHARP_AND_BLOOMY + o.color = bloomColor(v.color, _EmissionGain); +#else + o.color = v.color; +#endif + o.texcoord = v.texcoord0; + o.id = (float2)v.id; + return o; + } + + v2f vert_1 (appdata_t v) + { + return vertModulated(v, 1, 1); + } + + v2f vert_2 (appdata_t v) + { + return vertModulated(v, 1.333, -1); + } + + v2f vert_3 (appdata_t v) + { + return vertModulated(v, 1.77, -1); + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // interior procedural line +#if SHARP_AND_BLOOMY + // Step function: 3 in [.4, .6], 1 elsewhere + float procedural = ( abs(i.texcoord.y - 0.5) < .1 ) ? 3 : 1; +#else + // The lack of AA and low resolution on mobile is really visible, so instead use a + // softer interior line. This has a lot more brightness, so it's good that the + // vertex color isn't also blown out. + + float edginess = ( abs(i.texcoord.y - 0.5) * 2.0 ); // in [0, 1] + // Smooth ramp from 2 in the middle to 1 on the edge + float procedural = lerp(2.0, 1.0, edginess); +#endif + + // Ignore incoming i.color.a +#if SELECTION_ON + float3 unencoded = GetSelectionColor() * (0.5 * procedural); +#else + float3 unencoded = i.color.rgb * (procedural * procedural); +#endif + + // It doesn't matter which of these is first since they can't both be active at the same time; + // but only one ordering will compile because of the return types. + float4 color = encodeHdr(unencoded); + return SrgbToNative(color * _Dissolve); + } +ENDCG + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One //SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + + SubShader { + Pass { + CGPROGRAM + #pragma vertex vert_1 + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + ENDCG + } + + Pass { + CGPROGRAM + #pragma vertex vert_2 + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + ENDCG + } + + Pass { + CGPROGRAM + #pragma vertex vert_3 + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Embers/Embers.shader b/Assets/Resources/Brushes/Basic/Embers/Embers.shader index eace4ad726..ab2356d624 100644 --- a/Assets/Resources/Brushes/Basic/Embers/Embers.shader +++ b/Assets/Resources/Brushes/Basic/Embers/Embers.shader @@ -1,180 +1,201 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/Embers" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 - _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _ScrollRate; - // In decimeters - float3 _ScrollDistance; - // Amplitude: in decimeters - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - float _SpreadRate; - - // pos and seed should be stable values. - // seed is a value in [0, 1] - // t01 is a time value in [0, 1] - float3 ComputeDisplacement(float3 pos, float seed, float t01) { - float t2 = _Time.y; - float floatUpTime01 = t01; - -#if SELECTION_ON - t01 = 0; - t2 = 0; -#endif - - // Animate the motion of the embers - // Accumulate all displacement into a common, pre-transformed space. - float4 dispVec = float4(_ScrollDistance, 0.0) * t01; - - dispVec.x += sin(t01 * _ScrollJitterFrequency + seed * 100 + t2 + pos.z) * _ScrollJitterIntensity; - dispVec.y += (fmod(seed * 100, 1) - 0.5) * _ScrollDistance.y * floatUpTime01; - dispVec.z += cos(t01 * _ScrollJitterFrequency + seed * 100 + t2 + pos.x) * _ScrollJitterIntensity; - -#ifdef AUDIO_REACTIVE - float fft = (tex2Dlod(_FFTTex, float4(pos.y,0,0,0)).b)*2 + .1; - dispVec.y += fft; -#endif - -#if SELECTION_ON - dispVec.y = abs(dispVec.y * 0.2); - dispVec *= 0.5; -#endif - return dispVec * kDecimetersToWorldUnits; - } - - v2f vert (ParticleVertexWithSpread_t v) { - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - // Used as a random-ish seed for various calculations - float seed = v.color.a; - float t01 = fmod(_Time.y*_ScrollRate + seed * 10, 1); - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float spreadProgress = SpreadProgress(birthTime, _SpreadRate); - float4 center = SpreadParticle(v, spreadProgress); - float3 disp = ComputeDisplacement(center.xyz, seed, t01); - disp = spreadProgress * disp; - - // Ramp color from bright to dark over particle lifetime - float3 incolor = v.color.rgb; - float t_minus_1 = 1-t01; - float sparkle = (pow(abs(sin(_Time.y * 3 + seed * 10)), 30)); - v.color.rgb += pow(t_minus_1,10)*incolor*200; - v.color.rgb += incolor * sparkle * 50; - -#ifdef AUDIO_REACTIVE - // Additional color boost from beat detection - v.color.rgb = v.color.rgb * .5 + 2*_BeatOutput.x * v.color.rgb; -#endif - - // Dim over lifetime - v.color.rgb *= incolor * pow (1 - t01, 2)*5; - - // Custom vertex animation -#if 1 - // Displacement is in scene space - // Note that xf_CS is actually scene, not canvas - // The problem with this is that if you scale up a layer, the particles - // get big but the overall motion stays the same. - float4 center_WS = mul(unity_ObjectToWorld, center); - center_WS.xyz += mul(xf_CS, float4(disp, 0)); - PrepForOdsWorldSpace(center_WS); - float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); - o.vertex = mul(UNITY_MATRIX_VP, corner_WS); -#else - // Displacement is in canvas space - // Note that we assume object space == canvas space (which it is, for TB) - PrepForOds(center); - center = center + float4(disp.xyz, 0); - float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); - o.vertex = UnityObjectToClipPos(corner); -#endif - - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - return o; - } - - // i.color is srgb - fixed4 frag (v2f i) : SV_Target - { - float4 texCol = tex2D(_MainTex, i.texcoord); - float4 color = 2.0f * i.color * _TintColor * texCol; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); -#if SELECTION_ON - color.rgb = GetSelectionColor() * texCol.a; -#endif - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/Embers" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _ScrollRate; + // In decimeters + float3 _ScrollDistance; + // Amplitude: in decimeters + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + float _SpreadRate; + + // pos and seed should be stable values. + // seed is a value in [0, 1] + // t01 is a time value in [0, 1] + float3 ComputeDisplacement(float3 pos, float seed, float t01) { + float t2 = GetTime().y; + float floatUpTime01 = t01; + +#if SELECTION_ON + t01 = 0; + t2 = 0; +#endif + + // Animate the motion of the embers + // Accumulate all displacement into a common, pre-transformed space. + float4 dispVec = float4(_ScrollDistance, 0.0) * t01; + + dispVec.x += sin(t01 * _ScrollJitterFrequency + seed * 100 + t2 + pos.z) * _ScrollJitterIntensity; + dispVec.y += (fmod(seed * 100, 1) - 0.5) * _ScrollDistance.y * floatUpTime01; + dispVec.z += cos(t01 * _ScrollJitterFrequency + seed * 100 + t2 + pos.x) * _ScrollJitterIntensity; + +#ifdef AUDIO_REACTIVE + float fft = (tex2Dlod(_FFTTex, float4(pos.y,0,0,0)).b)*2 + .1; + dispVec.y += fft; +#endif + +#if SELECTION_ON + dispVec.y = abs(dispVec.y * 0.2); + dispVec *= 0.5; +#endif + return dispVec * kDecimetersToWorldUnits; + } + + v2f vert (ParticleVertexWithSpread_t v) { + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + // Used as a random-ish seed for various calculations + float seed = v.color.a; + float t01 = fmod(GetTime().y*_ScrollRate + seed * 10, 1); + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float spreadProgress = SpreadProgress(birthTime, _SpreadRate); + float4 center = SpreadParticle(v, spreadProgress); + float3 disp = ComputeDisplacement(center.xyz, seed, t01); + disp = spreadProgress * disp; + + // Ramp color from bright to dark over particle lifetime + float3 incolor = v.color.rgb; + float t_minus_1 = 1-t01; + float sparkle = (pow(abs(sin(GetTime().y * 3 + seed * 10)), 30)); + v.color.rgb += pow(t_minus_1,10)*incolor*200; + v.color.rgb += incolor * sparkle * 50; + +#ifdef AUDIO_REACTIVE + // Additional color boost from beat detection + v.color.rgb = v.color.rgb * .5 + 2*_BeatOutput.x * v.color.rgb; +#endif + + // Dim over lifetime + v.color.rgb *= incolor * pow (1 - t01, 2)*5; + + // Custom vertex animation +#if 1 + // Displacement is in scene space + // Note that xf_CS is actually scene, not canvas + // The problem with this is that if you scale up a layer, the particles + // get big but the overall motion stays the same. + float4 center_WS = mul(unity_ObjectToWorld, center); + center_WS.xyz += mul(xf_CS, float4(disp, 0)); + PrepForOdsWorldSpace(center_WS); + float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); + o.vertex = mul(UNITY_MATRIX_VP, corner_WS); +#else + // Displacement is in canvas space + // Note that we assume object space == canvas space (which it is, for TB) + PrepForOds(center); + center = center + float4(disp.xyz, 0); + float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); + o.vertex = UnityObjectToClipPos(corner); +#endif + + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + o.id = (float2)v.id; + return o; + } + + // i.color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 texCol = tex2D(_MainTex, i.texcoord); + float4 color = 2.0f * i.color * _TintColor * texCol; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); +#if SELECTION_ON + color.rgb = GetSelectionColor() * texCol.a; +#endif + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/FacetedTube/FacetedTube.mat b/Assets/Resources/Brushes/Basic/FacetedTube/FacetedTube.mat index 8604ac5485..5569f3c309 100644 --- a/Assets/Resources/Brushes/Basic/FacetedTube/FacetedTube.mat +++ b/Assets/Resources/Brushes/Basic/FacetedTube/FacetedTube.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: FacetedTube m_Shader: {fileID: 4800000, guid: 387f4f61bc82c4e5f813ad7caa1f394a, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 5 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -27,11 +28,19 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: + - _ClipEnd: -1 + - _ClipStart: 0 - _Cutoff: 0.5 - _EmissionGain: 0.5 - _EmissionLM: 0 - _InvFade: 1 + - _Opacity: 1 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} + - _ColorX: {r: 1, g: 0, b: 0, a: 1} + - _ColorY: {r: 0, g: 1, b: 0, a: 1} + - _ColorZ: {r: 0, g: 0, b: 1, a: 1} - _TintColor: {r: 0.5441177, g: 0.16886412, b: 0, a: 0.5019608} + m_BuildTextureStacks: [] diff --git a/Assets/Resources/Brushes/Basic/Fire/Fire.shader b/Assets/Resources/Brushes/Basic/Fire/Fire.shader index dd9a74597e..7e321532a5 100644 --- a/Assets/Resources/Brushes/Basic/Fire/Fire.shader +++ b/Assets/Resources/Brushes/Basic/Fire/Fire.shader @@ -1,144 +1,166 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Fire" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _Scroll1 ("Scroll1", Float) = 0 - _Scroll2 ("Scroll2", Float) = 0 - _DisplacementIntensity("Displacement", Float) = .1 - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; -#if SHADER_TARGET >= 40 - centroid float2 texcoord : TEXCOORD0; -#else - float2 texcoord : TEXCOORD0; -#endif - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float4 color : COLOR; -#if SHADER_TARGET >= 40 - centroid float2 texcoord : TEXCOORD0; -#else - float2 texcoord : TEXCOORD0; -#endif - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - fixed _Scroll1; - fixed _Scroll2; - half _DisplacementIntensity; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = bloomColor(v.color, _EmissionGain); - o.pos = UnityObjectToClipPos(v.vertex); - o.worldPos = mul(unity_ObjectToWorld, v.vertex); - return o; - } - - // Note: input color is srgb - fixed4 frag (v2f i) : COLOR - { - half2 displacement; - float procedural_line = 0; -#ifdef AUDIO_REACTIVE - // Envelope - float envelope = sin(i.texcoord.x * 3.14159); - float envelopeHalf = sin(i.texcoord.x * 3.14159 * .5); - - // Basic fire effect - displacement = tex2D(_MainTex, i.texcoord + half2(-_Time.x * _Scroll1, 0) ).a; - - // Waveform fire effect - float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x * .2 + .025*i.worldPos.y,0)).g - .5f) + displacement*.05; - procedural_line = pow(abs(1 - abs((i.texcoord.y - .5) + waveform)), max(100 * i.texcoord.x, 0.001)); - - waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x * .3 + .034*i.worldPos.y,0)).w - .5f) + displacement*.02; - procedural_line += pow(abs(1 - abs((i.texcoord.y - .5) + waveform)), max(100 * i.texcoord.x, 0.001)); - - //procedural_line = saturate(1 - 10*abs(i.texcoord.y - .5 + waveform * envelopeHalf)); - //procedural_line = pow(procedural_line, i.texcoord.x* 10); - -#else - displacement = tex2D(_MainTex, i.texcoord + half2(-_Time.x * _Scroll1, 0) ).a; -#endif - - half4 tex = tex2D(_MainTex, i.texcoord + half2(-_Time.x * _Scroll2, 0) - displacement * _DisplacementIntensity); - tex.xyz *= step(0.01, tex.xyz); - -#ifdef AUDIO_REACTIVE - tex = tex * .5 + 2 * procedural_line * ( envelope * envelopeHalf); -#endif - float4 color = i.color * tex; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - FRAG_MOBILESELECT(color) - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Fire" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _Scroll1 ("Scroll1", Float) = 0 + _Scroll2 ("Scroll2", Float) = 0 + _DisplacementIntensity("Displacement", Float) = .1 + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; +#if SHADER_TARGET >= 40 + centroid float2 texcoord : TEXCOORD0; +#else + float2 texcoord : TEXCOORD0; +#endif + float3 worldPos : TEXCOORD1; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float4 color : COLOR; +#if SHADER_TARGET >= 40 + centroid float2 texcoord : TEXCOORD0; +#else + float2 texcoord : TEXCOORD0; +#endif + float3 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + fixed _Scroll1; + fixed _Scroll2; + half _DisplacementIntensity; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = bloomColor(v.color, _EmissionGain); + o.pos = UnityObjectToClipPos(v.vertex); + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.id = (float2)v.id; + return o; + } + + // Note: input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + half2 displacement; + float procedural_line = 0; +#ifdef AUDIO_REACTIVE + // Envelope + float envelope = sin(i.texcoord.x * 3.14159); + float envelopeHalf = sin(i.texcoord.x * 3.14159 * .5); + + // Basic fire effect + displacement = tex2D(_MainTex, i.texcoord + half2(-GetTime().x * _Scroll1, 0) ).a; + + // Waveform fire effect + float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x * .2 + .025*i.worldPos.y,0)).g - .5f) + displacement*.05; + procedural_line = pow(abs(1 - abs((i.texcoord.y - .5) + waveform)), max(100 * i.texcoord.x, 0.001)); + + waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x * .3 + .034*i.worldPos.y,0)).w - .5f) + displacement*.02; + procedural_line += pow(abs(1 - abs((i.texcoord.y - .5) + waveform)), max(100 * i.texcoord.x, 0.001)); + + //procedural_line = saturate(1 - 10*abs(i.texcoord.y - .5 + waveform * envelopeHalf)); + //procedural_line = pow(procedural_line, i.texcoord.x* 10); + +#else + displacement = tex2D(_MainTex, i.texcoord + half2(-GetTime().x * _Scroll1, 0) ).a; +#endif + + half4 tex = tex2D(_MainTex, i.texcoord + half2(-GetTime().x * _Scroll2, 0) - displacement * _DisplacementIntensity); + tex.xyz *= step(0.01, tex.xyz); + +#ifdef AUDIO_REACTIVE + tex = tex * .5 + 2 * procedural_line * ( envelope * envelopeHalf); +#endif + float4 color = i.color * tex; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Highlighter/AdditiveCutout.shader b/Assets/Resources/Brushes/Basic/Highlighter/AdditiveCutout.shader index d24a59f20f..8cac9ae8dc 100644 --- a/Assets/Resources/Brushes/Basic/Highlighter/AdditiveCutout.shader +++ b/Assets/Resources/Brushes/Basic/Highlighter/AdditiveCutout.shader @@ -1,92 +1,111 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/AdditiveCutout" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - uniform float _Cutoff; - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = TbVertToNative(v.color); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - half4 c = tex2D(_MainTex, i.texcoord ); - - // Cutoff the alpha value based on the incoming vertex alpha - i.color.a = (i.color.a * c.a < _Cutoff) ? 0 : 1; - - float4 col = i.color * float4(c.rgb,1); - FRAG_MOBILESELECT(col) - return col; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/AdditiveCutout" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + uniform float _Cutoff; + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = TbVertToNative(v.color); + o.id = v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + half4 c = tex2D(_MainTex, i.texcoord ); + + // Cutoff the alpha value based on the incoming vertex alpha + i.color.a = (i.color.a * c.a < _Cutoff) ? 0 : 1; + + float4 col = i.color * float4(c.rgb,1); + FRAG_MOBILESELECT(col) + col.a *= _Opacity; + return col; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/HyperGrid/HyperGrid.shader b/Assets/Resources/Brushes/Basic/HyperGrid/HyperGrid.shader index b0a2de014e..a9f74bf9ee 100644 --- a/Assets/Resources/Brushes/Basic/HyperGrid/HyperGrid.shader +++ b/Assets/Resources/Brushes/Basic/HyperGrid/HyperGrid.shader @@ -1,120 +1,144 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/HyperGrid" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma glsl - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 texcoord1 : TEXCOORD1; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - // Subtract out the Canvas space pose to keep the verts from popping around while - // transforming (e.g. apply quantization in an immutable space). - float4 worldPos = mul(unity_ObjectToWorld, v.vertex); - PrepForOdsWorldSpace(worldPos); - worldPos = mul(xf_I_CS, worldPos); - - float waveform = 0; - - float lifetime = _Time.y - v.texcoord1.w; - float size = length(v.texcoord1.xyz); - float release = saturate(lifetime); - -#ifdef AUDIO_REACTIVE - worldPos.y -= release * fmod(_BeatOutputAccum.x - v.texcoord1.w, 5); - worldPos.y += .3 * release * pow(sin(_BeatOutputAccum.x * 2 + worldPos.x),5); -#endif - // Quantize vertices - float q = (1.0f / size) * .5; - q += 5 * saturate(1- release*10); - float3 quantPos = ceil(worldPos.xyz * q) / q; - worldPos.xyz = quantPos; - worldPos = mul(xf_CS, worldPos); - o.pos = mul(UNITY_MATRIX_VP, worldPos); - - o.color = 2 * v.color + v.color.yzxw * _BeatOutput.x; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : SV_Target - { - float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); - c = encodeHdr(c.rgb * c.a); - c = SrgbToNative(c); - FRAG_MOBILESELECT(c) - return c; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/HyperGrid" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma glsl + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + // Subtract out the Canvas space pose to keep the verts from popping around while + // transforming (e.g. apply quantization in an immutable space). + float4 worldPos = mul(unity_ObjectToWorld, v.vertex); + PrepForOdsWorldSpace(worldPos); + worldPos = mul(xf_I_CS, worldPos); + + float waveform = 0; + + float lifetime = GetTime().y - v.texcoord1.w; + float size = length(v.texcoord1.xyz); + float release = saturate(lifetime); + +#ifdef AUDIO_REACTIVE + worldPos.y -= release * fmod(_BeatOutputAccum.x - v.texcoord1.w, 5); + worldPos.y += .3 * release * pow(sin(_BeatOutputAccum.x * 2 + worldPos.x),5); +#endif + // Quantize vertices + float q = (1.0f / size) * .5; + q += 5 * saturate(1- release*10); + float3 quantPos = ceil(worldPos.xyz * q) / q; + worldPos.xyz = quantPos; + worldPos = mul(xf_CS, worldPos); + o.pos = mul(UNITY_MATRIX_VP, worldPos); + + o.color = 2 * v.color + v.color.yzxw * _BeatOutput.x; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); + c = encodeHdr(c.rgb * c.a); + c = SrgbToNative(c); + FRAG_MOBILESELECT(c) + return c * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.mat b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.mat index d9690cfbb0..a1510751ed 100644 --- a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.mat +++ b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: HypercolorDoubleSided m_Shader: {fileID: 4800000, guid: 9a1f8894d4b051a43a120f0b237cd2f8, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 5 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -27,20 +28,29 @@ Material: m_Texture: {fileID: 2800000, guid: df7c592ef1f278543b4de38471df9994, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: + - _ClipEnd: -1 + - _ClipStart: 0 - _Cutoff: 0.5 - _DisplacementIntensity: 0.1 - _EmissionGain: 0.5 - _EmissionScroll1: 0 - _EmissionScroll2: 0 - _InvFade: 1 + - _Opacity: 1 + - _OverrideTime: 0 - _Scroll1: 20 - _Scroll2: 0 - _Shininess: 0.5 + - _TimeBlend: 0 + - _TimeSpeed: 1 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - _SpecColor: {r: 0.27450982, g: 0.27450982, b: 0.27450982, a: 1} + - _TimeOverrideValue: {r: 0, g: 0, b: 0, a: 0} - _TintColor: {r: 0.61764705, g: 0.61764705, b: 0.61764705, a: 1} + m_BuildTextureStacks: [] --- !u!1002 &2100001 EditorExtensionImpl: serializedVersion: 6 diff --git a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.shader b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.shader index e430b705de..670c89c349 100644 --- a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.shader +++ b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorDoubleSided.shader @@ -1,128 +1,152 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/HypercolorDoubleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - Cull Off - LOD 100 - - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct appdata { - float4 vertex : POSITION; - float3 texcoord : TEXCOORD0; - float3 texcoord1 : TEXCOORD1; - float3 texcoord2 : TEXCOORD2; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - float3 worldPos; - fixed vface : VFACE; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - fixed _Cutoff; - - void vert (inout appdata v, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - float t = 0.0; - - float strokeWidth = abs(v.texcoord.z) * 1.2; - -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.z * 5; - float waveIntensity = _BeatOutput.z * .1 * strokeWidth; - v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) - * cross(v.tangent.xyz, v.normal.xyz) - * waveIntensity) - ; -#endif - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - - float scroll = _Time.z; -#ifdef AUDIO_REACTIVE - float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; - float t = length(localPos) * .5; - scroll = _BeatOutputAccum.y*30; - float angle = atan2(localPos.x, localPos.y); - float waveform = tex2D(_WaveFormTex, float2(angle * 6,0)).g*2; - - tex.rgb = float3(1,0,0) * (sin(tex.r*2 + scroll*0.5 - t) + 1); - tex.rgb += float3(0,1,0) * (sin(tex.r*3 + scroll*1 - t) + 1); - tex.rgb += float3(0,0,1) * (sin(tex.r*4 + scroll*0.25 - t) + 1); -#else - tex.rgb = float3(1,0,0) * (sin(tex.r * 2 + scroll*0.5 - IN.uv_MainTex.x) + 1) * 2; - tex.rgb += float3(0,1,0) * (sin(tex.r * 3.3 + scroll*1 - IN.uv_MainTex.x) + 1) * 2; - tex.rgb += float3(0,0,1) * (sin(tex.r * 4.66 + scroll*0.25 - IN.uv_MainTex.x) + 1) * 2; -#endif - - o.Albedo = SrgbToNative(tex * IN.color).rgb; - o.Smoothness = _Shininess; - o.Specular = SrgbToNative(_SpecColor * tex).rgb; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Alpha = tex.a * IN.color.a; - if (o.Alpha < _Cutoff) { - discard; - } - o.Alpha = 1; -#ifdef AUDIO_REACTIVE - o.Emission = o.Albedo; - o.Albedo = .2; - o.Specular *= .5; -#endif - SURF_FRAG_MOBILESELECT(o); - o.Normal.z *= IN.vface; - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} - - - +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/HypercolorDoubleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + Cull Off + LOD 100 + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct appdata { + float4 vertex : POSITION; + float3 texcoord : TEXCOORD0; + float3 texcoord1 : TEXCOORD1; + float3 texcoord2 : TEXCOORD2; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + float3 worldPos; + fixed vface : VFACE; + uint id : TEXCOORD2; + float4 screenPos; + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + fixed _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert (inout appdata v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + float t = 0.0; + + float strokeWidth = abs(v.texcoord.z) * 1.2; + +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.z * 5; + float waveIntensity = _BeatOutput.z * .1 * strokeWidth; + v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) + * cross(v.tangent.xyz, v.normal.xyz) + * waveIntensity) + ; +#endif + o.id = v.id; + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + + float scroll = GetTime().z; +#ifdef AUDIO_REACTIVE + float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; + float t = length(localPos) * .5; + scroll = _BeatOutputAccum.y*30; + float angle = atan2(localPos.x, localPos.y); + float waveform = tex2D(_WaveFormTex, float2(angle * 6,0)).g*2; + + tex.rgb = float3(1,0,0) * (sin(tex.r*2 + scroll*0.5 - t) + 1); + tex.rgb += float3(0,1,0) * (sin(tex.r*3 + scroll*1 - t) + 1); + tex.rgb += float3(0,0,1) * (sin(tex.r*4 + scroll*0.25 - t) + 1); +#else + tex.rgb = float3(1,0,0) * (sin(tex.r * 2 + scroll*0.5 - IN.uv_MainTex.x) + 1) * 2; + tex.rgb += float3(0,1,0) * (sin(tex.r * 3.3 + scroll*1 - IN.uv_MainTex.x) + 1) * 2; + tex.rgb += float3(0,0,1) * (sin(tex.r * 4.66 + scroll*0.25 - IN.uv_MainTex.x) + 1) * 2; +#endif + + o.Albedo = SrgbToNative(tex * IN.color).rgb; + o.Smoothness = _Shininess; + o.Specular = SrgbToNative(_SpecColor * tex).rgb; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Alpha = tex.a * IN.color.a; + if (o.Alpha < _Cutoff) { + discard; + } + o.Alpha = 1; +#ifdef AUDIO_REACTIVE + o.Emission = o.Albedo; + o.Albedo = .2; + o.Specular *= .5; +#endif + SURF_FRAG_MOBILESELECT(o); + o.Normal.z *= IN.vface; + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} + + + diff --git a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorSingleSided.shader b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorSingleSided.shader index b9a261f417..162b4c11fb 100644 --- a/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorSingleSided.shader +++ b/Assets/Resources/Brushes/Basic/Hypercolor/HypercolorSingleSided.shader @@ -1,105 +1,111 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/HypercolorSingleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - Cull Back - LOD 100 - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - float3 worldPos; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full v) { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - float t = 0.0; - - float strokeWidth = abs(v.texcoord.z) * 1.2; - -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.z * 5; - float waveIntensity = _BeatOutput.z * .1 * strokeWidth; - v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) - * cross(v.tangent.xyz, v.normal.xyz) - * waveIntensity) - ; -#endif - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - - float scroll = _Time.z; -#ifdef AUDIO_REACTIVE - float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; - float t = length(localPos) * .5; - scroll = _BeatOutputAccum.y*30; - float angle = atan2(localPos.x, localPos.y); - float waveform = tex2D(_WaveFormTex, float2(angle * 6,0)).g*2; - - tex.rgb = float3(1,0,0) * (sin(tex.r*2 + scroll*0.5 - t) + 1); - tex.rgb += float3(0,1,0) * (sin(tex.r*3 + scroll*1 - t) + 1); - tex.rgb += float3(0,0,1) * (sin(tex.r*4 + scroll*0.25 - t) + 1); -#else - tex.rgb = float3(1,0,0) * (sin(tex.r * 2 + scroll*0.5 - IN.uv_MainTex.x) + 1) * 2; - tex.rgb += float3(0,1,0) * (sin(tex.r * 3.3 + scroll*1 - IN.uv_MainTex.x) + 1) * 2; - tex.rgb += float3(0,0,1) * (sin(tex.r * 4.66 + scroll*0.25 - IN.uv_MainTex.x) + 1) * 2; -#endif - - o.Albedo = SrgbToNative(tex * IN.color).rgb; - o.Smoothness = _Shininess; - o.Specular = SrgbToNative(_SpecColor * tex).rgb; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Alpha = tex.a * IN.color.a; -#ifdef AUDIO_REACTIVE - o.Emission = o.Albedo; - o.Albedo = .2; - o.Specular *= .5; -#endif - - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} - - - +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/HypercolorSingleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 +} + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + Cull Back + LOD 100 + + CGPROGRAM + #pragma target 3.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + float3 worldPos; + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + + void vert (inout appdata_full v) { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + float t = 0.0; + + float strokeWidth = abs(v.texcoord.z) * 1.2; + +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.z * 5; + float waveIntensity = _BeatOutput.z * .1 * strokeWidth; + v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) + * cross(v.tangent.xyz, v.normal.xyz) + * waveIntensity) + ; +#endif + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + + float scroll = GetTime().z; +#ifdef AUDIO_REACTIVE + float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; + float t = length(localPos) * .5; + scroll = _BeatOutputAccum.y*30; + float angle = atan2(localPos.x, localPos.y); + float waveform = tex2D(_WaveFormTex, float2(angle * 6,0)).g*2; + + tex.rgb = float3(1,0,0) * (sin(tex.r*2 + scroll*0.5 - t) + 1); + tex.rgb += float3(0,1,0) * (sin(tex.r*3 + scroll*1 - t) + 1); + tex.rgb += float3(0,0,1) * (sin(tex.r*4 + scroll*0.25 - t) + 1); +#else + tex.rgb = float3(1,0,0) * (sin(tex.r * 2 + scroll*0.5 - IN.uv_MainTex.x) + 1) * 2; + tex.rgb += float3(0,1,0) * (sin(tex.r * 3.3 + scroll*1 - IN.uv_MainTex.x) + 1) * 2; + tex.rgb += float3(0,0,1) * (sin(tex.r * 4.66 + scroll*0.25 - IN.uv_MainTex.x) + 1) * 2; +#endif + + o.Albedo = SrgbToNative(tex * IN.color).rgb; + o.Smoothness = _Shininess; + o.Specular = SrgbToNative(_SpecColor * tex).rgb; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Alpha = tex.a * IN.color.a; +#ifdef AUDIO_REACTIVE + o.Emission = o.Albedo; + o.Albedo = .2; + o.Specular *= .5; +#endif + + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} + + + diff --git a/Assets/Resources/Brushes/Basic/LightWire/LightWire.shader b/Assets/Resources/Brushes/Basic/LightWire/LightWire.shader index c186809a17..59d127e8a1 100644 --- a/Assets/Resources/Brushes/Basic/LightWire/LightWire.shader +++ b/Assets/Resources/Brushes/Basic/LightWire/LightWire.shader @@ -1,111 +1,148 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/LightWire" { - Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - } - SubShader { - Cull Back - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert noshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct Input { - float2 uv_MainTex; - float4 color : Color; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full v, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - // Radius is stored in texcoord (used to be tangent.w) - float radius = v.texcoord.z; - - float t; - float envelope = sin ( fmod ( v.texcoord.x * 2, 1.0f) * 3.14159); - float lights = envelope < .15 ? 1 : 0; - - radius *= 0.9; - v.vertex.xyz += v.normal * lights * radius; - } - - float3 SrgbToNative3(float3 color) { - return SrgbToNative(float4(color, 1)).rgb; - } - - // Input color is srgb - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - float envelope = sin ( fmod ( IN.uv_MainTex.x*2, 1.0f) * 3.14159); - float lights = envelope < .1 ? 1 : 0; - float border = abs(envelope - .1) < .01 ? 0 : 1; - o.Specular = .3 - lights * .15; - o.Smoothness = .3 + lights * .3; - - float t; -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.x*10; -#else - t = _Time.w; -#endif - - if (lights) { - int colorindex = fmod(IN.uv_MainTex.x*2 + 0.5, 3); - if (colorindex == 0) IN.color.rgb = IN.color.rgb * float3(.2,.2,1); - else if (colorindex == 1) IN.color.rgb = IN.color.rgb * float3(1,.2,.2); - else IN.color.rgb = IN.color.rgb * float3(.2,1,.2); - - float lightindex = fmod(IN.uv_MainTex.x*2 + .5,7); - float timeindex = fmod(t, 7); - float delta = abs(lightindex - timeindex); - float on = 1 - saturate(delta*1.5); - IN.color = bloomColor(IN.color * on, .7); - } - - o.Albedo = (1-lights) * IN.color.rgb * .2; - o.Albedo *= border; - o.Specular *= border; - -#ifdef AUDIO_REACTIVE - IN.color.rgb = IN.color.rgb * .25 + IN.color.rgb*_BeatOutput.x * .75; -#endif - o.Emission += lights * IN.color.rgb; - - o.Albedo = SrgbToNative3(o.Albedo); - o.Emission = SrgbToNative3(o.Emission); - o.Specular = SrgbToNative3(o.Specular); - - SURF_FRAG_MOBILESELECT(o); - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/LightWire" { + Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader { + Cull Back + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert noshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct Input { + float2 uv_MainTex; + float4 color : Color; + float2 id : TEXCOORD2; + float4 screenPos; + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + // Radius is stored in texcoord (used to be tangent.w) + float radius = v.texcoord.z; + + float t; + float envelope = sin ( fmod ( v.texcoord.x * 2, 1.0f) * 3.14159); + float lights = envelope < .15 ? 1 : 0; + + radius *= 0.9; + v.vertex.xyz += v.normal * lights * radius; + o.id = (float2)v.id; + } + + float3 SrgbToNative3(float3 color) { + return SrgbToNative(float4(color, 1)).rgb; + } + + // Input color is srgb + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + float envelope = sin ( fmod ( IN.uv_MainTex.x*2, 1.0f) * 3.14159); + float lights = envelope < .1 ? 1 : 0; + float border = abs(envelope - .1) < .01 ? 0 : 1; + o.Specular = .3 - lights * .15; + o.Smoothness = .3 + lights * .3; + + float t; +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.x*10; +#else + t = GetTime().w; +#endif + + if (lights) { + int colorindex = fmod(IN.uv_MainTex.x*2 + 0.5, 3); + if (colorindex == 0) IN.color.rgb = IN.color.rgb * float3(.2,.2,1); + else if (colorindex == 1) IN.color.rgb = IN.color.rgb * float3(1,.2,.2); + else IN.color.rgb = IN.color.rgb * float3(.2,1,.2); + + float lightindex = fmod(IN.uv_MainTex.x*2 + .5,7); + float timeindex = fmod(t, 7); + float delta = abs(lightindex - timeindex); + float on = 1 - saturate(delta*1.5); + IN.color = bloomColor(IN.color * on, .7); + } + + o.Albedo = (1-lights) * IN.color.rgb * .2; + o.Albedo *= border; + o.Specular *= border; + +#ifdef AUDIO_REACTIVE + IN.color.rgb = IN.color.rgb * .25 + IN.color.rgb*_BeatOutput.x * .75; +#endif + o.Emission += lights * IN.color.rgb; + + o.Albedo = SrgbToNative3(o.Albedo); + o.Emission = SrgbToNative3(o.Emission); + o.Specular = SrgbToNative3(o.Specular); + + SURF_FRAG_MOBILESELECT(o); + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Basic/Petal/Petal.shader b/Assets/Resources/Brushes/Basic/Petal/Petal.shader index 53087863e0..59b4765ab4 100644 --- a/Assets/Resources/Brushes/Basic/Petal/Petal.shader +++ b/Assets/Resources/Brushes/Basic/Petal/Petal.shader @@ -1,64 +1,95 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Petal" { - Properties{ - _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess("Shininess", Range(0.01, 1)) = 0.3 - _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - } - SubShader{ - Tags {"IgnoreProjector" = "True" "RenderType" = "Opaque"} - Cull Off - - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct Input { - float2 uv_MainTex; - float4 color : Color; - fixed vface : VFACE; - }; - - half _Shininess; - - void vert(inout appdata_full i, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(i.vertex); - i.color = TbVertToNative(i.color); - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - // Fade from center outward (dark to light) - float4 darker_color = IN.color; - darker_color *= 0.6; - float4 finalColor = lerp(IN.color, darker_color, 1- IN.uv_MainTex.x); - - float fAO = IN.vface == -1 ? .5 * IN.uv_MainTex.x : 1; - o.Albedo = finalColor * fAO; - o.Smoothness = _Shininess; - o.Specular = _SpecColor * fAO; - o.Alpha = 1; - - SURF_FRAG_MOBILESELECT(o); - } - ENDCG - } -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Petal" { + Properties{ + _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess("Shininess", Range(0.01, 1)) = 0.3 + _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader{ + Tags {"IgnoreProjector" = "True" "RenderType" = "Opaque"} + Cull Off + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER + #pragma multi_compile __ SELECTION_ON + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct Input { + float2 uv_MainTex; + float4 color : Color; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 screenPos; + }; + + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(i.vertex); + i.color = TbVertToNative(i.color); + o.id = i.id; + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + // Fade from center outward (dark to light) + float4 darker_color = IN.color; + darker_color *= 0.6; + float4 finalColor = lerp(IN.color, darker_color, 1- IN.uv_MainTex.x); + + float fAO = IN.vface == -1 ? .5 * IN.uv_MainTex.x : 1; + o.Albedo = finalColor * fAO; + o.Smoothness = _Shininess; + o.Specular = _SpecColor * fAO; + o.Alpha = 1; + + SURF_FRAG_MOBILESELECT(o); + } + ENDCG + } +} diff --git a/Assets/Resources/Brushes/Basic/Plasma/Plasma.shader b/Assets/Resources/Brushes/Basic/Plasma/Plasma.shader index d1f3415744..296ad1c1d7 100644 --- a/Assets/Resources/Brushes/Basic/Plasma/Plasma.shader +++ b/Assets/Resources/Brushes/Basic/Plasma/Plasma.shader @@ -1,160 +1,184 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Plasma" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - - _Scroll1 ("Scroll1", Float) = 0 - _Scroll2 ("Scroll2", Float) = 0 - _EmissionScroll1 ("Emission Scroll1", Float) = 0 - _EmissionScroll2 ("Emission Scroll2", Float) = 0 - - _DisplacementIntensity("Displacement", Float) = .1 - - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One //SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ SELECTION_ON - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - fixed _Scroll1; - fixed _Scroll2; - fixed _EmissionScroll1; - fixed _EmissionScroll2; - half _DisplacementIntensity; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.worldPos = mul(unity_ObjectToWorld, v.vertex); - o.vertex = UnityObjectToClipPos(v.vertex); - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - return o; - } - - float rand_1_05(in float2 uv) - { - float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); - return abs(noise.x + noise.y) * 0.5; - } - - fixed4 frag (v2f i) : COLOR - { - // Workaround for b/30500118, caused by b/30504121 - i.color.a = saturate(i.color.a); - - // Tuning constants for 3 lines - half3 A = half3(0.55, 0.3, 0.7 ); - half3 aRate = half3(1.2 , 1.0, 1.33); - half3 M = half3(1.0 , 2.2, 1.5); // kind of a multiplier on A's values - half3 bRate = half3(1.5 , 3.0, 2.25) + M * aRate; - half3 LINE_POS = 0.5; - half3 LINE_WIDTH = .012; - -#ifdef AUDIO_REACTIVE - float waveformcoord = i.texcoord.x * .2f; - float envelope = sin(3.14159 * waveformcoord); - float waveform = (tex2D(_WaveFormTex, float2(waveformcoord,0)).r - .5f); - i.texcoord.y += waveform * envelope * .5f; -#endif - - // Calculate uvs for each line - half3 us, vs; - { - us = A * i.texcoord.x - aRate * _Time.y; - - half3 tmp = M*A * i.texcoord.x - bRate * _Time.y; - tmp = abs(frac(tmp) - 0.5); - vs = i.texcoord.y + .4 * i.color.a * half3(1,-1,1) * tmp; - vs = saturate(lerp((vs - .5) * 4, vs, sin( (3.14159/2) * i.color.a))); - } - - half4 tex = tex2D(_MainTex, half2(us[0], vs[0])); - tex += tex2D(_MainTex, half2(us[1], vs[1])); - tex += tex2D(_MainTex, half2(us[2], vs[2])); - - // render 3 procedural lines - half3 procline = 1 - saturate(pow((vs - LINE_POS)/LINE_WIDTH, 2)); - tex += dot(procline, half3(1,1,1)); - - // adjust brightness; modulate by color - tex *= .8 * (1 + 30 * pow((1 - i.color.a), 5)); - i.color.a = 1; // kill any other alpha values that may come into this brush - - float4 c = i.color * tex; -#if SELECTION_ON - c.rgb = GetSelectionColor() * tex; -#endif - return encodeHdr(c.rgb * c.a); - } - - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Plasma" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + + _Scroll1 ("Scroll1", Float) = 0 + _Scroll2 ("Scroll2", Float) = 0 + _EmissionScroll1 ("Emission Scroll1", Float) = 0 + _EmissionScroll2 ("Emission Scroll2", Float) = 0 + + _DisplacementIntensity("Displacement", Float) = .1 + + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One //SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ SELECTION_ON + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float3 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + fixed _Scroll1; + fixed _Scroll2; + fixed _EmissionScroll1; + fixed _EmissionScroll2; + half _DisplacementIntensity; + half _EmissionGain; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.vertex = UnityObjectToClipPos(v.vertex); + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.id = (float2)v.id; + return o; + } + + float rand_1_05(in float2 uv) + { + float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); + return abs(noise.x + noise.y) * 0.5; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // Workaround for b/30500118, caused by b/30504121 + i.color.a = saturate(i.color.a); + + // Tuning constants for 3 lines + half3 A = half3(0.55, 0.3, 0.7 ); + half3 aRate = half3(1.2 , 1.0, 1.33); + half3 M = half3(1.0 , 2.2, 1.5); // kind of a multiplier on A's values + half3 bRate = half3(1.5 , 3.0, 2.25) + M * aRate; + half3 LINE_POS = 0.5; + half3 LINE_WIDTH = .012; + +#ifdef AUDIO_REACTIVE + float waveformcoord = i.texcoord.x * .2f; + float envelope = sin(3.14159 * waveformcoord); + float waveform = (tex2D(_WaveFormTex, float2(waveformcoord,0)).r - .5f); + i.texcoord.y += waveform * envelope * .5f; +#endif + + // Calculate uvs for each line + half3 us, vs; + { + us = A * i.texcoord.x - aRate * GetTime().y; + + half3 tmp = M*A * i.texcoord.x - bRate * GetTime().y; + tmp = abs(frac(tmp) - 0.5); + vs = i.texcoord.y + .4 * i.color.a * half3(1,-1,1) * tmp; + vs = saturate(lerp((vs - .5) * 4, vs, sin( (3.14159/2) * i.color.a))); + } + + half4 tex = tex2D(_MainTex, half2(us[0], vs[0])); + tex += tex2D(_MainTex, half2(us[1], vs[1])); + tex += tex2D(_MainTex, half2(us[2], vs[2])); + + // render 3 procedural lines + half3 procline = 1 - saturate(pow((vs - LINE_POS)/LINE_WIDTH, 2)); + tex += dot(procline, half3(1,1,1)); + + // adjust brightness; modulate by color + tex *= .8 * (1 + 30 * pow((1 - i.color.a), 5)); + i.color.a = 1; // kill any other alpha values that may come into this brush + + float4 c = i.color * tex; +#if SELECTION_ON + c.rgb = GetSelectionColor() * tex; +#endif + float4 color = encodeHdr(c.rgb * c.a); + return color * _Opacity; + } + + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Rainbow/Rainbow.shader b/Assets/Resources/Brushes/Basic/Rainbow/Rainbow.shader index f79f60beaa..97d90db468 100644 --- a/Assets/Resources/Brushes/Basic/Rainbow/Rainbow.shader +++ b/Assets/Resources/Brushes/Basic/Rainbow/Rainbow.shader @@ -1,218 +1,241 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Rainbow" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - // Split into two different LOD passes as the 200 lod (mobile) needs to use a different - // blend mode than standard. - CGINCLUDE - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #pragma target 3.0 - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - float4 GetRainbowColor( half2 texcoord) - { - texcoord = saturate(texcoord); - // Create parametric UV's - half2 uvs = texcoord; - float row_id = floor(uvs.y * 5); - uvs.y *= 5; - - // Create parametric colors - half4 tex = float4(0,0,0,1); - half row_y = fmod(uvs.y,1); - - float time = frac( _Time.z * 0.2 ) * 5; - float rowOffset = floor( time ); - - row_id += rowOffset; - row_id = floor(fmod( row_id, 5) + 0.1); - - tex.rgb = row_id == 0 ? float3(1,0,0) : tex.rgb; - tex.rgb = row_id == 1 ? float3(.7,.3,0) : tex.rgb; - tex.rgb = row_id == 2 ? float3(0,1,.0) : tex.rgb; - tex.rgb = row_id == 3 ? float3(0,.2,1) : tex.rgb; - tex.rgb = row_id == 4 ? float3(.4,0,1.2) : tex.rgb; - - // Make rainbow lines pulse - tex.rgb *= pow( (sin(row_id * 1 + _Time.z) + 1)/2,5); - - // Make rainbow lines thin - tex.rgb *= saturate(pow(row_y * (1 - row_y) * 5, 50)); - - return tex; - } - - float4 GetAudioReactiveRainbowColor( half2 texcoord) - { - texcoord = saturate(texcoord); - // Create parametric UV's - half2 uvs = texcoord; - float row_id = floor(uvs.y * 5); - uvs.y *= 5; - - // Create parametric colors - half4 tex = float4(0,0,0,1); - half row_y = fmod(uvs.y,1); - - row_id = ceil(fmod(row_id + _BeatOutputAccum.x*3,5)) - 1; - - tex.rgb = row_id == 0 ? float3(1,0,0) : tex.rgb; - tex.rgb = row_id == 1 ? float3(.7,.3,0) : tex.rgb; - tex.rgb = row_id == 2 ? float3(0,1,.0) : tex.rgb; - tex.rgb = row_id == 3 ? float3(0,.2,1) : tex.rgb; - tex.rgb = row_id == 4 ? float3(.4,0,1.2) : tex.rgb; - - // Make rainbow lines pulse - // tex.rgb *= pow( (sin(row_id * 1 + _BeatOutputAccum.x*10) + 1)/2,5); - - // Make rainbow lines thin - tex.rgb *= saturate(pow(row_y * (1 - row_y) * 5, 50)); - - return tex; - } - - float4 GetAudioReactiveColor( half2 texcoord) - { - texcoord = texcoord.yx; - texcoord.y *= 2; - - // Create parametric UV's - float quantizedMotion = ceil((_BeatOutputAccum.z*.1) / 10); - float row_id = abs(texcoord.y * 12 + quantizedMotion); - - // Create parametric colors - float4 tex = float4(0,0,0,1); - float row_y = fmod(abs(row_id),1.0); - - row_id = ceil(fmod(row_id, 8)); - - float bandlevels = tex2D(_FFTTex, float2(row_id/8,0) ).w; - bandlevels = max(bandlevels, .1); - tex.rgb = abs(texcoord.x - .5) < bandlevels * .5 ? float3(1,1,1) : tex.rgb; - - // Make rainbow lines pulse - tex.rgb *= tex.rgb * .5 + tex.rgb * _BeatOutput.y; - - // Make rainbow lines thin - tex.rgb *= saturate(20 - abs(row_y - .5)*50); - return tex; - } - - - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - i.color.a = 1; //ignore incoming vert alpha -#ifdef AUDIO_REACTIVE - float4 tex = GetAudioReactiveRainbowColor(i.texcoord.xy); - tex *= GetAudioReactiveColor(i.texcoord.xy); - tex = i.color * tex * exp(_EmissionGain * 2.5f); -#else - float4 tex = GetRainbowColor(i.texcoord.xy); - tex = i.color * tex * exp(_EmissionGain * 3.0f); -#endif - float4 color = encodeHdr(tex.rgb * tex.a); - color = SrgbToNative(color); - FRAG_MOBILESELECT(color) - return color; - } - - - ENDCG - - // PC (Uses 'Add' blend mode for RGB) - SubShader { - LOD 201 - Pass { - BlendOp Add, Min - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - ENDCG - } - } - - // Mobile (Uses 'Max' blend mode for RGB) - SubShader { - LOD 150 - Pass { - BlendOp Max, Min - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Rainbow" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + // Split into two different LOD passes as the 200 lod (mobile) needs to use a different + // blend mode than standard. + CGINCLUDE + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + float4 GetRainbowColor( half2 texcoord) + { + texcoord = saturate(texcoord); + // Create parametric UV's + half2 uvs = texcoord; + float row_id = floor(uvs.y * 5); + uvs.y *= 5; + + // Create parametric colors + half4 tex = float4(0,0,0,1); + half row_y = fmod(uvs.y,1); + + float time = frac( GetTime().z * 0.2 ) * 5; + float rowOffset = floor( time ); + + row_id += rowOffset; + row_id = floor(fmod( row_id, 5) + 0.1); + + tex.rgb = row_id == 0 ? float3(1,0,0) : tex.rgb; + tex.rgb = row_id == 1 ? float3(.7,.3,0) : tex.rgb; + tex.rgb = row_id == 2 ? float3(0,1,.0) : tex.rgb; + tex.rgb = row_id == 3 ? float3(0,.2,1) : tex.rgb; + tex.rgb = row_id == 4 ? float3(.4,0,1.2) : tex.rgb; + + // Make rainbow lines pulse + tex.rgb *= pow( (sin(row_id * 1 + GetTime().z) + 1)/2,5); + + // Make rainbow lines thin + tex.rgb *= saturate(pow(row_y * (1 - row_y) * 5, 50)); + + return tex; + } + + float4 GetAudioReactiveRainbowColor( half2 texcoord) + { + texcoord = saturate(texcoord); + // Create parametric UV's + half2 uvs = texcoord; + float row_id = floor(uvs.y * 5); + uvs.y *= 5; + + // Create parametric colors + half4 tex = float4(0,0,0,1); + half row_y = fmod(uvs.y,1); + + row_id = ceil(fmod(row_id + _BeatOutputAccum.x*3,5)) - 1; + + tex.rgb = row_id == 0 ? float3(1,0,0) : tex.rgb; + tex.rgb = row_id == 1 ? float3(.7,.3,0) : tex.rgb; + tex.rgb = row_id == 2 ? float3(0,1,.0) : tex.rgb; + tex.rgb = row_id == 3 ? float3(0,.2,1) : tex.rgb; + tex.rgb = row_id == 4 ? float3(.4,0,1.2) : tex.rgb; + + // Make rainbow lines pulse + // tex.rgb *= pow( (sin(row_id * 1 + _BeatOutputAccum.x*10) + 1)/2,5); + + // Make rainbow lines thin + tex.rgb *= saturate(pow(row_y * (1 - row_y) * 5, 50)); + + return tex; + } + + float4 GetAudioReactiveColor( half2 texcoord) + { + texcoord = texcoord.yx; + texcoord.y *= 2; + + // Create parametric UV's + float quantizedMotion = ceil((_BeatOutputAccum.z*.1) / 10); + float row_id = abs(texcoord.y * 12 + quantizedMotion); + + // Create parametric colors + float4 tex = float4(0,0,0,1); + float row_y = fmod(abs(row_id),1.0); + + row_id = ceil(fmod(row_id, 8)); + + float bandlevels = tex2D(_FFTTex, float2(row_id/8,0) ).w; + bandlevels = max(bandlevels, .1); + tex.rgb = abs(texcoord.x - .5) < bandlevels * .5 ? float3(1,1,1) : tex.rgb; + + // Make rainbow lines pulse + tex.rgb *= tex.rgb * .5 + tex.rgb * _BeatOutput.y; + + // Make rainbow lines thin + tex.rgb *= saturate(20 - abs(row_y - .5)*50); + return tex; + } + + + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + i.color.a = 1; //ignore incoming vert alpha +#ifdef AUDIO_REACTIVE + float4 tex = GetAudioReactiveRainbowColor(i.texcoord.xy); + tex *= GetAudioReactiveColor(i.texcoord.xy); + tex = i.color * tex * exp(_EmissionGain * 2.5f); +#else + float4 tex = GetRainbowColor(i.texcoord.xy); + tex = i.color * tex * exp(_EmissionGain * 3.0f); +#endif + float4 color = encodeHdr(tex.rgb * tex.a); + color = SrgbToNative(color); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + + + ENDCG + + // PC (Uses 'Add' blend mode for RGB) + SubShader { + LOD 201 + Pass { + BlendOp Add, Min + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } + + // Mobile (Uses 'Max' blend mode for RGB) + SubShader { + LOD 150 + Pass { + BlendOp Max, Min + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Smoke/Smoke.shader b/Assets/Resources/Brushes/Basic/Smoke/Smoke.shader index 7d617ff37e..74887e3e73 100644 --- a/Assets/Resources/Brushes/Basic/Smoke/Smoke.shader +++ b/Assets/Resources/Brushes/Basic/Smoke/Smoke.shader @@ -1,136 +1,159 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/Smoke" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma target 3.0 - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 pos : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _ScrollRate; - - // - // Functions for line/plane distances. Experimental. - // - float dist_from_line(float3 line_dir, float3 point_on_line, float3 pos) { - float3 point_to_line = pos - point_on_line; - float3 dist_along_line = dot(point_to_line, line_dir); - float3 closest_point_on_line = dist_along_line * line_dir + point_on_line; - return length(closest_point_on_line - pos); - } - - float dist_from_line_repeating(float3 line_dir, float3 point_on_line, float3 pos) { - float3 point_to_line = pos - point_on_line; - float3 dist_along_line = dot(point_to_line, line_dir); - float3 closest_point_on_line = dist_along_line * line_dir + point_on_line; - return length( sin(closest_point_on_line - pos)); - } - - float4 dist_from_plane(float3 plane_normal, float3 point_on_plane, float3 pos) { - float dist = dot(plane_normal, pos - point_on_plane); - float3 closest_point_on_plane = pos - dist * plane_normal; - return float4(closest_point_on_plane.xyz, abs(dist)); - } - - v2f vert (ParticleVertex_t v) - { - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float4 center = float4(v.center.xyz, 1); - float4 center_WS = mul(unity_ObjectToWorld, center); - - float t = _Time.y*_ScrollRate + v.color.a * 10; - float time = _Time.x * 5; - float d = 30; - float freq = .1; - float3 disp = float3(1,0,0) * curlX(center_WS.xyz * freq + time, d); - disp += float3(0,1,0) * curlY(center_WS.xyz * freq +time, d); - disp += float3(0,0,1) * curlZ(center_WS.xyz * freq + time, d); - disp = disp * 5 * kDecimetersToWorldUnits; - - center_WS.xyz += mul(xf_CS, float4(disp, 0)); - - PrepForOdsWorldSpace(center_WS); - float4 corner = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); - o.pos = mul(UNITY_MATRIX_VP, corner); - - o.color = v.color; - v.color.a = 1; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - - return o; - } - - fixed4 frag (v2f i) : SV_Target - { - float4 c = tex2D(_MainTex, i.texcoord); - c *= i.color * _TintColor; - c = SrgbToNative(c); -#if SELECTION_ON - float strength = length(c.rgb * c.a) * 3; - FRAG_MOBILESELECT(c) - c.rgb *= strength; -#endif - return c; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/Smoke" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma target 3.0 + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + struct v2f { + float4 pos : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _ScrollRate; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + // + // Functions for line/plane distances. Experimental. + // + float dist_from_line(float3 line_dir, float3 point_on_line, float3 pos) { + float3 point_to_line = pos - point_on_line; + float3 dist_along_line = dot(point_to_line, line_dir); + float3 closest_point_on_line = dist_along_line * line_dir + point_on_line; + return length(closest_point_on_line - pos); + } + + float dist_from_line_repeating(float3 line_dir, float3 point_on_line, float3 pos) { + float3 point_to_line = pos - point_on_line; + float3 dist_along_line = dot(point_to_line, line_dir); + float3 closest_point_on_line = dist_along_line * line_dir + point_on_line; + return length( sin(closest_point_on_line - pos)); + } + + float4 dist_from_plane(float3 plane_normal, float3 point_on_plane, float3 pos) { + float dist = dot(plane_normal, pos - point_on_plane); + float3 closest_point_on_plane = pos - dist * plane_normal; + return float4(closest_point_on_plane.xyz, abs(dist)); + } + + v2f vert (ParticleVertex_t v) + { + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float4 center = float4(v.center.xyz, 1); + float4 center_WS = mul(unity_ObjectToWorld, center); + + float t = GetTime().y*_ScrollRate + v.color.a * 10; + float time = GetTime().x * 5; + float d = 30; + float freq = .1; + float3 disp = float3(1,0,0) * curlX(center_WS.xyz * freq + time, d); + disp += float3(0,1,0) * curlY(center_WS.xyz * freq +time, d); + disp += float3(0,0,1) * curlZ(center_WS.xyz * freq + time, d); + disp = disp * 5 * kDecimetersToWorldUnits; + + center_WS.xyz += mul(xf_CS, float4(disp, 0)); + + PrepForOdsWorldSpace(center_WS); + float4 corner = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); + o.pos = mul(UNITY_MATRIX_VP, corner); + + o.color = v.color; + v.color.a = 1; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + o.id = (float2)v.id; + + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + float4 c = tex2D(_MainTex, i.texcoord); + c *= i.color * _TintColor; + c = SrgbToNative(c); +#if SELECTION_ON + float strength = length(c.rgb * c.a) * 3; + FRAG_MOBILESELECT(c) + c.rgb *= strength; +#endif + c.a *= _Opacity; + return c; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Snow/Snow.shader b/Assets/Resources/Brushes/Basic/Snow/Snow.shader index 8a6df60fcb..f45587a3cd 100644 --- a/Assets/Resources/Brushes/Basic/Snow/Snow.shader +++ b/Assets/Resources/Brushes/Basic/Snow/Snow.shader @@ -1,124 +1,147 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/Snow" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 - _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _ScrollRate; - float3 _ScrollDistance; - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - float _SpreadRate; - - v2f vert (ParticleVertexWithSpread_t v) - { - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - v.color = TbVertToSrgb(v.color); - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float spreadProgress = SpreadProgress(birthTime, _SpreadRate); - float4 center = SpreadParticle(v, spreadProgress); - float4 center_WS = mul(unity_ObjectToWorld, center); - - // Custom vertex animation - float scrollAmount = _Time.y; - float t = fmod(scrollAmount * _ScrollRate + v.color.a, 1); - float4 dispVec = (t - .5f) * float4(_ScrollDistance, 0.0); - dispVec.x += sin(t * _ScrollJitterFrequency + _Time.y) * _ScrollJitterIntensity; - dispVec.z += cos(t * _ScrollJitterFrequency * .5 + _Time.y) * _ScrollJitterIntensity; - dispVec.xyz = spreadProgress * dispVec * kDecimetersToWorldUnits; - center_WS += mul(xf_CS, dispVec); - - PrepForOdsWorldSpace(center_WS); - - float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); -#ifdef AUDIO_REACTIVE - o.color = musicReactiveColor(v.color, _BeatOutput.w); - corner_WS = musicReactiveAnimationWorldSpace(corner_WS, v.color, _BeatOutput.w, corner_WS.y*5); -#else - o.color = v.color; -#endif - - o.vertex = mul(UNITY_MATRIX_VP, corner_WS); - o.color.a = pow(1 - abs(2*(t - .5)), 3); - o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : SV_Target - { - float4 texCol = tex2D(_MainTex, i.texcoord); - float4 color = SrgbToNative(2.0f * i.color * _TintColor * texCol); -#if SELECTION_ON - color.rgb = GetSelectionColor() * texCol.r; - color.a = texCol.a; -#endif - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/Snow" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _ScrollRate; + float3 _ScrollDistance; + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + float _SpreadRate; + + v2f vert (ParticleVertexWithSpread_t v) + { + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + v.color = TbVertToSrgb(v.color); + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float spreadProgress = SpreadProgress(birthTime, _SpreadRate); + float4 center = SpreadParticle(v, spreadProgress); + float4 center_WS = mul(unity_ObjectToWorld, center); + + // Custom vertex animation + float scrollAmount = GetTime().y; + float t = fmod(scrollAmount * _ScrollRate + v.color.a, 1); + float4 dispVec = (t - .5f) * float4(_ScrollDistance, 0.0); + dispVec.x += sin(t * _ScrollJitterFrequency + GetTime().y) * _ScrollJitterIntensity; + dispVec.z += cos(t * _ScrollJitterFrequency * .5 + GetTime().y) * _ScrollJitterIntensity; + dispVec.xyz = spreadProgress * dispVec * kDecimetersToWorldUnits; + center_WS += mul(xf_CS, dispVec); + + PrepForOdsWorldSpace(center_WS); + + float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); +#ifdef AUDIO_REACTIVE + o.color = musicReactiveColor(v.color, _BeatOutput.w); + corner_WS = musicReactiveAnimationWorldSpace(corner_WS, v.color, _BeatOutput.w, corner_WS.y*5); +#else + o.color = v.color; +#endif + + o.vertex = mul(UNITY_MATRIX_VP, corner_WS); + o.color.a = pow(1 - abs(2*(t - .5)), 3); + o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 texCol = tex2D(_MainTex, i.texcoord); + float4 color = SrgbToNative(2.0f * i.color * _TintColor * texCol); +#if SELECTION_ON + color.rgb = GetSelectionColor() * texCol.r; + color.a = texCol.a; +#endif + color.a *= _Opacity; + return color; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/SoftHighlighter/SoftHighlighter.shader b/Assets/Resources/Brushes/Basic/SoftHighlighter/SoftHighlighter.shader index 375a55c682..bd52c569c2 100644 --- a/Assets/Resources/Brushes/Basic/SoftHighlighter/SoftHighlighter.shader +++ b/Assets/Resources/Brushes/Basic/SoftHighlighter/SoftHighlighter.shader @@ -1,97 +1,116 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/SoftHighlighter" { -Properties { - _MainTex ("Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); -#ifdef AUDIO_REACTIVE - v.color = TbVertToSrgb(v.color); - o.color = musicReactiveColor(v.color, _BeatOutput.z); - v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.z, o.texcoord.x); - o.color = SrgbToNative(o.color); -#else - o.color = TbVertToNative(v.color); -#endif - o.pos = UnityObjectToClipPos(v.vertex); - return o; - - } - - fixed4 frag (v2f i) : COLOR - { - float4 c = tex2D(_MainTex, i.texcoord ); - c *= i.color; - FRAG_MOBILESELECT(c) - return c; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/SoftHighlighter" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float2 id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); +#ifdef AUDIO_REACTIVE + v.color = TbVertToSrgb(v.color); + o.color = musicReactiveColor(v.color, _BeatOutput.z); + v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.z, o.texcoord.x); + o.color = SrgbToNative(o.color); +#else + o.color = TbVertToNative(v.color); +#endif + o.pos = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + float4 c = tex2D(_MainTex, i.texcoord ); + c *= i.color; + c.a *= _Opacity; + FRAG_MOBILESELECT(c) + return c; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Stars/Stars.shader b/Assets/Resources/Brushes/Basic/Stars/Stars.shader index 39bd0b40c4..e0703ff73c 100644 --- a/Assets/Resources/Brushes/Basic/Stars/Stars.shader +++ b/Assets/Resources/Brushes/Basic/Stars/Stars.shader @@ -1,115 +1,136 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/Stars" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _SparkleRate ("Sparkle Rate", Float) = 2.5 - _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _SparkleRate; - float _SpreadRate; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (ParticleVertexWithSpread_t v) - { - v.color = TbVertToSrgb(v.color); - const float PI = 3.14159265359; - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float spreadProgress = SpreadProgress(birthTime, _SpreadRate); - float4 center = SpreadParticle(v, spreadProgress); - PrepForOds(center); - - float phase = v.color.a * (2 * PI); - float brightness; - -#ifdef AUDIO_REACTIVE - brightness = 800 * pow(abs(sin(_BeatOutputAccum.w * _SparkleRate + phase)), 20); - brightness = brightness*.25 + 2*brightness * (_BeatOutput.w); -#else - brightness = 800 * pow(abs(sin(_Time.y * _SparkleRate + phase)), 20); -#endif - o.color.rgb = v.color.rgb * brightness; - o.color.a = 1; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - - float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); - o.vertex = UnityObjectToClipPos(corner); - - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : SV_Target - { - float4 texCol = tex2D(_MainTex, i.texcoord); - float4 color = i.color * texCol; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); -#if SELECTION_ON - color.rgb = GetSelectionColor() * texCol.r; - color.a = texCol.a; -#endif - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/Stars" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _SparkleRate ("Sparkle Rate", Float) = 2.5 + _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _SparkleRate; + float _SpreadRate; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (ParticleVertexWithSpread_t v) + { + v.color = TbVertToSrgb(v.color); + const float PI = 3.14159265359; + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float spreadProgress = SpreadProgress(birthTime, _SpreadRate); + float4 center = SpreadParticle(v, spreadProgress); + PrepForOds(center); + + float phase = v.color.a * (2 * PI); + float brightness; + +#ifdef AUDIO_REACTIVE + brightness = 800 * pow(abs(sin(_BeatOutputAccum.w * _SparkleRate + phase)), 20); + brightness = brightness*.25 + 2*brightness * (_BeatOutput.w); +#else + brightness = 800 * pow(abs(sin(GetTime().y * _SparkleRate + phase)), 20); +#endif + o.color.rgb = v.color.rgb * brightness; + o.color.a = 1; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + + float4 corner = OrientParticle(center.xyz, halfSize, v.vid, rotation); + o.vertex = UnityObjectToClipPos(corner); + o.id = (float2)v.id; + + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 texCol = tex2D(_MainTex, i.texcoord); + float4 color = i.color * texCol; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); +#if SELECTION_ON + color.rgb = GetSelectionColor() * texCol.r; + color.a = texCol.a; +#endif + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Streamers/Streamers.shader b/Assets/Resources/Brushes/Basic/Streamers/Streamers.shader index 5cf7c9928a..6f9ac2920e 100644 --- a/Assets/Resources/Brushes/Basic/Streamers/Streamers.shader +++ b/Assets/Resources/Brushes/Basic/Streamers/Streamers.shader @@ -1,148 +1,170 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Streamers" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _Scroll1 ("Scroll1", Float) = 0 - _Scroll2 ("Scroll2", Float) = 0 - _DisplacementIntensity("Displacement", Float) = .1 - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile_particles - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 // Required -> compiler error: too many instructions for SM 2.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - fixed _Scroll1; - fixed _Scroll2; - half _DisplacementIntensity; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.worldPos = mul(unity_ObjectToWorld, v.vertex); - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - float rand_1_05(in float2 uv) - { - float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); - return abs(noise.x + noise.y) * 0.5; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - // Create parametric flowing UV's - half2 uvs = i.texcoord; - float row_id = floor(uvs.y * 5); - float row_rand = rand_1_05(row_id.xx); - uvs.x += row_rand * 200; - - half2 sins = sin(uvs.x * half2(10,23) + _Time.z * half2(5,3)); - uvs.y = 5 * uvs.y + dot(half2(.05, -.05), sins); - -#ifdef AUDIO_REACTIVE - // Scrolling UVs - uvs.x *= .5 + row_rand * .3; - uvs.x -= _BeatOutputAccum.x * (1 + fmod(row_id * 1.61803398875, 1) - 0.5); -#else - // Scrolling UVs - uvs.x *= .5 + row_rand * .3; - uvs.x -= _Time.y * (1 + fmod(row_id * 1.61803398875, 1) - 0.5); -#endif - - // Sample final texture - half4 tex = tex2D(_MainTex, uvs); - - // Boost hot spot in texture - tex += pow(tex, 2) * 55; - - // Clean up border pixels filtering artifacts - tex *= fmod(uvs.y,1); // top edge - tex *= fmod(uvs.y,1); // top edge - tex *= 1 - fmod(uvs.y,1); // bottom edge - tex *= 1 - fmod(uvs.y,1); // bottom edge - -#ifdef AUDIO_REACTIVE - tex += tex * _BeatOutput.x; -#endif - - float4 color = i.color * tex * exp(_EmissionGain * 5.0f); - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - FRAG_MOBILESELECT(color) - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Streamers" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _Scroll1 ("Scroll1", Float) = 0 + _Scroll2 ("Scroll2", Float) = 0 + _DisplacementIntensity("Displacement", Float) = .1 + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile_particles + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 // Required -> compiler error: too many instructions for SM 2.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + fixed _Scroll1; + fixed _Scroll2; + half _DisplacementIntensity; + half _EmissionGain; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + float rand_1_05(in float2 uv) + { + float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); + return abs(noise.x + noise.y) * 0.5; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + // Create parametric flowing UV's + half2 uvs = i.texcoord; + float row_id = floor(uvs.y * 5); + float row_rand = rand_1_05(row_id.xx); + uvs.x += row_rand * 200; + + half2 sins = sin(uvs.x * half2(10,23) + GetTime().z * half2(5,3)); + uvs.y = 5 * uvs.y + dot(half2(.05, -.05), sins); + +#ifdef AUDIO_REACTIVE + // Scrolling UVs + uvs.x *= .5 + row_rand * .3; + uvs.x -= _BeatOutputAccum.x * (1 + fmod(row_id * 1.61803398875, 1) - 0.5); +#else + // Scrolling UVs + uvs.x *= .5 + row_rand * .3; + uvs.x -= GetTime().y * (1 + fmod(row_id * 1.61803398875, 1) - 0.5); +#endif + + // Sample final texture + half4 tex = tex2D(_MainTex, uvs); + + // Boost hot spot in texture + tex += pow(tex, 2) * 55; + + // Clean up border pixels filtering artifacts + tex *= fmod(uvs.y,1); // top edge + tex *= fmod(uvs.y,1); // top edge + tex *= 1 - fmod(uvs.y,1); // bottom edge + tex *= 1 - fmod(uvs.y,1); // bottom edge + +#ifdef AUDIO_REACTIVE + tex += tex * _BeatOutput.x; +#endif + + float4 color = i.color * tex * exp(_EmissionGain * 5.0f); + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Toon/Toon.shader b/Assets/Resources/Brushes/Basic/Toon/Toon.shader index 822f58aba5..e69e2bbb75 100644 --- a/Assets/Resources/Brushes/Basic/Toon/Toon.shader +++ b/Assets/Resources/Brushes/Basic/Toon/Toon.shader @@ -1,162 +1,183 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Toon" { -Properties { - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} - _OutlineMax("Maximum outline size", Range(0, .5)) = .005 -} - -CGINCLUDE - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile_fog - #pragma multi_compile __ SELECTION_ON - #pragma target 3.0 - sampler2D _MainTex; - float4 _MainTex_ST; - float _OutlineMax; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float3 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - UNITY_FOG_COORDS(1) - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vertInflate (appdata_t v, float inflate) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float outlineEnabled = inflate; - float radius = v.texcoord.z; - inflate *= radius * .4; - float bulge = 0.0; - float3 worldNormal = UnityObjectToWorldNormal(v.normal); - -#ifdef AUDIO_REACTIVE - float fft = tex2Dlod(_FFTTex, float4(_BeatOutputAccum.z*.25 + v.texcoord.x, 0,0,0)).g; - bulge = fft * radius * 10.0; -#endif - - // - // Careful: perspective projection is non-afine, so math assumptions may not be valid here. - // - - // Technically these are not yet in NDC because they haven't been divided by W, so their - // range is currently [-W, W]. - o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal.xyz * bulge, v.vertex.w)); - float4 outline_NDC = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal.xyz * inflate, v.vertex.w)); - - // Displacement in proper NDC coords (e.g. [-1, 1]) - float3 disp = outline_NDC.xyz / outline_NDC.w - o.pos.xyz / o.pos.w; - - // Magnitude is a scaling factor to shrink large outlines down to a max width, in NDC space. - // Notice here we're only measuring 2D displacment in X and Y. - float mag = length(disp.xy); - mag = min(_OutlineMax, mag) / mag; - - // Ideally we would project back into world space to do the scaling, but the inverse - // projection matrix is not currently available. So instead, we multiply back in the w - // component so both sides of the += operator below are in the same space. Also note - // that the w component is a function of depth, so modifying X and Y independent of Z - // should mean that the original w value remains valid. - o.pos.xyz += float3(disp.xy * mag, disp.z) * o.pos.w * outlineEnabled; - - // Push Z back to avoid z-fighting when scaled very small. This is not legit, - // mathematically speaking and likely causes crazy surface derivitives. - o.pos.z -= disp.z * o.pos.w * outlineEnabled; - - o.color = v.color; - o.color.a = 1; - o.color.xyz += worldNormal.y *.2; - o.color.xyz = max(0, o.color.xyz); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - v2f vert (appdata_t v) - { - v.color = TbVertToNative(v.color); - return vertInflate(v,0); - } - - v2f vertEdge (appdata_t v) - { - // v.color = TbVertToNative(v.color); no need - return vertInflate(v, 1.0); - } - - fixed4 fragBlack (v2f i) : SV_Target - { - float4 color = float4(0,0,0,1); - UNITY_APPLY_FOG(i.fogCoord, color); - FRAG_MOBILESELECT(color) - return color; - } - - fixed4 fragColor (v2f i) : SV_Target - { - UNITY_APPLY_FOG(i.fogCoord, i.color); - FRAG_MOBILESELECT(i.color) - return i.color; - } - -ENDCG - - - -SubShader { - // For exportManifest.json: - // GltfCull Back - Cull Back - Pass{ - CGPROGRAM - #pragma vertex vert - #pragma fragment fragColor - ENDCG - } - - Cull Front - Pass{ - CGPROGRAM - #pragma vertex vertEdge - #pragma fragment fragBlack - ENDCG - } - } -Fallback "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Toon" { +Properties { + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _OutlineMax("Maximum outline size", Range(0, .5)) = .005 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +CGINCLUDE + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile_fog + #pragma multi_compile __ SELECTION_ON + #pragma target 3.0 + sampler2D _MainTex; + float4 _MainTex_ST; + float _OutlineMax; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float3 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + UNITY_FOG_COORDS(1) + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vertInflate (appdata_t v, float inflate) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float outlineEnabled = inflate; + float radius = v.texcoord.z; + inflate *= radius * .4; + float bulge = 0.0; + float3 worldNormal = UnityObjectToWorldNormal(v.normal); + +#ifdef AUDIO_REACTIVE + float fft = tex2Dlod(_FFTTex, float4(_BeatOutputAccum.z*.25 + v.texcoord.x, 0,0,0)).g; + bulge = fft * radius * 10.0; +#endif + + // + // Careful: perspective projection is non-afine, so math assumptions may not be valid here. + // + + // Technically these are not yet in NDC because they haven't been divided by W, so their + // range is currently [-W, W]. + o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal.xyz * bulge, v.vertex.w)); + float4 outline_NDC = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal.xyz * inflate, v.vertex.w)); + + // Displacement in proper NDC coords (e.g. [-1, 1]) + float3 disp = outline_NDC.xyz / outline_NDC.w - o.pos.xyz / o.pos.w; + + // Magnitude is a scaling factor to shrink large outlines down to a max width, in NDC space. + // Notice here we're only measuring 2D displacment in X and Y. + float mag = length(disp.xy); + mag = min(_OutlineMax, mag) / mag; + + // Ideally we would project back into world space to do the scaling, but the inverse + // projection matrix is not currently available. So instead, we multiply back in the w + // component so both sides of the += operator below are in the same space. Also note + // that the w component is a function of depth, so modifying X and Y independent of Z + // should mean that the original w value remains valid. + o.pos.xyz += float3(disp.xy * mag, disp.z) * o.pos.w * outlineEnabled; + + // Push Z back to avoid z-fighting when scaled very small. This is not legit, + // mathematically speaking and likely causes crazy surface derivitives. + o.pos.z -= disp.z * o.pos.w * outlineEnabled; + + o.color = v.color; + o.color.a = 1; + o.color.xyz += worldNormal.y *.2; + o.color.xyz = max(0, o.color.xyz); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + UNITY_TRANSFER_FOG(o, o.pos); + o.id = (float2)v.id; + return o; + } + + v2f vert (appdata_t v) + { + v.color = TbVertToNative(v.color); + return vertInflate(v,0); + } + + v2f vertEdge (appdata_t v) + { + // v.color = TbVertToNative(v.color); no need + return vertInflate(v, 1.0); + } + + fixed4 fragBlack (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + float4 color = float4(0,0,0,1); + UNITY_APPLY_FOG(i.fogCoord, color); + FRAG_MOBILESELECT(color) + return color; + } + + fixed4 fragColor (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + UNITY_APPLY_FOG(i.fogCoord, i.color); + FRAG_MOBILESELECT(i.color) + return i.color; + } + +ENDCG + + + +SubShader { + // For exportManifest.json: + // GltfCull Back + Cull Back + Pass{ + CGPROGRAM + #pragma vertex vert + #pragma fragment fragColor + ENDCG + } + + Cull Front + Pass{ + CGPROGRAM + #pragma vertex vertEdge + #pragma fragment fragBlack + ENDCG + } + } +Fallback "Diffuse" +} diff --git a/Assets/Resources/Brushes/Basic/TubeToonInverted/TubeToonInverted.shader b/Assets/Resources/Brushes/Basic/TubeToonInverted/TubeToonInverted.shader index 5a78545aed..db7fd599e0 100644 --- a/Assets/Resources/Brushes/Basic/TubeToonInverted/TubeToonInverted.shader +++ b/Assets/Resources/Brushes/Basic/TubeToonInverted/TubeToonInverted.shader @@ -1,112 +1,131 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/TubeToonInverted" { -Properties { - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} -} - -CGINCLUDE - - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - sampler2D _MainTex; - float4 _MainTex_ST; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vertInflate (appdata_t v, float inflate) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - v.vertex.xyz += v.normal.xyz * inflate; - o.vertex = UnityObjectToClipPos(v.vertex); - o.color = v.color; - o.color.a = 1; - o.color.xyz += v.normal.y *.2; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - return o; - } - - v2f vert (appdata_t v) - { - return vertInflate(v,0); - } - - v2f vertEdge (appdata_t v) - { - // As the scale goes up, we want the outline to be smaller, almost as if it's in screenspace - // however we don't want the outline to be a constant size, it should get smaller as the - // stroke gets further from camera, to avoid distant strokes turning into a big black mess. - float scale = length(mul(xf_I_CS, float3(0.05, 0, 0))); - return vertInflate(v, scale); - } - - fixed4 fragBlack (v2f i) : SV_Target - { - return float4(0,0,0,1); - } - - fixed4 fragColor (v2f i) : SV_Target - { - return i.color; - } - -ENDCG - - - -SubShader { - Cull Back - Pass{ - CGPROGRAM - #pragma vertex vert - #pragma fragment fragBlack - ENDCG - } - - Cull Front - Pass{ - CGPROGRAM - #pragma vertex vertEdge - #pragma fragment fragColor - ENDCG - } - } -Fallback "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/TubeToonInverted" { +Properties { + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +CGINCLUDE + + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + sampler2D _MainTex; + float4 _MainTex_ST; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vertInflate (appdata_t v, float inflate) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + v.vertex.xyz += v.normal.xyz * inflate; + o.vertex = UnityObjectToClipPos(v.vertex); + o.color = v.color; + o.color.a = 1; + o.color.xyz += v.normal.y *.2; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.id = (float2)v.id; + return o; + } + + v2f vert (appdata_t v) + { + return vertInflate(v,0); + } + + v2f vertEdge (appdata_t v) + { + // As the scale goes up, we want the outline to be smaller, almost as if it's in screenspace + // however we don't want the outline to be a constant size, it should get smaller as the + // stroke gets further from camera, to avoid distant strokes turning into a big black mess. + float scale = length(mul(xf_I_CS, float3(0.05, 0, 0))); + return vertInflate(v, scale); + } + + fixed4 fragBlack (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + return float4(0,0,0,1); + } + + fixed4 fragColor (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + return i.color; + } + +ENDCG + + + +SubShader { + Cull Back + Pass{ + CGPROGRAM + #pragma vertex vert + #pragma fragment fragBlack + ENDCG + } + + Cull Front + Pass{ + CGPROGRAM + #pragma vertex vertEdge + #pragma fragment fragColor + ENDCG + } + } +Fallback "Diffuse" +} diff --git a/Assets/Resources/Brushes/Basic/VelvetInk/VelvetInk.shader b/Assets/Resources/Brushes/Basic/VelvetInk/VelvetInk.shader index e33df527cc..83a29eb068 100644 --- a/Assets/Resources/Brushes/Basic/VelvetInk/VelvetInk.shader +++ b/Assets/Resources/Brushes/Basic/VelvetInk/VelvetInk.shader @@ -1,96 +1,114 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/VelvetInk" { -Properties { - _MainTex ("Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); -#ifdef AUDIO_REACTIVE - v.color = TbVertToSrgb(v.color); - o.color = musicReactiveColor(v.color, _BeatOutput.w); - v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.w, o.texcoord.x); - o.color = SrgbToNative(o.color); -#else - o.color = TbVertToNative(v.color); -#endif - o.pos = UnityObjectToClipPos(v.vertex); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - half4 c = tex2D(_MainTex, i.texcoord ); - c = i.color * c; - FRAG_MOBILESELECT(c) - return c; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/VelvetInk" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); +#ifdef AUDIO_REACTIVE + v.color = TbVertToSrgb(v.color); + o.color = musicReactiveColor(v.color, _BeatOutput.w); + v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.w, o.texcoord.x); + o.color = SrgbToNative(o.color); +#else + o.color = TbVertToNative(v.color); +#endif + o.pos = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + half4 c = tex2D(_MainTex, i.texcoord ); + c = i.color * c; + FRAG_MOBILESELECT(c) + c.a *= _Opacity; + return c; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/Waveform/Waveform.shader b/Assets/Resources/Brushes/Basic/Waveform/Waveform.shader index 65886f9f5c..03e1c3fdac 100644 --- a/Assets/Resources/Brushes/Basic/Waveform/Waveform.shader +++ b/Assets/Resources/Brushes/Basic/Waveform/Waveform.shader @@ -1,114 +1,136 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/Waveform" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 unbloomedColor : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = bloomColor(v.color, _EmissionGain); - o.unbloomedColor = v.color; - return o; - } - - // Input colors are srgb - fixed4 frag (v2f i) : COLOR - { - // Envelope - float envelope = sin(i.texcoord.x * 3.14159); - -#ifdef AUDIO_REACTIVE - float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r) - .5; -#else - float waveform = .15 * sin( -30 * i.unbloomedColor.r * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.r); - waveform += .15 * sin( -40 * i.unbloomedColor.g * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.g); - waveform += .15 * sin( -50 * i.unbloomedColor.b * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.b); -#endif - - float pinch = (1 - envelope) * 40 + 20; - float procedural_line = saturate(1 - pinch*abs(i.texcoord.y - .5 -waveform * envelope)); - float4 color = 1; - color.rgb *= envelope * procedural_line; - color = i.color * color; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - FRAG_MOBILESELECT(color) - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/Waveform" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 unbloomedColor : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = bloomColor(v.color, _EmissionGain); + o.unbloomedColor = v.color; + o.id = (float2)v.id; + return o; + } + + // Input colors are srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + // Envelope + float envelope = sin(i.texcoord.x * 3.14159); + +#ifdef AUDIO_REACTIVE + float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r) - .5; +#else + float waveform = .15 * sin( -30 * i.unbloomedColor.r * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.r); + waveform += .15 * sin( -40 * i.unbloomedColor.g * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.g); + waveform += .15 * sin( -50 * i.unbloomedColor.b * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.b); +#endif + + float pinch = (1 - envelope) * 40 + 20; + float procedural_line = saturate(1 - pinch*abs(i.texcoord.y - .5 -waveform * envelope)); + float4 color = 1; + color.rgb *= envelope * procedural_line; + color = i.color * color; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/WaveformFFT/WaveformFFT.shader b/Assets/Resources/Brushes/Basic/WaveformFFT/WaveformFFT.shader index 02c305f1d7..7ab51f3ecc 100644 --- a/Assets/Resources/Brushes/Basic/WaveformFFT/WaveformFFT.shader +++ b/Assets/Resources/Brushes/Basic/WaveformFFT/WaveformFFT.shader @@ -1,108 +1,130 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/WaveformFFT" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - float4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 unbloomedColor : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = bloomColor(v.color, _EmissionGain); - o.unbloomedColor = v.color; - return o; - } - - fixed4 frag (v2f i) : COLOR - { - // Envelope - float envelope = 1; //sin(i.texcoord.x * 3.14159); - -#ifdef AUDIO_REACTIVE - float waveform = (tex2D(_FFTTex, float2(.5 - i.texcoord.x,0)).b); -#else - float waveform = .15 * sin( -30 * i.unbloomedColor.r * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.r); - waveform += .15 * sin( -40 * i.unbloomedColor.g * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.g); - waveform += .15 * sin( -50 * i.unbloomedColor.b * _Time.w + i.texcoord.x * 100 * i.unbloomedColor.b); -#endif - - float pinch = (1 - envelope) * 40 + 20; - //float procedural_line = saturate(1 - pinch*abs(i.texcoord.y + -waveform * envelope)); - float procedural_line = abs(i.texcoord.y - .5) > waveform ? 0 : waveform ; //saturate(1 - pinch*abs(i.texcoord.y + -waveform * envelope)); - float4 color = 1; - color.rgb *= envelope * procedural_line; - color = i.color * color; - return encodeHdr(color.rgb * color.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/WaveformFFT" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + float4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 unbloomedColor : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = bloomColor(v.color, _EmissionGain); + o.unbloomedColor = v.color; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // Envelope + float envelope = 1; //sin(i.texcoord.x * 3.14159); + +#ifdef AUDIO_REACTIVE + float waveform = (tex2D(_FFTTex, float2(.5 - i.texcoord.x,0)).b); +#else + float waveform = .15 * sin( -30 * i.unbloomedColor.r * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.r); + waveform += .15 * sin( -40 * i.unbloomedColor.g * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.g); + waveform += .15 * sin( -50 * i.unbloomedColor.b * GetTime().w + i.texcoord.x * 100 * i.unbloomedColor.b); +#endif + + float pinch = (1 - envelope) * 40 + 20; + //float procedural_line = saturate(1 - pinch*abs(i.texcoord.y + -waveform * envelope)); + float procedural_line = abs(i.texcoord.y - .5) > waveform ? 0 : waveform ; //saturate(1 - pinch*abs(i.texcoord.y + -waveform * envelope)); + float4 color = 1; + color.rgb *= envelope * procedural_line; + color = i.color * color; + color = encodeHdr(color.rgb * color.a); + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/WaveformParticles/WaveformParticles.shader b/Assets/Resources/Brushes/Basic/WaveformParticles/WaveformParticles.shader index 571b28c101..063a2898d6 100644 --- a/Assets/Resources/Brushes/Basic/WaveformParticles/WaveformParticles.shader +++ b/Assets/Resources/Brushes/Basic/WaveformParticles/WaveformParticles.shader @@ -1,121 +1,145 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/WaveformParticles" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma glsl - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/Math.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 texcoord1 : TEXCOORD1; - float3 tangent : TANGENT; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float3 worldPos : TEXCOORD1; - float lifetime : TEXCOORD2; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - float4 worldPos = mul(unity_ObjectToWorld, v.vertex); - float3 perVertOffset = v.texcoord1.xyz; - float lifetime = _Time.y - v.texcoord1.w; - o.lifetime = lifetime; - float release = saturate(lifetime * .1); - float3 localMidpointPos = v.vertex.xyz - perVertOffset; - float4 worldMidpointPos = mul(unity_ObjectToWorld, localMidpointPos); - -#ifdef AUDIO_REACTIVE - lifetime = -lifetime*.1 + _BeatOutputAccum.x; - -#endif - - float time = lifetime; - float d = 10 + v.color.g * 3; - float freq = 1.5 + v.color.r; - float3 disp = float3(1,0,0) * curlX(worldMidpointPos.xyz * freq + time, d); - disp += float3(0,1,0) * curlY(worldMidpointPos.xyz * freq +time, d); - disp += float3(0,0,1) * curlZ(worldMidpointPos.xyz * freq + time, d); - - worldMidpointPos.xyz += release * disp * 10; - worldPos.xyz = worldMidpointPos.xyz + perVertOffset; - - o.vertex = mul(UNITY_MATRIX_VP, worldPos); - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.worldPos = worldPos.xyz; - return o; - } - - fixed4 frag (v2f i) : SV_Target - { - - float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); - return encodeHdr(c.rgb * c.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/WaveformParticles" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma glsl + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/Math.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float3 tangent : TANGENT; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float3 worldPos : TEXCOORD1; + float lifetime : TEXCOORD2; + uint id : TEXCOORD3; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float4 worldPos = mul(unity_ObjectToWorld, v.vertex); + float3 perVertOffset = v.texcoord1.xyz; + float lifetime = GetTime().y - v.texcoord1.w; + o.lifetime = lifetime; + float release = saturate(lifetime * .1); + float3 localMidpointPos = v.vertex.xyz - perVertOffset; + float4 worldMidpointPos = mul(unity_ObjectToWorld, localMidpointPos); + +#ifdef AUDIO_REACTIVE + lifetime = -lifetime*.1 + _BeatOutputAccum.x; + +#endif + + float time = lifetime; + float d = 10 + v.color.g * 3; + float freq = 1.5 + v.color.r; + float3 disp = float3(1,0,0) * curlX(worldMidpointPos.xyz * freq + time, d); + disp += float3(0,1,0) * curlY(worldMidpointPos.xyz * freq +time, d); + disp += float3(0,0,1) * curlZ(worldMidpointPos.xyz * freq + time, d); + + worldMidpointPos.xyz += release * disp * 10; + worldPos.xyz = worldMidpointPos.xyz + perVertOffset; + + o.vertex = mul(UNITY_MATRIX_VP, worldPos); + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.worldPos = worldPos.xyz; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 c = i.color * _TintColor * tex2D(_MainTex, i.texcoord); + c = encodeHdr(c.rgb * c.a); + return c * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/WaveformPulse/NeonPulse.shader b/Assets/Resources/Brushes/Basic/WaveformPulse/NeonPulse.shader index de51b97f85..171dbb2012 100644 --- a/Assets/Resources/Brushes/Basic/WaveformPulse/NeonPulse.shader +++ b/Assets/Resources/Brushes/Basic/WaveformPulse/NeonPulse.shader @@ -1,91 +1,115 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/WaveformPulse" { - -Properties { - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - Cull Off ZWrite Off - - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert - - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct appdata { - float4 vertex : POSITION; - float3 texcoord : TEXCOORD0; - float3 texcoord1 : TEXCOORD1; - float3 texcoord2 : TEXCOORD2; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Input { - float4 color : Color; - float2 tex : TEXCOORD0; - float3 viewDir; - float3 worldNormal; - INTERNAL_DATA - }; - - float _EmissionGain; - - void vert (inout appdata i, out Input o) { - PrepForOds(i.vertex); - UNITY_INITIALIZE_OUTPUT(Input, o); - o.color = TbVertToSrgb(o.color); - o.tex = i.texcoord; - } - - // Input color is srgb - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - o.Smoothness = .8; - o.Specular = .05; - float audioMultiplier = 1; -#ifdef AUDIO_REACTIVE - audioMultiplier += audioMultiplier * _BeatOutput.x; - IN.tex.x -= _BeatOutputAccum.z; - IN.color += IN.color * _BeatOutput.w * .25; -#else - IN.tex.x -= _Time.x*15; -#endif - IN.tex.x = fmod( abs(IN.tex.x),1); - float neon = saturate(pow( 10 * saturate(.2 - IN.tex.x),5) * audioMultiplier); - float4 bloom = bloomColor(IN.color, _EmissionGain); - float3 n = WorldNormalVector (IN, o.Normal); - half rim = 1.0 - saturate(dot (normalize(IN.viewDir), n)); - bloom *= pow(1-rim,5); - o.Emission = SrgbToNative(bloom * neon); - SURF_FRAG_MOBILESELECT(o); - } - ENDCG -} // SubShader - -} // Shader +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/WaveformPulse" { + +Properties { + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + Cull Off ZWrite Off + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert + + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct appdata { + float4 vertex : POSITION; + float3 texcoord : TEXCOORD0; + float3 texcoord1 : TEXCOORD1; + float3 texcoord2 : TEXCOORD2; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct Input { + float4 color : Color; + float2 tex : TEXCOORD0; + float3 viewDir; + float3 worldNormal; + uint id : SV_VertexID; + float4 screenPos; + INTERNAL_DATA + }; + + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert (inout appdata i, out Input o) { + PrepForOds(i.vertex); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.color = TbVertToSrgb(o.color); + o.id = (float2)i.id; + } + + // Input color is srgb + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + o.Smoothness = .8; + o.Specular = .05; + float audioMultiplier = 1; +#ifdef AUDIO_REACTIVE + audioMultiplier += audioMultiplier * _BeatOutput.x; + IN.tex.x -= _BeatOutputAccum.z; + IN.color += IN.color * _BeatOutput.w * .25; +#else + IN.tex.x -= GetTime().x*15; +#endif + IN.tex.x = fmod( abs(IN.tex.x),1); + float neon = saturate(pow( 10 * saturate(.2 - IN.tex.x),5) * audioMultiplier); + float4 bloom = bloomColor(IN.color, _EmissionGain); + float3 n = WorldNormalVector (IN, o.Normal); + half rim = 1.0 - saturate(dot (normalize(IN.viewDir), n)); + bloom *= pow(1-rim,5); + o.Emission = SrgbToNative(bloom * neon); + o.Alpha *= _Dissolve; + o.Emission *= _Dissolve; + o.Albedo *= _Dissolve; + o.Specular *= _Dissolve; + SURF_FRAG_MOBILESELECT(o); + } + ENDCG +} // SubShader + +} // Shader diff --git a/Assets/Resources/Brushes/Basic/WaveformTube/WaveformTube.shader b/Assets/Resources/Brushes/Basic/WaveformTube/WaveformTube.shader index f902469cde..1ae2fecea3 100644 --- a/Assets/Resources/Brushes/Basic/WaveformTube/WaveformTube.shader +++ b/Assets/Resources/Brushes/Basic/WaveformTube/WaveformTube.shader @@ -1,95 +1,112 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Visualizer/WaveformTube" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One //SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - float4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); - - o.color = bloomColor(v.color, _EmissionGain); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - i.texcoord.x -= _BeatOutputAccum.x; - i.texcoord.y += i.texcoord.x; - i.texcoord.x *= .25; - - float wav = (tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r - .5f); - i.texcoord.y += wav; - float4 c = i.color * tex2D(_MainTex, i.texcoord); - return encodeHdr(c.rgb * c.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Visualizer/WaveformTube" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One //SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + float4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); + + o.color = bloomColor(v.color, _EmissionGain); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + i.texcoord.x -= _BeatOutputAccum.x; + i.texcoord.y += i.texcoord.x; + i.texcoord.x *= .25; + + float wav = (tex2D(_WaveFormTex, float2(i.texcoord.x,0)).r - .5f); + i.texcoord.y += wav; + float4 c = i.color * tex2D(_MainTex, i.texcoord); + c = encodeHdr(c.rgb * c.a); + return c * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteDoubleSided.shader b/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteDoubleSided.shader index 7d0dee6963..dfc9f10f6d 100644 --- a/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteDoubleSided.shader +++ b/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteDoubleSided.shader @@ -1,91 +1,117 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/WigglyGraphiteDoubleSided" { - Properties{ - _MainTex("Main Texture", 2D) = "white" {} - _SecondaryTex("Diffuse Tex", 2D) = "white" {} - _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 - } - SubShader{ - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - Cull Off - - CGPROGRAM - #pragma target 4.0 - #pragma surface surf StandardSpecular vertex:vert addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - struct appdata { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float2 texcoord1 : TEXCOORD1; - float2 texcoord2 : TEXCOORD2; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Input { - float2 uv_MainTex; - float4 color : Color; - fixed vface : VFACE; - }; - - sampler2D _MainTex; - float _Cutoff; - - void vert(inout appdata i, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(i.vertex); - o.color = TbVertToSrgb(i.color); - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - fixed2 scrollUV = IN.uv_MainTex; - - // Animate flipbook motion. Currently tuned to taste. -#ifdef AUDIO_REACTIVE - float anim = ceil(fmod(_Time.y * 3.0 + _BeatOutput.x * 3.0, 6.0)); -#else - float anim = ceil(fmod(_Time.y * 12.0, 6.0)); -#endif - scrollUV.x += anim; - scrollUV.x *= 1.1; - - o.Specular = 0; - o.Smoothness = 0; - o.Albedo = IN.color.rgb; - o.Alpha = tex2D(_MainTex, scrollUV).w * IN.color.a; - if (o.Alpha < _Cutoff) { - discard; - } - o.Alpha = 1; - o.Normal.z *= IN.vface; - - SURF_FRAG_MOBILESELECT(o); - } - ENDCG - } - FallBack "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/WigglyGraphiteDoubleSided" { + Properties{ + _MainTex("Main Texture", 2D) = "white" {} + _SecondaryTex("Diffuse Tex", 2D) = "white" {} + _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader{ + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + Cull Off + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + struct appdata { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float2 texcoord1 : TEXCOORD1; + float2 texcoord2 : TEXCOORD2; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct Input { + float2 uv_MainTex; + float4 color : Color; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 vertex : SV_POSITION; + float4 screenPos; + }; + + sampler2D _MainTex; + float _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert(inout appdata i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + o.vertex = UnityObjectToClipPos(i.vertex); + PrepForOds(i.vertex); + o.color = TbVertToSrgb(i.color); + o.id = i.id; + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed2 scrollUV = IN.uv_MainTex; + + // Animate flipbook motion. Currently tuned to taste. +#ifdef AUDIO_REACTIVE + float anim = ceil(fmod(GetTime().y * 3.0 + _BeatOutput.x * 3.0, 6.0)); +#else + float anim = ceil(fmod(GetTime().y * 12.0, 6.0)); +#endif + scrollUV.x += anim; + scrollUV.x *= 1.1; + + o.Specular = 0; + o.Smoothness = 0; + o.Albedo = IN.color.rgb; + o.Alpha = tex2D(_MainTex, scrollUV).w * IN.color.a; + if (o.Alpha < _Cutoff) { + discard; + } + o.Alpha = 1; + o.Normal.z *= IN.vface; + + SURF_FRAG_MOBILESELECT(o); + } + ENDCG + } + FallBack "Diffuse" +} diff --git a/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteSingleSided.shader b/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteSingleSided.shader index 8c7eda504f..817f331c7a 100644 --- a/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteSingleSided.shader +++ b/Assets/Resources/Brushes/Basic/WigglyGraphite/WigglyGraphiteSingleSided.shader @@ -1,74 +1,80 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/WigglyGraphiteSingleSided" { - Properties{ - _MainTex("Main Texture", 2D) = "white" {} - _SecondaryTex("Diffuse Tex", 2D) = "white" {} - _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 - } - SubShader{ - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 200 - Cull Back - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_SecondaryTex; - float4 color : Color; - float2 texcoord1 : TEXCOORD1; - }; - - sampler2D _MainTex; - sampler2D _SecondaryTex; - - void vert(inout appdata_full i) { - PrepForOds(i.vertex); - i.color = TbVertToSrgb(i.color); - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - fixed2 scrollUV = IN.uv_MainTex; - - // Animate flipbook motion. Currently tuned to taste. - float anim = fmod(_Time.y * 12, 6); - anim = ceil(anim); - scrollUV.x += anim; - scrollUV.x *= 1.1; - - float3 secondary_tex = tex2D(_MainTex, IN.uv_SecondaryTex ).rgb; - - // Apply the alpha mask - float primary_tex = tex2D(_MainTex, scrollUV).w; - - float3 tex = secondary_tex * primary_tex; - - o.Specular = 0; - o.Smoothness = 0; - o.Albedo = IN.color.rgb; - o.Alpha = tex * IN.color.a; - } - ENDCG - } - FallBack "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/WigglyGraphiteSingleSided" { + Properties{ + _MainTex("Main Texture", 2D) = "white" {} + _SecondaryTex("Diffuse Tex", 2D) = "white" {} + _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + } + SubShader{ + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 200 + Cull Back + + CGPROGRAM + #pragma target 3.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_SecondaryTex; + float4 color : Color; + float2 texcoord1 : TEXCOORD1; + }; + + sampler2D _MainTex; + sampler2D _SecondaryTex; + + void vert(inout appdata_full i) { + PrepForOds(i.vertex); + i.color = TbVertToSrgb(i.color); + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + fixed2 scrollUV = IN.uv_MainTex; + + // Animate flipbook motion. Currently tuned to taste. + float anim = fmod(GetTime().y * 12, 6); + anim = ceil(anim); + scrollUV.x += anim; + scrollUV.x *= 1.1; + + float3 secondary_tex = tex2D(_MainTex, IN.uv_SecondaryTex ).rgb; + + // Apply the alpha mask + float primary_tex = tex2D(_MainTex, scrollUV).w; + + float3 tex = secondary_tex * primary_tex; + + o.Specular = 0; + o.Smoothness = 0; + o.Albedo = IN.color.rgb; + o.Alpha = tex * IN.color.a; + } + ENDCG + } + FallBack "Diffuse" +} diff --git a/Assets/Resources/Brushes/Basic/Wireframe/Wireframe.shader b/Assets/Resources/Brushes/Basic/Wireframe/Wireframe.shader index fc6e8dbec2..fc23a2c3b4 100644 --- a/Assets/Resources/Brushes/Basic/Wireframe/Wireframe.shader +++ b/Assets/Resources/Brushes/Basic/Wireframe/Wireframe.shader @@ -1,92 +1,109 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Wireframe" { -Properties { -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - AlphaTest Greater .01 - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = v.texcoord; - o.color = v.color; - o.vertex = UnityObjectToClipPos(v.vertex); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - - half w = 0; -#ifdef AUDIO_REACTIVE - float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.y,0)).r - .5f); - float envelope = sin(i.texcoord.y * 3.141569); - i.texcoord.x += waveform * envelope; - w = ( abs(i.texcoord.x - .5) > .5) ? 1 : 0; -#else - w = ( abs(i.texcoord.x - .5) > .45) ? 1 : 0; - w += ( abs(i.texcoord.y - .5) > .45) ? 1 : 0; -#endif - //float angle = atan2(i.texcoord.x, i.texcoord.y); - //w += ( abs(angle - (3.14/4.0)) < .05) ? 1 : 0; - return i.color * w; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Wireframe" { +Properties { + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + AlphaTest Greater .01 + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = v.texcoord; + o.color = v.color; + o.vertex = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + half w = 0; +#ifdef AUDIO_REACTIVE + float waveform = (tex2D(_WaveFormTex, float2(i.texcoord.y,0)).r - .5f); + float envelope = sin(i.texcoord.y * 3.141569); + i.texcoord.x += waveform * envelope; + w = ( abs(i.texcoord.x - .5) > .5) ? 1 : 0; +#else + w = ( abs(i.texcoord.x - .5) > .45) ? 1 : 0; + w += ( abs(i.texcoord.y - .5) > .45) ? 1 : 0; +#endif + //float angle = atan2(i.texcoord.x, i.texcoord.y); + //w += ( abs(angle - (3.14/4.0)) < .05) ? 1 : 0; + float4 color = i.color * w; + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Additive.shader b/Assets/Resources/Brushes/Shared/Shaders/Additive.shader index 84a2e89ec7..7adb7f93a8 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Additive.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Additive.shader @@ -1,97 +1,114 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Additive" { -Properties { - _MainTex ("Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); -#ifdef AUDIO_REACTIVE - o.color = musicReactiveColor(v.color, _BeatOutput.w); - v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.w, o.texcoord.x); -#else - o.color = v.color; -#endif - o.pos = UnityObjectToClipPos(v.vertex); - - return o; - - } - - fixed4 frag (v2f i) : COLOR - { - half4 c = tex2D(_MainTex, i.texcoord); - c = i.color * c; - FRAG_MOBILESELECT(c) - return encodeHdr(c.rgb * c.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Additive" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + + _Opacity("Opacity", Range(0,1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float2 id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); +#ifdef AUDIO_REACTIVE + o.color = musicReactiveColor(v.color, _BeatOutput.w); + v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.w, o.texcoord.x); +#else + o.color = v.color; +#endif + o.pos = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + half4 c = tex2D(_MainTex, i.texcoord); + c = i.color * c; + FRAG_MOBILESELECT(c) + c = encodeHdr(c.rgb * c.a); + return c * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Bloom.shader b/Assets/Resources/Brushes/Shared/Shaders/Bloom.shader index 9bfc021ac5..f27fa190c7 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Bloom.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Bloom.shader @@ -1,120 +1,138 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Bloom" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - // Split into two different LOD passes as the 200 lod (mobile) needs to use a different - // blend mode than standard. - CGINCLUDE - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _EmissionGain; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = bloomColor(v.color, _EmissionGain); -#ifdef AUDIO_REACTIVE - o.color = musicReactiveColor(o.color, _BeatOutput.y); - v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.y, o.texcoord.x); -#endif - o.pos = UnityObjectToClipPos(v.vertex); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - float4 color = i.color * tex2D(_MainTex, i.texcoord); - color = float4(color.rgb * color.a, 1.0); - color = SrgbToNative(color); - color = encodeHdr(color.rgb); - FRAG_MOBILESELECT(color) - return color; - } - - ENDCG - - // PC (Uses 'Add' blend mode for RGB) - SubShader { - LOD 201 - Pass { - BlendOp Add, Min - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - ENDCG - } - } - - // Mobile (Uses 'Max' blend mode for RGB) - SubShader { - LOD 150 - Pass { - BlendOp Max, Min - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Bloom" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + // Split into two different LOD passes as the 200 lod (mobile) needs to use a different + // blend mode than standard. + CGINCLUDE + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float4 color : COLOR; + float2 texcoord : TEXCOORD0; + float2 id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = bloomColor(v.color, _EmissionGain); +#ifdef AUDIO_REACTIVE + o.color = musicReactiveColor(o.color, _BeatOutput.y); + v.vertex = musicReactiveAnimation(v.vertex, v.color, _BeatOutput.y, o.texcoord.x); +#endif + o.pos = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + // It's hard to get alpha curves right so use dithering for hdr shaders + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + float4 color = i.color * tex2D(_MainTex, i.texcoord); + color = float4(color.rgb * color.a, 1.0); + color = SrgbToNative(color); + color = encodeHdr(color.rgb); + FRAG_MOBILESELECT(color) + return color * _Dissolve; + } + + ENDCG + + // PC (Uses 'Add' blend mode for RGB) + SubShader { + LOD 201 + Pass { + BlendOp Add, Min + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } + + // Mobile (Uses 'Max' blend mode for RGB) + // @andybak - why? Is this a performance thing or a compatibility thing? And is it still needed? + SubShader { + LOD 150 + Pass { + BlendOp Max, Min + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/DiffuseDoubleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/DiffuseDoubleSided.shader index dd9949c5ef..7bf79adfc1 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/DiffuseDoubleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/DiffuseDoubleSided.shader @@ -1,116 +1,177 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/DiffuseDoubleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - -SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 200 - Cull Off - -CGPROGRAM -#pragma surface surf Lambert vertex:vert addshadow -#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM -#pragma multi_compile __ SELECTION_ON -// Faster compiles -#pragma skip_variants INSTANCING_ON -#include "Assets/Shaders/Include/Brush.cginc" -#include "Assets/Shaders/Include/MobileSelection.cginc" -#pragma target 3.0 - -sampler2D _MainTex; -fixed4 _Color; -fixed _Cutoff; - -struct appdata { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float2 texcoord1 : TEXCOORD1; - float2 texcoord2 : TEXCOORD2; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - UNITY_VERTEX_INPUT_INSTANCE_ID -}; - -struct Input { - float2 uv_MainTex; - float4 color : COLOR; - fixed vface : VFACE; -}; - -void vert (inout appdata v, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); -} - -void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; - if (o.Alpha < _Cutoff) { - discard; - } - o.Alpha = 1; - o.Normal = float3(0,0,IN.vface); - SURF_FRAG_MOBILESELECT(o); -} - -ENDCG -} - - -// MOBILE VERSION -SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 100 - Cull Off - -CGPROGRAM -#pragma surface surf Lambert vertex:vert alphatest:_Cutoff -#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM -#include "Assets/Shaders/Include/Brush.cginc" -#pragma target 3.0 - -sampler2D _MainTex; -fixed4 _Color; - -struct Input { - float2 uv_MainTex; - float4 color : COLOR; - fixed vface : VFACE; -}; - -void vert (inout appdata_full v) { - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); -} - -void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; - o.Normal = float3(0,0,IN.vface); -} -ENDCG -} - -Fallback "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/DiffuseDoubleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 200 + Cull Off + +CGPROGRAM +#pragma surface surf Lambert vertex:vert addshadow +#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM +#pragma multi_compile __ SELECTION_ON +// Faster compiles +#pragma skip_variants INSTANCING_ON +#include "Assets/Shaders/Include/Brush.cginc" +#include "Assets/Shaders/Include/MobileSelection.cginc" +#pragma target 4.0 + +sampler2D _MainTex; +fixed4 _Color; +fixed _Cutoff; + +uniform half _ClipStart; +uniform half _ClipEnd; +uniform half _Dissolve; + +struct appdata { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float2 texcoord1 : TEXCOORD1; + float2 texcoord2 : TEXCOORD2; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct Input { + float2 uv_MainTex; + float4 color : COLOR; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 vertex : POSITION; + float4 screenPos; +}; + +struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + o.vertex = UnityObjectToClipPos(v.vertex); + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + o.id = v.id; +} + +void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; + if (o.Alpha < _Cutoff) { + discard; + } + o.Alpha = 1; + o.Normal = float3(0,0,IN.vface); + SURF_FRAG_MOBILESELECT(o); +} + +ENDCG +} + + +// MOBILE VERSION +SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 100 + Cull Off + +CGPROGRAM +#pragma surface surf Lambert vertex:vert alphatest:_Cutoff +#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM +#include "Assets/Shaders/Include/Brush.cginc" +#pragma target 4.0 + +sampler2D _MainTex; +fixed4 _Color; + +uniform half _ClipStart; +uniform half _ClipEnd; +uniform half _Dissolve; + +struct Input { + float2 uv_MainTex; + float4 color : COLOR; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 vertex : POSITION; + float4 screenPos; +}; + +struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + o.id = v.id; +} + +void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; + o.Normal = float3(0,0,IN.vface); +} +ENDCG +} + +Fallback "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueDoubleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueDoubleSided.shader index 998774162d..a1336c05bb 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueDoubleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueDoubleSided.shader @@ -1,71 +1,92 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/DiffuseOpaqueDoubleSided" { - -Properties { - _Color ("Main Color", Color) = (1,1,1,1) -} - -SubShader { - - Cull Off - - CGPROGRAM - #pragma surface surf Lambert vertex:vert addshadow - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - - #pragma target 3.0 - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - fixed4 _Color; - - struct appdata { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float2 texcoord1 : TEXCOORD1; - float2 texcoord2 : TEXCOORD2; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Input { - float4 color : COLOR; - fixed vface : VFACE; - }; - - void vert(inout appdata v, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); - } - - void surf (Input IN, inout SurfaceOutput o) { - o.Albedo = _Color * IN.color.rgb; - o.Normal = float3(0,0,IN.vface); - SURF_FRAG_MOBILESELECT(o); - } - - ENDCG -} // SubShader - -Fallback "Diffuse" - -} // Shader DiffuseOpaqueDoubleSided +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/DiffuseOpaqueDoubleSided" { + +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + + Cull Off + + CGPROGRAM + #pragma surface surf Lambert vertex:vert addshadow + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + + #pragma target 3.0 + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + fixed4 _Color; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float2 texcoord1 : TEXCOORD1; + float2 texcoord2 : TEXCOORD2; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct Input { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 screenPos; + }; + + void vert(inout appdata v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + o.vertex = v.vertex; + o.id = v.id; + } + + void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + o.Albedo = _Color * IN.color.rgb; + o.Normal = float3(0,0,IN.vface); + SURF_FRAG_MOBILESELECT(o); + } + + ENDCG +} // SubShader + +Fallback "Diffuse" + +} // Shader DiffuseOpaqueDoubleSided diff --git a/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueSingleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueSingleSided.shader index df60a431b5..290c8d1695 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueSingleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/DiffuseOpaqueSingleSided.shader @@ -1,55 +1,85 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/DiffuseOpaqueSingleSided" { - -Properties { - _Color ("Main Color", Color) = (1,1,1,1) -} - -SubShader { - Cull Back - - CGPROGRAM - #pragma surface surf Lambert vertex:vert addshadow - - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile __ SELECTION_ON - // Faster compiles - #pragma skip_variants INSTANCING_ON - - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - fixed4 _Color; - - struct Input { - float4 color : COLOR; - }; - - void vert(inout appdata_full v, out Input o) { - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); - UNITY_INITIALIZE_OUTPUT(Input, o); - } - - void surf (Input IN, inout SurfaceOutput o) { - o.Albedo = _Color * IN.color.rgb; - SURF_FRAG_MOBILESELECT(o); - } - ENDCG -} // SubShader - -Fallback "Diffuse" - -} // Shader +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/DiffuseOpaqueSingleSided" { + +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Cull Back + + CGPROGRAM + #pragma surface surf Lambert vertex:vert addshadow + + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile __ SELECTION_ON + // Faster compiles + #pragma skip_variants INSTANCING_ON + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + fixed4 _Color; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float4 color : COLOR; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id v, out Input o) { + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.id = v.id; + } + + void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + o.Albedo = _Color * IN.color.rgb; + SURF_FRAG_MOBILESELECT(o); + } + ENDCG +} // SubShader + +Fallback "Diffuse" + +} // Shader diff --git a/Assets/Resources/Brushes/Shared/Shaders/DiffuseSingleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/DiffuseSingleSided.shader index 047c3897b7..cc8882158f 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/DiffuseSingleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/DiffuseSingleSided.shader @@ -1,92 +1,151 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/DiffuseSingleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - -SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 200 - Cull Back - -CGPROGRAM -#pragma surface surf Lambert vertex:vert alphatest:_Cutoff addshadow -#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM -#pragma multi_compile __ SELECTION_ON -#pragma target 4.0 -#include "Assets/Shaders/Include/Brush.cginc" -#include "Assets/Shaders/Include/MobileSelection.cginc" - -sampler2D _MainTex; -fixed4 _Color; - -struct Input { - float2 uv_MainTex; - float4 color : COLOR; -}; - -void vert (inout appdata_full v, out Input o) { - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); - UNITY_INITIALIZE_OUTPUT(Input, o); -} - -void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; - SURF_FRAG_MOBILESELECT(o); -} - -ENDCG -} - - -// MOBILE VERSION -SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 100 - -CGPROGRAM -#pragma surface surf Lambert vertex:vert alphatest:_Cutoff -#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM -#include "Assets/Shaders/Include/Brush.cginc" - -sampler2D _MainTex; -fixed4 _Color; - -struct Input { - float2 uv_MainTex; - float4 color : COLOR; -}; - -void vert (inout appdata_full v) { - PrepForOds(v.vertex); - v.color = TbVertToNative(v.color); -} - -void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; -} -ENDCG -} - -Fallback "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/DiffuseSingleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 200 + Cull Back + +CGPROGRAM +#pragma surface surf Lambert vertex:vert alphatest:_Cutoff addshadow +#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM +#pragma multi_compile __ SELECTION_ON +#pragma target 4.0 +#include "Assets/Shaders/Include/Brush.cginc" +#include "Assets/Shaders/Include/MobileSelection.cginc" + +sampler2D _MainTex; +fixed4 _Color; + +uniform half _ClipStart; +uniform half _ClipEnd; +uniform half _Dissolve; + +struct Input { + float2 uv_MainTex; + float4 color : COLOR; + uint id : SV_VertexID; + float4 screenPos; +}; + +struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +void vert (inout appdata_full_plus_id v, out Input o) { + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.id = v.id; +} + +void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; + SURF_FRAG_MOBILESELECT(o); +} + +ENDCG +} + + +// MOBILE VERSION +SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 100 + +CGPROGRAM +#pragma surface surf Lambert vertex:vert alphatest:_Cutoff +#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM +#pragma target 4.0 +#include "Assets/Shaders/Include/Brush.cginc" + +sampler2D _MainTex; +fixed4 _Color; + +uniform half _ClipStart; +uniform half _ClipEnd; +uniform half _Dissolve; + +struct Input { + float2 uv_MainTex; + float4 color : COLOR; + uint id : SV_VertexID; + float4 vertex : POSITION; + float4 screenPos; + fixed vface : VFACE; +}; + +struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToNative(v.color); +} + +void surf (Input IN, inout SurfaceOutput o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; +} +ENDCG +} + +Fallback "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Multiplicative.shader b/Assets/Resources/Brushes/Shared/Shaders/Multiplicative.shader index d1e34c826e..38b9a69f21 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Multiplicative.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Multiplicative.shader @@ -1,86 +1,105 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Multiplicative" { -Properties { - _MainTex ("Texture", 2D) = "white" {} -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - // TODO: investigate different blend mode that allows us to remove blend in the frag - Blend DstColor Zero - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - fixed4 frag (v2f i) : COLOR - { - half4 c = tex2D(_MainTex, i.texcoord ); - c = i.color * c; - // TODO: investigate doing this in the blend mode - return lerp(1, c, c.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Multiplicative" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + // TODO: investigate different blend mode that allows us to remove blend in the frag + Blend DstColor Zero + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + half4 c = tex2D(_MainTex, i.texcoord ); + c = i.color * c; + // TODO: investigate doing this in the blend mode + c = lerp(1, c, c.a); + c.a *= _Opacity; + return c; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Special/AdditiveScrolling.shader b/Assets/Resources/Brushes/Shared/Shaders/Special/AdditiveScrolling.shader index 739ba0856f..fc0aeac647 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Special/AdditiveScrolling.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Special/AdditiveScrolling.shader @@ -1,102 +1,107 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/AdditiveScrolling" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 - _FalloffPower("Falloff Power", Float) = 2.0 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend SrcAlpha One - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - }; - - float4 _MainTex_ST; - float _ScrollRate; - float3 _ScrollDistance; - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - float3 _WorldSpaceRootCameraPosition; - half _FalloffPower; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - // Custom vertex animation - float4 worldPos = mul(unity_ObjectToWorld, v.vertex); - float t = fmod(_Time.y*_ScrollRate + v.color.a, 1); - worldPos.xyz += (t - .5f) * _ScrollDistance; - worldPos.x += sin(t * _ScrollJitterFrequency + _Time.y) * _ScrollJitterIntensity; - worldPos.z += cos(t * _ScrollJitterFrequency * .5 + _Time.y) * _ScrollJitterIntensity; - v.color.a = pow(1 - abs(2*(t - .5)),3); - - o.vertex = mul(UNITY_MATRIX_VP, worldPos); - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - - // Edge Falloff - float3 worldSpaceView = normalize(_WorldSpaceRootCameraPosition.xyz - mul(unity_ObjectToWorld, v.vertex).xyz); - float3 worldSpaceNormal = normalize(mul(unity_ObjectToWorld, float4(v.normal.xyz,0))); - float falloff = abs(dot(worldSpaceNormal, worldSpaceView)); - o.color.a *= pow(falloff, _FalloffPower); - - return o; - - } - - fixed4 frag (v2f i) : SV_Target - { - return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/AdditiveScrolling" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + _FalloffPower("Falloff Power", Float) = 2.0 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend SrcAlpha One + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + }; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + }; + + float4 _MainTex_ST; + float _ScrollRate; + float3 _ScrollDistance; + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + float3 _WorldSpaceRootCameraPosition; + half _FalloffPower; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + // Custom vertex animation + float4 worldPos = mul(unity_ObjectToWorld, v.vertex); + float t = fmod(GetTime().y*_ScrollRate + v.color.a, 1); + worldPos.xyz += (t - .5f) * _ScrollDistance; + worldPos.x += sin(t * _ScrollJitterFrequency + GetTime().y) * _ScrollJitterIntensity; + worldPos.z += cos(t * _ScrollJitterFrequency * .5 + GetTime().y) * _ScrollJitterIntensity; + v.color.a = pow(1 - abs(2*(t - .5)),3); + + o.vertex = mul(UNITY_MATRIX_VP, worldPos); + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + + // Edge Falloff + float3 worldSpaceView = normalize(_WorldSpaceRootCameraPosition.xyz - mul(unity_ObjectToWorld, v.vertex).xyz); + float3 worldSpaceNormal = normalize(mul(unity_ObjectToWorld, float4(v.normal.xyz,0))); + float falloff = abs(dot(worldSpaceNormal, worldSpaceView)); + o.color.a *= pow(falloff, _FalloffPower); + + return o; + + } + + fixed4 frag (v2f i) : SV_Target + { + return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord); + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Special/Faceted.shader b/Assets/Resources/Brushes/Shared/Shaders/Special/Faceted.shader index 7d0a208fce..f656727e14 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Special/Faceted.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Special/Faceted.shader @@ -1,80 +1,106 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Faceted" { -Properties { - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} -} - -SubShader { - Cull Back - Pass{ - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - sampler2D _MainTex; - float4 _MainTex_ST; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; - return o; - } - - fixed4 frag (v2f i) : SV_Target - { - float3 n = normalize(cross(ddy(i.worldPos), ddx(i.worldPos))); - i.color.xyz = n.xyz; - return i.color; - } - - ENDCG - } - } -Fallback "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Faceted" { +Properties { + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _ColorX("Color X", Color) = (1,0,0,1) + _ColorY("Color Y", Color) = (0,1,0,1) + _ColorZ("Color Z", Color) = (0,0,1,1) + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Cull Back + Pass{ + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + sampler2D _MainTex; + float4 _MainTex_ST; + fixed4 _ColorX; + fixed4 _ColorY; + fixed4 _ColorZ; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float3 worldPos : TEXCOORD1; + float2 id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float3 n = normalize(cross(ddy(i.worldPos), ddx(i.worldPos))); + i.color.xyz = float3( + lerp(float3(0,0,0), _ColorX, n.x) + + lerp(float3(0,0,0), _ColorY, n.y) + + lerp(float3(0,0,0), _ColorZ, n.z) + ); + return i.color; + } + + ENDCG + } + } +Fallback "Diffuse" +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/StandardDoubleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/StandardDoubleSided.shader index 14cc71854a..f3ca4b3a78 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/StandardDoubleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/StandardDoubleSided.shader @@ -1,573 +1,688 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/StandardDoubleSided" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - - // -------------------------------------------------------------------------------------------- // - // DESKTOP VERSION. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 400 - Cull Off - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - fixed vface : VFACE; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full i /*, out Input o*/) { - // UNITY_INITIALIZE_OUTPUT(Input, o); - // o.tangent = v.tangent; - PrepForOds(i.vertex); - i.color = TbVertToNative(i.color); - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; - o.Smoothness = _Shininess; - o.Specular = _SpecColor; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Normal.z *= IN.vface; - - o.Alpha = tex.a * IN.color.a; - } - ENDCG - } - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Vert/Frag, MSAA + Alpha-To-Coverage, w/Bump. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } - Cull off - LOD 201 - - Pass { - Tags { "LightMode"="ForwardBase" } - AlphaToMask On - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - half3 tspace0 : TEXCOORD1; - half3 tspace1 : TEXCOORD2; - half3 tspace2 : TEXCOORD3; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - float4 _MainTex_TexelSize; - sampler2D _BumpMap; - - fixed _Cutoff; - half _MipScale; - - float ComputeMipLevel(float2 uv) { - float2 dx = ddx(uv); - float2 dy = ddy(uv); - float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); - return max(0.0, 0.5 * log2(delta_max_sqr)); - } - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - - half3 wNormal = UnityObjectToWorldNormal(v.normal); - half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); - half tangentSign = v.tangent.w * unity_WorldTransformParams.w; - half3 wBitangent = cross(wNormal, wTangent) * tangentSign; - o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); - o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); - o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = tex2D(_MainTex, i.uv).a * col.a; - col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; - col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; - - half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); - tnormal.z *= vface; - - // Transform normal from tangent to world space. - half3 worldNormal; - worldNormal.x = dot(i.tspace0, tnormal); - worldNormal.y = dot(i.tspace1, tnormal); - worldNormal.z = dot(i.tspace2, tnormal); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - - return col; - } - - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Vert/Frag, Alpha Tested, w/Bump. - // -------------------------------------------------------------------------------------------- // - SubShader{ - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull off - LOD 200 - - Pass { - Tags { "LightMode"="ForwardBase" } - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile __ SELECTION_ON - #pragma multi_compile_fog - - #include "UnityCG.cginc" - #include "Lighting.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - fixed4 color : COLOR; - half3 tspace0 : TEXCOORD1; - half3 tspace1 : TANGENT; - half3 tspace2 : NORMAL; - float4 worldPos : TEXCOORD4; - UNITY_FOG_COORDS(5) - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - sampler2D _BumpMap; - half _Shininess; - - fixed _Cutoff; - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.color = v.color; - - half3 wNormal = UnityObjectToWorldNormal(v.normal); - half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); - half tangentSign = v.tangent.w * unity_WorldTransformParams.w; - half3 wBitangent = cross(wNormal, wTangent) * tangentSign; - o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); - o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); - o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); - o.worldPos = mul (unity_ObjectToWorld, v.vertex); - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = tex2D(_MainTex, i.uv).a * col.a; - if (col.a < _Cutoff) { discard; } - - // The standard shader we have desaturates the color of objects depending on the - // brightness of their specular color - this seems to be a reasonable emulation. - float desaturated = dot(col, float3(0.3, 0.59, 0.11)); - col.rgb = lerp(col, desaturated, _SpecColor * 1.2); - - col.a = 1; - half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); - tnormal.z *= vface; - - // transform normal from tangent to world space - half3 worldNormal; - worldNormal.x = dot(i.tspace0, tnormal); - worldNormal.y = dot(i.tspace1, tnormal); - worldNormal.z = dot(i.tspace2, tnormal); - - fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz); - fixed ndotl = saturate(dot(worldNormal, worldLightDir)); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - col.rgb *= lighting; - - // Add in some (modified) Phong specular highlights. - float3 viewDir = normalize(_WorldSpaceCameraPos - i.worldPos.xyz); - float3 lightreflect = reflect(-worldLightDir, worldNormal); - // The magic numbers here are generated by hand to try and match the specular highlights - // generated by the surface shader on a scale between duct tape and shiny hull. - float ratio = (_Shininess - 0.4) / 0.35; // ratio of shininess between duct tape and hull. - float power = clamp(4 + ratio * 10, 1, 14); - float strength = 1 + 3 * ratio; - float specComponent = pow(max(0, dot(lightreflect, viewDir)), power) * strength; - float3 specCol = _SpecColor * _LightColor0 * specComponent; - col.rgb += specCol; - UNITY_APPLY_FOG(i.fogCoord, col); - FRAG_MOBILESELECT(col) - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Vert/Frag, NO ALPHA TEST, w/Bump. - // -------------------------------------------------------------------------------------------- // - SubShader{ - Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } - Cull off - LOD 199 - - Pass { - Tags { "LightMode"="ForwardBase" } - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - half3 tspace0 : TEXCOORD1; - half3 tspace1 : TEXCOORD2; - half3 tspace2 : TEXCOORD3; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - sampler2D _BumpMap; - - fixed _Cutoff; - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - - half3 wNormal = UnityObjectToWorldNormal(v.normal); - half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); - half tangentSign = v.tangent.w * unity_WorldTransformParams.w; - half3 wBitangent = cross(wNormal, wTangent) * tangentSign; - o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); - o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); - o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = tex2D(_MainTex, i.uv).a * col.a; - //if (col.a < _Cutoff) { discard; } - half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); - tnormal.z *= vface; - - // transform normal from tangent to world space - half3 worldNormal; - worldNormal.x = dot(i.tspace0, tnormal); - worldNormal.y = dot(i.tspace1, tnormal); - worldNormal.z = dot(i.tspace2, tnormal); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION -- vert/frag, MSAA + Alpha-To-Coverage, No Bump. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } - Cull Off - LOD 150 - - Pass { - Tags { "LightMode"="ForwardBase" } - AlphaToMask On - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - float4 _MainTex_TexelSize; - - fixed _Cutoff; - half _MipScale; - - float ComputeMipLevel(float2 uv) { - float2 dx = ddx(uv); - float2 dy = ddy(uv); - float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); - return max(0.0, 0.5 * log2(delta_max_sqr)); - } - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a *= tex2D(_MainTex, i.uv).a; - col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; - col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; - - half3 worldNormal = normalize(i.worldNormal * vface); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - - // TODO: only apply a discard when MSAA is disabled. This kills the nicely - // anti-aliased edges above, however that anti-aliasing manifests as bloom when in LDR - // mode. - if (col.a < _Cutoff) { - discard; - } - col.a = 1.0; - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION -- vert/frag, NO CUTOUT, NO BUMP. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } - Cull Off - LOD 149 - - Pass { - Tags { "LightMode"="ForwardBase" } - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - float4 _MainTex_TexelSize; - - fixed _Cutoff; - half _MipScale; - - float ComputeMipLevel(float2 uv) { - float2 dx = ddx(uv); - float2 dy = ddy(uv); - float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); - return max(0.0, 0.5 * log2(delta_max_sqr)); - } - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = 1; - - half3 worldNormal = normalize(i.worldNormal * vface); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Lambert SurfaceShader, Alpha Test, No Bump. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 50 - Cull Off - - CGPROGRAM - #pragma surface surf Lambert vertex:vert alphatest:_Cutoff - #pragma target 3.0 - - sampler2D _MainTex; - fixed4 _Color; - - struct Input { - float2 uv_MainTex; - float4 color : COLOR; - fixed vface : VFACE; - }; - - void vert (inout appdata_full v) { - } - - void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; - o.Normal = float3(0,0,IN.vface); - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/StandardDoubleSided" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + + // -------------------------------------------------------------------------------------------- // + // DESKTOP VERSION. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 400 + Cull Off + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert (inout appdata_full_plus_id i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + // o.tangent = v.tangent; + PrepForOds(i.vertex); + i.color = TbVertToNative(i.color); + o.id = i.id; + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; + o.Smoothness = _Shininess; + o.Specular = _SpecColor; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Normal.z *= IN.vface; + + o.Alpha = tex.a * IN.color.a; + } + ENDCG + } + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Vert/Frag, MSAA + Alpha-To-Coverage, w/Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull off + LOD 201 + + Pass { + Tags { "LightMode"="ForwardBase" } + AlphaToMask On + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + half3 tspace0 : TEXCOORD1; + half3 tspace1 : TEXCOORD2; + half3 tspace2 : TEXCOORD3; + uint id : TEXCOORD4; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _MainTex_TexelSize; + sampler2D _BumpMap; + + fixed _Cutoff; + half _MipScale; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + float ComputeMipLevel(float2 uv) { + float2 dx = ddx(uv); + float2 dy = ddy(uv); + float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); + return max(0.0, 0.5 * log2(delta_max_sqr)); + } + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + + half3 wNormal = UnityObjectToWorldNormal(v.normal); + half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 wBitangent = cross(wNormal, wTangent) * tangentSign; + o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); + o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); + o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = tex2D(_MainTex, i.uv).a * col.a; + col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; + col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; + + half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); + tnormal.z *= vface; + + // Transform normal from tangent to world space. + half3 worldNormal; + worldNormal.x = dot(i.tspace0, tnormal); + worldNormal.y = dot(i.tspace1, tnormal); + worldNormal.z = dot(i.tspace2, tnormal); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + + return col; + } + + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Vert/Frag, Alpha Tested, w/Bump. + // -------------------------------------------------------------------------------------------- // + SubShader{ + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } + Cull off + LOD 200 + + Pass { + Tags { "LightMode"="ForwardBase" } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile __ SELECTION_ON + #pragma multi_compile_fog + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + fixed4 color : COLOR; + half3 tspace0 : TEXCOORD1; + half3 tspace1 : TANGENT; + half3 tspace2 : NORMAL; + float4 worldPos : TEXCOORD4; + float2 id : TEXCOORD6; + UNITY_FOG_COORDS(5) + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + sampler2D _BumpMap; + half _Shininess; + + fixed _Cutoff; + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + half3 wNormal = UnityObjectToWorldNormal(v.normal); + half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 wBitangent = cross(wNormal, wTangent) * tangentSign; + o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); + o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); + o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); + o.worldPos = mul (unity_ObjectToWorld, v.vertex); + UNITY_TRANSFER_FOG(o, o.pos); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = tex2D(_MainTex, i.uv).a * col.a; + if (col.a < _Cutoff) { discard; } + + // The standard shader we have desaturates the color of objects depending on the + // brightness of their specular color - this seems to be a reasonable emulation. + float desaturated = dot(col, float3(0.3, 0.59, 0.11)); + col.rgb = lerp(col, desaturated, _SpecColor * 1.2); + + col.a = 1; + half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); + tnormal.z *= vface; + + // transform normal from tangent to world space + half3 worldNormal; + worldNormal.x = dot(i.tspace0, tnormal); + worldNormal.y = dot(i.tspace1, tnormal); + worldNormal.z = dot(i.tspace2, tnormal); + + fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz); + fixed ndotl = saturate(dot(worldNormal, worldLightDir)); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + col.rgb *= lighting; + + // Add in some (modified) Phong specular highlights. + float3 viewDir = normalize(_WorldSpaceCameraPos - i.worldPos.xyz); + float3 lightreflect = reflect(-worldLightDir, worldNormal); + // The magic numbers here are generated by hand to try and match the specular highlights + // generated by the surface shader on a scale between duct tape and shiny hull. + float ratio = (_Shininess - 0.4) / 0.35; // ratio of shininess between duct tape and hull. + float power = clamp(4 + ratio * 10, 1, 14); + float strength = 1 + 3 * ratio; + float specComponent = pow(max(0, dot(lightreflect, viewDir)), power) * strength; + float3 specCol = _SpecColor * _LightColor0 * specComponent; + col.rgb += specCol; + UNITY_APPLY_FOG(i.fogCoord, col); + FRAG_MOBILESELECT(col) + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Vert/Frag, NO ALPHA TEST, w/Bump. + // -------------------------------------------------------------------------------------------- // + SubShader{ + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull off + LOD 199 + + Pass { + Tags { "LightMode"="ForwardBase" } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + half3 tspace0 : TEXCOORD1; + half3 tspace1 : TEXCOORD2; + half3 tspace2 : TEXCOORD3; + uint id : TEXCOORD4; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + sampler2D _BumpMap; + + fixed _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + + half3 wNormal = UnityObjectToWorldNormal(v.normal); + half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 wBitangent = cross(wNormal, wTangent) * tangentSign; + o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); + o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); + o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = tex2D(_MainTex, i.uv).a * col.a; + //if (col.a < _Cutoff) { discard; } + half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); + tnormal.z *= vface; + + // transform normal from tangent to world space + half3 worldNormal; + worldNormal.x = dot(i.tspace0, tnormal); + worldNormal.y = dot(i.tspace1, tnormal); + worldNormal.z = dot(i.tspace2, tnormal); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION -- vert/frag, MSAA + Alpha-To-Coverage, No Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull Off + LOD 150 + + Pass { + Tags { "LightMode"="ForwardBase" } + AlphaToMask On + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + uint id : TEXCOORD2; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _MainTex_TexelSize; + + fixed _Cutoff; + half _MipScale; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + float ComputeMipLevel(float2 uv) { + float2 dx = ddx(uv); + float2 dy = ddy(uv); + float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); + return max(0.0, 0.5 * log2(delta_max_sqr)); + } + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a *= tex2D(_MainTex, i.uv).a; + col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; + col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; + + half3 worldNormal = normalize(i.worldNormal * vface); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + + // TODO: only apply a discard when MSAA is disabled. This kills the nicely + // anti-aliased edges above, however that anti-aliasing manifests as bloom when in LDR + // mode. + if (col.a < _Cutoff) { + discard; + } + col.a = 1.0; + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION -- vert/frag, NO CUTOUT, NO BUMP. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull Off + LOD 149 + + Pass { + Tags { "LightMode"="ForwardBase" } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + uint id : TEXCOORD2; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _MainTex_TexelSize; + + fixed _Cutoff; + half _MipScale; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + float ComputeMipLevel(float2 uv) { + float2 dx = ddx(uv); + float2 dy = ddy(uv); + float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); + return max(0.0, 0.5 * log2(delta_max_sqr)); + } + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = 1; + + half3 worldNormal = normalize(i.worldNormal * vface); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Lambert SurfaceShader, Alpha Test, No Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 50 + Cull Off + + CGPROGRAM + #pragma surface surf Lambert vertex:vert alphatest:_Cutoff + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + + sampler2D _MainTex; + fixed4 _Color; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float2 uv_MainTex; + float4 color : COLOR; + fixed vface : VFACE; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + o.id = v.id; + } + + void surf (Input IN, inout SurfaceOutput o) { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; + o.Normal = float3(0,0,IN.vface); + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/StandardSingleSided.shader b/Assets/Resources/Brushes/Shared/Shaders/StandardSingleSided.shader index 5985ea80a5..6388c1216f 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/StandardSingleSided.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/StandardSingleSided.shader @@ -1,376 +1,461 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/StandardSingleSided" { - Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap ("Normalmap", 2D) = "bump" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 - } - - // -------------------------------------------------------------------------------------------- // - // DESKTOP VERSION. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 400 - Cull Back - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full i /*, out Input o*/) { - // UNITY_INITIALIZE_OUTPUT(Input, o); - // o.tangent = v.tangent; - PrepForOds(i.vertex); - i.color = TbVertToNative(i.color); - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; - o.Smoothness = _Shininess; - o.Specular = _SpecColor; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Alpha = tex.a * IN.color.a; - } - ENDCG - } - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Vert/Frag, MSAA + Alpha-To-Coverage, w/Bump. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull Back - LOD 201 - - Pass { - Tags { "LightMode"="ForwardBase" } - AlphaToMask On - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - half3 tspace0 : TEXCOORD1; - half3 tspace1 : TEXCOORD2; - half3 tspace2 : TEXCOORD3; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - float4 _MainTex_TexelSize; - sampler2D _BumpMap; - - fixed _Cutoff; - half _MipScale; - - float ComputeMipLevel(float2 uv) { - float2 dx = ddx(uv); - float2 dy = ddy(uv); - float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); - return max(0.0, 0.5 * log2(delta_max_sqr)); - } - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - - half3 wNormal = UnityObjectToWorldNormal(v.normal); - half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); - half tangentSign = v.tangent.w * unity_WorldTransformParams.w; - half3 wBitangent = cross(wNormal, wTangent) * tangentSign; - o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); - o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); - o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = tex2D(_MainTex, i.uv).a * col.a; - col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; - col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; - - half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); - tnormal.z *= vface; - - // Transform normal from tangent to world space. - half3 worldNormal; - worldNormal.x = dot(i.tspace0, tnormal); - worldNormal.y = dot(i.tspace1, tnormal); - worldNormal.z = dot(i.tspace2, tnormal); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - - return col; - } - - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Vert/Frag, Alpha Tested, w/Bump. - // -------------------------------------------------------------------------------------------- // - SubShader{ - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull Back - LOD 200 - - Pass { - Tags { "LightMode"="ForwardBase" } - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - #pragma multi_compile __ SELECTION_ON - #pragma multi_compile_fog - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - float4 tangent : TANGENT; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - fixed4 color : COLOR; - half3 tspace0 : TEXCOORD1; - half3 tspace1 : TANGENT; - half3 tspace2 : NORMAL; - UNITY_FOG_COORDS(5) - - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - sampler2D _BumpMap; - - fixed _Cutoff; - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.color = v.color; - - half3 wNormal = UnityObjectToWorldNormal(v.normal); - half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); - half tangentSign = v.tangent.w * unity_WorldTransformParams.w; - half3 wBitangent = cross(wNormal, wTangent) * tangentSign; - o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); - o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); - o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a = tex2D(_MainTex, i.uv).a * col.a; - if (col.a < _Cutoff) { discard; } - half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); - tnormal.z *= vface; - - // transform normal from tangent to world space - half3 worldNormal; - worldNormal.x = dot(i.tspace0, tnormal); - worldNormal.y = dot(i.tspace1, tnormal); - worldNormal.z = dot(i.tspace2, tnormal); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - UNITY_APPLY_FOG(i.fogCoord, col); - FRAG_MOBILESELECT(col) - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION -- vert/frag, MSAA + Alpha-To-Coverage, No Bump. - // -------------------------------------------------------------------------------------------- // - SubShader { - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull Back - LOD 150 - - Pass { - Tags { "LightMode"="ForwardBase" } - AlphaToMask On - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Lighting.cginc" - - // Disable all the things. - #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow - - struct appdata { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - half3 normal : NORMAL; - fixed4 color : COLOR; - }; - - struct v2f { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - half3 worldNormal : NORMAL; - fixed4 color : COLOR; - }; - - sampler2D _MainTex; - float4 _MainTex_ST; - float4 _MainTex_TexelSize; - - fixed _Cutoff; - half _MipScale; - - float ComputeMipLevel(float2 uv) { - float2 dx = ddx(uv); - float2 dy = ddy(uv); - float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); - return max(0.0, 0.5 * log2(delta_max_sqr)); - } - - v2f vert (appdata v) { - v2f o; - o.pos = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - o.worldNormal = UnityObjectToWorldNormal(v.normal); - o.color = v.color; - return o; - } - - fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { - fixed4 col = i.color; - col.a *= tex2D(_MainTex, i.uv).a; - col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; - col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; - - half3 worldNormal = normalize(i.worldNormal * vface); - - fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); - fixed3 lighting = ndotl * _LightColor0; - lighting += ShadeSH9(half4(worldNormal, 1.0)); - - col.rgb *= lighting; - - return col; - } - ENDCG - } // pass - } // subshader - - // -------------------------------------------------------------------------------------------- // - // MOBILE VERSION - Lambert SurfaceShader, Alpha Test, No Bump. - // -------------------------------------------------------------------------------------------- // - SubShader{ - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - LOD 50 - - CGPROGRAM - #pragma surface surf Lambert vertex:vert alphatest:_Cutoff - #pragma target 3.0 - - sampler2D _MainTex; - fixed4 _Color; - - struct Input { - float2 uv_MainTex; - float4 color : COLOR; - }; - - void vert (inout appdata_full v) { - } - - void surf (Input IN, inout SurfaceOutput o) { - fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; - o.Albedo = c.rgb * IN.color.rgb; - o.Alpha = c.a * IN.color.a; - } - - ENDCG - } // SubShader - - FallBack "Transparent/Cutout/VertexLit" -} // shader +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/StandardSingleSided" { + Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap ("Normalmap", 2D) = "bump" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + // -------------------------------------------------------------------------------------------- // + // DESKTOP VERSION. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 400 + Cull Back + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + void vert (inout appdata_full_plus_id i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + // o.tangent = v.tangent; + PrepForOds(i.vertex); + i.color = TbVertToNative(i.color); + o.id = i.id; + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; + o.Smoothness = _Shininess; + o.Specular = _SpecColor; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Alpha = tex.a * IN.color.a; + } + ENDCG + } + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Vert/Frag, MSAA + Alpha-To-Coverage, w/Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull Back + LOD 201 + + Pass { + Tags { "LightMode"="ForwardBase" } + AlphaToMask On + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + half3 tspace0 : TEXCOORD1; + half3 tspace1 : TEXCOORD2; + half3 tspace2 : TEXCOORD3; + uint id : TEXCOORD4; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _MainTex_TexelSize; + sampler2D _BumpMap; + + fixed _Cutoff; + half _MipScale; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + float ComputeMipLevel(float2 uv) { + float2 dx = ddx(uv); + float2 dy = ddy(uv); + float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); + return max(0.0, 0.5 * log2(delta_max_sqr)); + } + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + + half3 wNormal = UnityObjectToWorldNormal(v.normal); + half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 wBitangent = cross(wNormal, wTangent) * tangentSign; + o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); + o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); + o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = tex2D(_MainTex, i.uv).a * col.a; + col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; + col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; + + half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); + tnormal.z *= vface; + + // Transform normal from tangent to world space. + half3 worldNormal; + worldNormal.x = dot(i.tspace0, tnormal); + worldNormal.y = dot(i.tspace1, tnormal); + worldNormal.z = dot(i.tspace2, tnormal); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + + return col; + } + + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Vert/Frag, Alpha Tested, w/Bump. + // -------------------------------------------------------------------------------------------- // + SubShader{ + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } + Cull Back + LOD 200 + + Pass { + Tags { "LightMode"="ForwardBase" } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile __ SELECTION_ON + #pragma multi_compile_fog + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + float4 tangent : TANGENT; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + fixed4 color : COLOR; + half3 tspace0 : TEXCOORD1; + half3 tspace1 : TANGENT; + half3 tspace2 : NORMAL; + float4 worldPos : TEXCOORD4; + float2 id : TEXCOORD5; + UNITY_FOG_COORDS(6) + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + sampler2D _BumpMap; + half _Shininess; + + fixed _Cutoff; + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + half3 wNormal = UnityObjectToWorldNormal(v.normal); + half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 wBitangent = cross(wNormal, wTangent) * tangentSign; + o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x); + o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y); + o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); + o.worldPos = mul (unity_ObjectToWorld, v.vertex); + UNITY_TRANSFER_FOG(o, o.pos); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a = tex2D(_MainTex, i.uv).a * col.a; + if (col.a < _Cutoff) { discard; } + + // The standard shader we have desaturates the color of objects depending on the + // brightness of their specular color - this seems to be a reasonable emulation. + float desaturated = dot(col, float3(0.3, 0.59, 0.11)); + col.rgb = lerp(col, desaturated, _SpecColor * 1.2); + + col.a = 1; + half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv)); + tnormal.z *= vface; + + // transform normal from tangent to world space + half3 worldNormal; + worldNormal.x = dot(i.tspace0, tnormal); + worldNormal.y = dot(i.tspace1, tnormal); + worldNormal.z = dot(i.tspace2, tnormal); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + col.rgb *= lighting; + UNITY_APPLY_FOG(i.fogCoord, col); + FRAG_MOBILESELECT(col) + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION -- vert/frag, MSAA + Alpha-To-Coverage, No Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" } + Cull Back + LOD 150 + + Pass { + Tags { "LightMode"="ForwardBase" } + AlphaToMask On + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + + // Disable all the things. + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight noshadow + + struct appdata { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half3 normal : NORMAL; + fixed4 color : COLOR; + uint id : SV_VertexID; + }; + + struct v2f { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + half3 worldNormal : NORMAL; + fixed4 color : COLOR; + uint id : TEXCOORD2; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _MainTex_TexelSize; + + fixed _Cutoff; + half _MipScale; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + float ComputeMipLevel(float2 uv) { + float2 dx = ddx(uv); + float2 dy = ddy(uv); + float delta_max_sqr = max(dot(dx, dx), dot(dy, dy)); + return max(0.0, 0.5 * log2(delta_max_sqr)); + } + + v2f vert (appdata v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.color = v.color; + return o; + } + + fixed4 frag (v2f i, fixed vface : VFACE) : SV_Target { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 col = i.color; + col.a *= tex2D(_MainTex, i.uv).a; + col.a *= 1 + max(0, ComputeMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale; + col.a = (col.a - _Cutoff) / max(2 * fwidth(col.a), 0.0001) + 0.5; + + half3 worldNormal = normalize(i.worldNormal * vface); + + fixed ndotl = saturate(dot(worldNormal, normalize(_WorldSpaceLightPos0.xyz))); + fixed3 lighting = ndotl * _LightColor0; + lighting += ShadeSH9(half4(worldNormal, 1.0)); + + col.rgb *= lighting; + + return col; + } + ENDCG + } // pass + } // subshader + + // -------------------------------------------------------------------------------------------- // + // MOBILE VERSION - Lambert SurfaceShader, Alpha Test, No Bump. + // -------------------------------------------------------------------------------------------- // + SubShader { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + LOD 50 + Cull Back + + CGPROGRAM + #pragma surface surf Lambert vertex:vert alphatest:_Cutoff + #pragma target 3.0 + + #include "Assets/Shaders/Include/Brush.cginc" + + sampler2D _MainTex; + fixed4 _Color; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float2 uv_MainTex; + float4 color : COLOR; + uint id : SV_VertexID; + float4 screenPos; + }; + + void vert (inout appdata_full v) { + } + + void surf (Input IN, inout SurfaceOutput o) { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb * IN.color.rgb; + o.Alpha = c.a * IN.color.a; + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/Brushes/Shared/Shaders/Unlit.shader b/Assets/Resources/Brushes/Shared/Shaders/Unlit.shader index 4042dae5a7..1a298b7f48 100644 --- a/Assets/Resources/Brushes/Shared/Shaders/Unlit.shader +++ b/Assets/Resources/Brushes/Shared/Shaders/Unlit.shader @@ -1,96 +1,110 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Unlit" { - -Properties { - _MainTex ("Texture", 2D) = "white" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 -} - -SubShader { - Pass { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - Lighting Off - Cull Off - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile_fog - #pragma multi_compile __ SELECTION_ON - #include "Assets/Shaders/Include/Brush.cginc" - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/MobileSelection.cginc" - - sampler2D _MainTex; - float _Cutoff; - - - - struct appdata_t { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 pos : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - UNITY_FOG_COORDS(1) - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.pos = UnityObjectToClipPos(v.vertex); - o.texcoord = v.texcoord; - o.color = TbVertToNative(v.color); - UNITY_TRANSFER_FOG(o, o.pos); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - fixed4 c; - UNITY_APPLY_FOG(i.fogCoord, i.color); - c = tex2D(_MainTex, i.texcoord) * i.color; - if (c.a < _Cutoff) { - discard; - } - c.a = 1; - FRAG_MOBILESELECT(c) - return c; - } - - ENDCG - } -} - -Fallback "Unlit/Diffuse" - -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Unlit" { + +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Pass { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + Lighting Off + Cull Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile_fog + #pragma multi_compile __ SELECTION_ON + #include "Assets/Shaders/Include/Brush.cginc" + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/MobileSelection.cginc" + + sampler2D _MainTex; + float _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 pos : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + float2 id : TEXCOORD2; + UNITY_FOG_COORDS(1) + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord = v.texcoord; + o.id = (float2)v.id; + o.color = TbVertToNative(v.color); + UNITY_TRANSFER_FOG(o, o.pos); + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + fixed4 c; + UNITY_APPLY_FOG(i.fogCoord, i.color); + c = tex2D(_MainTex, i.texcoord) * i.color; + if (c.a < _Cutoff) { + discard; + } + c.a = 1; + FRAG_MOBILESELECT(c) + return c; + } + + ENDCG + } +} + +Fallback "Unlit/Diffuse" + +} diff --git a/Assets/Resources/X/Brushes/BubbleWand/BubbleWand.shader b/Assets/Resources/X/Brushes/BubbleWand/BubbleWand.shader index 23e2d4c950..4fee67bd5a 100644 --- a/Assets/Resources/X/Brushes/BubbleWand/BubbleWand.shader +++ b/Assets/Resources/X/Brushes/BubbleWand/BubbleWand.shader @@ -1,108 +1,148 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/BubbleWand" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 -} - - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - Cull off ZWrite Off - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - float _EmissionGain; - float _ScrollRate; - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - - float4 displace(float4 pos, float timeOffset) { - float t = _Time.y*_ScrollRate + timeOffset; - - pos.x += sin(t + _Time.y + pos.z * _ScrollJitterFrequency) * _ScrollJitterIntensity; - pos.z += cos(t + _Time.y + pos.x * _ScrollJitterFrequency) * _ScrollJitterIntensity; - pos.y += cos(t * 1.2 + _Time.y + pos.x * _ScrollJitterFrequency) * _ScrollJitterIntensity; - - float time = _Time.x; - float d = 30; - float freq = .1; - float3 disp = float3(1,0,0) * curlX(pos.xyz * freq + time, d); - disp += float3(0,1,0) * curlY(pos.xyz * freq +time, d); - disp += float3(0,0,1) * curlZ(pos.xyz * freq + time, d); - pos.xyz = _ScrollJitterIntensity * disp * kDecimetersToWorldUnits; - return pos; - } - - struct Input { - float4 color : Color; - float2 tex : TEXCOORD0; - float3 viewDir; - INTERNAL_DATA - }; - - void vert (inout appdata_full v, out Input o) { - PrepForOds(v.vertex); - - float radius = v.texcoord.z; - - // Bulge displacement - float wave = sin(v.texcoord.x*3.14159); - float3 wave_displacement = radius * v.normal.xyz * wave; - v.vertex.xyz += wave_displacement; - - // Noise displacement - // TO DO: Need to make this scale invariant - float4 displacement = displace(v.vertex,0); - v.vertex.xyz += displacement.xyz; - - // Perturb normal - v.normal = normalize(v.normal + displacement.xyz * 2.5 + wave_displacement * 2.5); - - o.color = TbVertToSrgb(o.color); - UNITY_INITIALIZE_OUTPUT(Input, o); - o.tex = v.texcoord.xy; - } - - // Input color is srgb - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - // Hardcode some shiny specular values - o.Smoothness = .9; - o.Specular = .6 * SrgbToNative(IN.color).rgb; - o.Albedo = 0; - - // Calculate rim - float3 n = WorldNormalVector (IN, o.Normal); - half rim = 1.0 - abs(dot (normalize(IN.viewDir), n)); - rim *= 1-pow(rim,5); - - //Thin slit diffraction texture ramp lookup - float3 diffraction = tex2D(_MainTex, half2(rim + _Time.x + o.Normal.y, rim + o.Normal.y)).xyz; - o.Emission = rim*(.25 * diffraction * rim + .75 * diffraction * IN.color); - - } - ENDCG - } -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/BubbleWand" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + + SubShader { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + Cull off ZWrite Off + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + float _EmissionGain; + float _ScrollRate; + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + float4 displace(float4 pos, float timeOffset) { + float t = GetTime().y*_ScrollRate + timeOffset; + + pos.x += sin(t + GetTime().y + pos.z * _ScrollJitterFrequency) * _ScrollJitterIntensity; + pos.z += cos(t + GetTime().y + pos.x * _ScrollJitterFrequency) * _ScrollJitterIntensity; + pos.y += cos(t * 1.2 + GetTime().y + pos.x * _ScrollJitterFrequency) * _ScrollJitterIntensity; + + float time = GetTime().x; + float d = 30; + float freq = .1; + float3 disp = float3(1,0,0) * curlX(pos.xyz * freq + time, d); + disp += float3(0,1,0) * curlY(pos.xyz * freq +time, d); + disp += float3(0,0,1) * curlZ(pos.xyz * freq + time, d); + pos.xyz = _ScrollJitterIntensity * disp * kDecimetersToWorldUnits; + return pos; + } + + struct Input { + float4 color : Color; + float2 tex : TEXCOORD0; + float3 viewDir; + uint id : SV_VertexID; + float4 screenPos; + INTERNAL_DATA + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id v, out Input o) { + PrepForOds(v.vertex); + + float radius = v.texcoord.z; + + // Bulge displacement + float wave = sin(v.texcoord.x*3.14159); + float3 wave_displacement = radius * v.normal.xyz * wave; + v.vertex.xyz += wave_displacement; + + // Noise displacement + // TO DO: Need to make this scale invariant + float4 displacement = displace(v.vertex,0); + v.vertex.xyz += displacement.xyz; + + // Perturb normal + v.normal = normalize(v.normal + displacement.xyz * 2.5 + wave_displacement * 2.5); + + o.color = TbVertToSrgb(o.color); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.tex = v.texcoord.xy; + o.id = v.id; + } + + // Input color is srgb + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + // Hardcode some shiny specular values + o.Smoothness = .9; + o.Specular = .6 * SrgbToNative(IN.color).rgb; + o.Albedo = 0; + + // Calculate rim + float3 n = WorldNormalVector (IN, o.Normal); + half rim = 1.0 - abs(dot (normalize(IN.viewDir), n)); + rim *= 1-pow(rim,5); + + //Thin slit diffraction texture ramp lookup + float3 diffraction = tex2D(_MainTex, half2(rim + GetTime().x + o.Normal.y, rim + o.Normal.y)).xyz; + o.Emission = rim*(.25 * diffraction * rim + .75 * diffraction * IN.color); + o.Emission *= _Opacity; + o.Specular *= _Opacity; + o.Smoothness *= _Opacity; + } + ENDCG + } +} diff --git a/Assets/Resources/X/Brushes/Digital/Digital.shader b/Assets/Resources/X/Brushes/Digital/Digital.shader index e0fa19e7f3..1623e5e824 100644 --- a/Assets/Resources/X/Brushes/Digital/Digital.shader +++ b/Assets/Resources/X/Brushes/Digital/Digital.shader @@ -1,183 +1,202 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Digital" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #pragma target 3.0 - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - #define BRUSHES_DIGITAL_ROWS 5 - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float2 st : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - - // start transforming the uv - o.st = o.texcoord; - - // fix aspect ratio - o.st.x *= 5; - - // scale it up so we can make a grid - o.st *= BRUSHES_DIGITAL_ROWS; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR { - float stroke_width = .1; - float antialias_feather_px = 4; - - float2 st = i.texcoord; - - // used for antialiasing - float2 st_per_px = fwidth(st); - - // create the grid. - // rc means row,col. rc.x actually really means x i.e. it's columns (from the perspective - // of a stroke going from left to right in front of you). - float2 rc = floor(st); - - // get the tile coordinates - // map tile_st.y to [-1, 1] - float tile_st = frac(st); - tile_st -= .5; - tile_st *= 2; - - float lum = 0; - float r = length(tile_st); - - // for each neighboring tile... - for (int ii = -1; ii <= 1; ii++) { - if (rc.x + ii < 0) continue; - for (int jj = -1; jj <= 1; jj++) { - if (abs(ii) == abs(jj)) continue; - if (rc.y + jj < 0) continue; - if (rc.y + jj >= BRUSHES_DIGITAL_ROWS) continue; - - // me and my neighbor decide if we should connect our tiles - // - // (x) represents random(rc) - // [x] represents random(rc) + random(rc + ij) - // - // (0.5)xx[1.3]xx(0.8) - // x - // x - // [1.1] [0.4] - // x - // x - // (0.6) [0.7] (0.1) - // - // if i'm (0.5), then i'm going to draw (0.5)xxx---(0.8) - // if i'm (0.8), then i'm going to draw (0.5)---xxx(0.8) - if (random(rc) + random(rc + float2(ii, jj)) < 1) continue; - - // draw a rectangle with width stroke_width through the center of - // this tile towards the other tile - // i=0,j=1 i=-1,j=0 - // ( --111-- ------- ) --111-- - // ( --111-- ------- ) --111-- - // ( --111-- 11111-- ) 11111-- - // max( --111-- , 11111-- ) = 11111-- - // ( --111-- 11111-- ) 11111-- - // ( ------- ------- ) ------- - // ( ------- ------- ) ------- - - float2 ij = float2(ii, jj); - float2 ij_perp = float2(-jj, ii); - // when ij points to the right: - // bound1 is bottomleft - // bound2 is topright - float2 bound1 = stroke_width * -ij_perp + stroke_width * -ij; - float2 bound2 = ij + stroke_width * ij_perp; - float2 min_bound = min(bound1, bound2); - float2 max_bound = max(bound1, bound2); - - float2 aa_feather = st_per_px * antialias_feather_px; - float current_lum = - smoothstep(min_bound.x - aa_feather.x, min_bound.x, st.x) * - smoothstep(max_bound.x + aa_feather.x, max_bound.x, st.x) * - smoothstep(min_bound.y - aa_feather.y, min_bound.y, st.y) * - smoothstep(max_bound.y + aa_feather.y, max_bound.y, st.y); - lum = max(lum, current_lum); - } - } - fixed4 color; - color.a = 1; - color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Digital" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #pragma target 3.0 + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + #define BRUSHES_DIGITAL_ROWS 5 + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float2 st : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + + // start transforming the uv + o.st = o.texcoord; + + // fix aspect ratio + o.st.x *= 5; + + // scale it up so we can make a grid + o.st *= BRUSHES_DIGITAL_ROWS; + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float stroke_width = .1; + float antialias_feather_px = 4; + + float2 st = i.texcoord; + + // used for antialiasing + float2 st_per_px = fwidth(st); + + // create the grid. + // rc means row,col. rc.x actually really means x i.e. it's columns (from the perspective + // of a stroke going from left to right in front of you). + float2 rc = floor(st); + + // get the tile coordinates + // map tile_st.y to [-1, 1] + float tile_st = frac(st); + tile_st -= .5; + tile_st *= 2; + + float lum = 0; + float r = length(tile_st); + + // for each neighboring tile... + for (int ii = -1; ii <= 1; ii++) { + if (rc.x + ii < 0) continue; + for (int jj = -1; jj <= 1; jj++) { + if (abs(ii) == abs(jj)) continue; + if (rc.y + jj < 0) continue; + if (rc.y + jj >= BRUSHES_DIGITAL_ROWS) continue; + + // me and my neighbor decide if we should connect our tiles + // + // (x) represents random(rc) + // [x] represents random(rc) + random(rc + ij) + // + // (0.5)xx[1.3]xx(0.8) + // x + // x + // [1.1] [0.4] + // x + // x + // (0.6) [0.7] (0.1) + // + // if i'm (0.5), then i'm going to draw (0.5)xxx---(0.8) + // if i'm (0.8), then i'm going to draw (0.5)---xxx(0.8) + if (random(rc) + random(rc + float2(ii, jj)) < 1) continue; + + // draw a rectangle with width stroke_width through the center of + // this tile towards the other tile + // i=0,j=1 i=-1,j=0 + // ( --111-- ------- ) --111-- + // ( --111-- ------- ) --111-- + // ( --111-- 11111-- ) 11111-- + // max( --111-- , 11111-- ) = 11111-- + // ( --111-- 11111-- ) 11111-- + // ( ------- ------- ) ------- + // ( ------- ------- ) ------- + + float2 ij = float2(ii, jj); + float2 ij_perp = float2(-jj, ii); + // when ij points to the right: + // bound1 is bottomleft + // bound2 is topright + float2 bound1 = stroke_width * -ij_perp + stroke_width * -ij; + float2 bound2 = ij + stroke_width * ij_perp; + float2 min_bound = min(bound1, bound2); + float2 max_bound = max(bound1, bound2); + + float2 aa_feather = st_per_px * antialias_feather_px; + float current_lum = + smoothstep(min_bound.x - aa_feather.x, min_bound.x, st.x) * + smoothstep(max_bound.x + aa_feather.x, max_bound.x, st.x) * + smoothstep(min_bound.y - aa_feather.y, min_bound.y, st.y) * + smoothstep(max_bound.y + aa_feather.y, max_bound.y, st.y); + lum = max(lum, current_lum); + } + } + fixed4 color; + color.a = 1; + color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Drafting/Drafting.shader b/Assets/Resources/X/Brushes/Drafting/Drafting.shader index 1273bd89f5..78a22e1dff 100644 --- a/Assets/Resources/X/Brushes/Drafting/Drafting.shader +++ b/Assets/Resources/X/Brushes/Drafting/Drafting.shader @@ -1,84 +1,104 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Drafting" { - Properties { - _MainTex ("Texture", 2D) = "white" {} - } - - SubShader { - Tags { - "Queue"="Transparent" - "IgnoreProjector"="True" - "RenderType"="Transparent" - } - Blend One One // SrcAlpha One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - Pass { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - uniform float _DraftingVisibility01; - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - - v2f vert (appdata_t v) { - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color * _DraftingVisibility01; - return o; - } - - fixed4 frag (v2f i) : COLOR { - half4 c = i.color * tex2D(_MainTex, i.texcoord ); - return encodeHdr(c.rgb * c.a); - } - ENDCG - } - } -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Drafting" { + Properties { + _MainTex ("Texture", 2D) = "white" {} + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + SubShader { + Tags { + "Queue"="Transparent" + "IgnoreProjector"="True" + "RenderType"="Transparent" + } + Blend One One // SrcAlpha One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + Pass { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + uniform float _DraftingVisibility01; + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + + v2f vert (appdata_t v) { + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color * _DraftingVisibility01; + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + half4 c = i.color * tex2D(_MainTex, i.texcoord ); + c = encodeHdr(c.rgb * c.a * _Opacity); + return c * _Opacity; + } + ENDCG + } + } +} diff --git a/Assets/Resources/X/Brushes/Fairy/Fairy.shader b/Assets/Resources/X/Brushes/Fairy/Fairy.shader index db1ad45573..acd1b13570 100644 --- a/Assets/Resources/X/Brushes/Fairy/Fairy.shader +++ b/Assets/Resources/X/Brushes/Fairy/Fairy.shader @@ -1,160 +1,182 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Fairy" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #pragma target 3.0 - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR { - float scale1 = 3; - float scale2 = 3; - - float2 st = i.texcoord.xy; - float2 uv = st; - - // fix aspect ratio - st.x *= 5; - - // divide the space into tiles - float2 scaler = floor(st); - scaler = random(scaler); - scaler *= scale1; - scaler = max(scaler, 1); - scaler = floor(scaler); - st *= scaler; - - // and again - scaler = floor(st); - scaler = random(scaler + 234.4); - scaler *= scale2; - scaler = max(scaler, 1); - scaler = floor(scaler); - st *= scaler; - - // row,col (only used as random seed) - float2 rc = floor(st); - - // get the tile uv - st = frac(st); - st -= .5; - st *= 2; - - // scale it a bit - float rscale = lerp(.2, 1, random(rc)); - st /= rscale; - - // move it a little bit - float2 offset = random2(rc + 5) * .1; - st += offset; - - float r = length(st); - float lum = 1 - r; - - // make sure the dot fully fades by the time we get to the edge - // of the square, otherwise it will get chopped off - lum -= max(offset.x, offset.y); - lum = saturate(lum); - - // vary the radial brightness falloff - float powpow = random(rc); - powpow = powpow * 2 - 1; - powpow = max(.3, powpow); - if (powpow < 0) - { - powpow = 1 / abs(powpow); - } - lum *= 2; - lum = pow(lum, powpow); - - // fade the dots in and out with variety - float fadespeed = lerp(.25, 1.25, random(rc)); - float fadephase = random(rc) * 2 * 3.14; - float time = sin(_Time.z * fadespeed + fadephase) / 2 + .5; - lum *= lerp(0, 1, time); - - fixed4 color; - color.a = 1; - color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Fairy" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #pragma target 3.0 + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float scale1 = 3; + float scale2 = 3; + + float2 st = i.texcoord.xy; + float2 uv = st; + + // fix aspect ratio + st.x *= 5; + + // divide the space into tiles + float2 scaler = floor(st); + scaler = random(scaler); + scaler *= scale1; + scaler = max(scaler, 1); + scaler = floor(scaler); + st *= scaler; + + // and again + scaler = floor(st); + scaler = random(scaler + 234.4); + scaler *= scale2; + scaler = max(scaler, 1); + scaler = floor(scaler); + st *= scaler; + + // row,col (only used as random seed) + float2 rc = floor(st); + + // get the tile uv + st = frac(st); + st -= .5; + st *= 2; + + // scale it a bit + float rscale = lerp(.2, 1, random(rc)); + st /= rscale; + + // move it a little bit + float2 offset = random2(rc + 5) * .1; + st += offset; + + float r = length(st); + float lum = 1 - r; + + // make sure the dot fully fades by the time we get to the edge + // of the square, otherwise it will get chopped off + lum -= max(offset.x, offset.y); + lum = saturate(lum); + + // vary the radial brightness falloff + float powpow = random(rc); + powpow = powpow * 2 - 1; + powpow = max(.3, powpow); + if (powpow < 0) + { + powpow = 1 / abs(powpow); + } + lum *= 2; + lum = pow(lum, powpow); + + // fade the dots in and out with variety + float fadespeed = lerp(.25, 1.25, random(rc)); + float fadephase = random(rc) * 2 * 3.14; + float time = sin(GetTime().z * fadespeed + fadephase) / 2 + .5; + lum *= lerp(0, 1, time); + + fixed4 color; + color.a = 1; + color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Fire 2/Fire2.shader b/Assets/Resources/X/Brushes/Fire 2/Fire2.shader index 41a0578f73..9cbbde199c 100644 --- a/Assets/Resources/X/Brushes/Fire 2/Fire2.shader +++ b/Assets/Resources/X/Brushes/Fire 2/Fire2.shader @@ -1,152 +1,172 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Fire2" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _DisplaceTex ("Displace Texture", 2D) = "white" {} - - _Scroll1 ("Scroll1", Float) = 0 - _Scroll2 ("Scroll2", Float) = 0 - _DisplacementIntensity("Displacement", Float) = .1 - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 - - _FlameFadeMin ("Fade Flame Min", Float) = 1 - _FlameFadeMax ("Fade Flame Max", Float) = 30 - -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma target 3.0 - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - sampler2D _DisplaceTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; -#if SHADER_TARGET >= 40 - centroid float2 texcoord : TEXCOORD0; -#else - float2 texcoord : TEXCOORD0; -#endif - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - float4 color : COLOR; -#if SHADER_TARGET >= 40 - centroid float2 texcoord : TEXCOORD0; -#else - float2 texcoord : TEXCOORD0; -#endif - float3 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - fixed _Scroll1; - fixed _Scroll2; - half _DisplacementIntensity; - half _EmissionGain; - - half _FlameFadeMax; - half _FlameFadeMin; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = bloomColor(v.color, _EmissionGain); - o.vertex = UnityObjectToClipPos(v.vertex); - o.worldPos = mul(unity_ObjectToWorld, v.vertex); - return o; - } - - // Note: input color is srgb - fixed4 frag (v2f i) : COLOR - { - half2 displacement; - float procedural_line = 0; - float flame_fade_mix = 0; - - displacement = tex2D( _DisplaceTex, i.texcoord ).xy; - displacement = displacement * 2.0 - 1.0; - displacement *= _DisplacementIntensity; - - half mask = tex2D(_MainTex, i.texcoord).y; - -#ifdef AUDIO_REACTIVE - flame_fade_mix = 1.0- saturate(_BeatOutput.w); -#else -#endif - half2 uv = i.texcoord; - uv += displacement; - - half flame1 = tex2D(_MainTex, uv * .7 + half2(-_Time.x * _Scroll1, 0)).x; - half flame2 = tex2D(_MainTex, half2(uv.x,1.0-uv.y) + half2(-_Time.x * _Scroll2, -_Time.x * _Scroll2 / 4 )).x; - - half flames = saturate( flame2 + flame1 ) / 2.0; - flames = smoothstep( 0, 0.8, mask*flames); - flames *= mask; - - half4 tex = half4(flames,flames,flames,1.0); - float flame_fade = lerp(_FlameFadeMin,_FlameFadeMax,flame_fade_mix); - - tex.xyz *= pow(1.0-i.texcoord.x, flame_fade) * (flame_fade*2); - - float4 color = i.color * tex; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Fire2" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _DisplaceTex ("Displace Texture", 2D) = "white" {} + + _Scroll1 ("Scroll1", Float) = 0 + _Scroll2 ("Scroll2", Float) = 0 + _DisplacementIntensity("Displacement", Float) = .1 + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _FlameFadeMin ("Fade Flame Min", Float) = 1 + _FlameFadeMax ("Fade Flame Max", Float) = 30 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.0 + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + sampler2D _DisplaceTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; +#if SHADER_TARGET >= 40 + centroid float2 texcoord : TEXCOORD0; +#else + float2 texcoord : TEXCOORD0; +#endif + float3 worldPos : TEXCOORD1; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + float4 color : COLOR; +#if SHADER_TARGET >= 40 + centroid float2 texcoord : TEXCOORD0; +#else + float2 texcoord : TEXCOORD0; +#endif + float3 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + fixed _Scroll1; + fixed _Scroll2; + half _DisplacementIntensity; + half _EmissionGain; + + half _FlameFadeMax; + half _FlameFadeMin; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = bloomColor(v.color, _EmissionGain); + o.vertex = UnityObjectToClipPos(v.vertex); + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.id = (float2)v.id; + return o; + } + + // Note: input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + half2 displacement; + float procedural_line = 0; + float flame_fade_mix = 0; + + displacement = tex2D( _DisplaceTex, i.texcoord ).xy; + displacement = displacement * 2.0 - 1.0; + displacement *= _DisplacementIntensity; + + half mask = tex2D(_MainTex, i.texcoord).y; + +#ifdef AUDIO_REACTIVE + flame_fade_mix = 1.0- saturate(_BeatOutput.w); +#else +#endif + half2 uv = i.texcoord; + uv += displacement; + + half flame1 = tex2D(_MainTex, uv * .7 + half2(-GetTime().x * _Scroll1, 0)).x; + half flame2 = tex2D(_MainTex, half2(uv.x,1.0-uv.y) + half2(-GetTime().x * _Scroll2, -GetTime().x * _Scroll2 / 4 )).x; + + half flames = saturate( flame2 + flame1 ) / 2.0; + flames = smoothstep( 0, 0.8, mask*flames); + flames *= mask; + + half4 tex = half4(flames,flames,flames,1.0); + float flame_fade = lerp(_FlameFadeMin,_FlameFadeMax,flame_fade_mix); + + tex.xyz *= pow(1.0-i.texcoord.x, flame_fade) * (flame_fade*2); + + float4 color = i.color * tex; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/KeijiroTube/KeijiroTube.shader b/Assets/Resources/X/Brushes/KeijiroTube/KeijiroTube.shader index b2753718dd..441b38a9b8 100644 --- a/Assets/Resources/X/Brushes/KeijiroTube/KeijiroTube.shader +++ b/Assets/Resources/X/Brushes/KeijiroTube/KeijiroTube.shader @@ -1,66 +1,101 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/KeijiroTube" { -Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 -} - SubShader { - LOD 200 - Cull Back - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float4 color : Color; - float radius; - }; - - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full i, out Input o) { - UNITY_INITIALIZE_OUTPUT(Input, o); - // o.tangent = v.tangent; - PrepForOds(i.vertex); - i.color = TbVertToNative(i.color); - - float radius = i.texcoord.z; - float wave = sin(i.texcoord.x - _Time.z); - float pulse = smoothstep(.45, .5, saturate(wave)); - i.vertex.xyz -= pulse * radius * i.normal.xyz; - o.radius = radius; - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - o.Albedo = _Color.rgb * IN.color.rgb; - o.Smoothness = _Shininess; - o.Specular = _SpecColor * IN.color.rgb; - } - ENDCG - } - - - FallBack "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/KeijiroTube" { +Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + SubShader { + LOD 200 + Cull Back + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float4 color : Color; + float radius; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + // o.tangent = v.tangent; + PrepForOds(i.vertex); + i.color = TbVertToNative(i.color); + + float radius = i.texcoord.z; + float wave = sin(i.texcoord.x - GetTime().z); + float pulse = smoothstep(.45, .5, saturate(wave)); + i.vertex.xyz -= pulse * radius * i.normal.xyz; + o.radius = radius; + o.id = i.id; + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + o.Albedo = _Color.rgb * IN.color.rgb; + o.Smoothness = _Shininess; + o.Specular = _SpecColor * IN.color.rgb; + } + ENDCG + } + + + FallBack "Diffuse" +} diff --git a/Assets/Resources/X/Brushes/Lacewing/Lacewing.shader b/Assets/Resources/X/Brushes/Lacewing/Lacewing.shader index 0e05a0c3c0..f95de667dc 100644 --- a/Assets/Resources/X/Brushes/Lacewing/Lacewing.shader +++ b/Assets/Resources/X/Brushes/Lacewing/Lacewing.shader @@ -1,107 +1,146 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Lacewing" { - Properties{ - _Color("Main Color", Color) = (1,1,1,1) - _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess("Shininess", Range(0.01, 1)) = 0.078125 - _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - _SpecTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap("Normalmap", 2D) = "bump" {} - _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 - } - SubShader{ - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull Back - LOD 100 - - CGPROGRAM -#pragma target 3.0 -#pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow -#pragma multi_compile __ AUDIO_REACTIVE -#pragma multi_compile __ ODS_RENDER ODS_RENDER_CM -#include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float2 uv_SpecTex; - float4 color : Color; - float3 worldPos; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - sampler2D _SpecTex; - fixed4 _Color; - half _Shininess; - - void vert(inout appdata_full v) { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - float t = 0.0; - - float strokeWidth = abs(v.texcoord.z) * 1.2; - -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.z * 5; - float waveIntensity = _BeatOutput.z * .1 * strokeWidth; - v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) - * cross(v.tangent.xyz, v.normal.xyz) - * waveIntensity) - ; -#endif - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 spectex = tex2D(_SpecTex, IN.uv_SpecTex); - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - - float scroll = _Time.z; -#ifdef AUDIO_REACTIVE - float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; - float t = length(localPos) * .5; - scroll = _BeatOutputAccum.y * 30; - float angle = atan2(localPos.x, localPos.y); - float waveform = tex2D(_WaveFormTex, float2(angle * 6, 0)).g * 2; - - spectex.rgb = float3(1, 0, 0) * (sin(spectex.r * 2 + scroll*0.5 - t) + 1); - spectex.rgb += float3(0, 1, 0) * (sin(spectex.r * 3 + scroll * 1 - t) + 1); - spectex.rgb += float3(0, 0, 1) * (sin(spectex.r * 4 + scroll*0.25 - t) + 1); -#else - spectex.rgb = float3(1, 0, 0) * (sin(spectex.r * 2 + scroll*0.5 - IN.uv_SpecTex.x) + 1) * 1; - spectex.rgb += float3(0, 1, 0) * (sin(spectex.r * 3.3 + scroll * 1 - IN.uv_SpecTex.x) + 1) * 1; - spectex.rgb += float3(0, 0, 1) * (sin(spectex.r * 4.66 + scroll*0.25 - IN.uv_SpecTex.x) + 1) * 1; -#endif - - o.Albedo = SrgbToNative(tex * IN.color).rgb; - o.Smoothness = _Shininess; - o.Specular = SrgbToNative(_SpecColor * spectex).rgb; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Alpha = tex.a * IN.color.a; - -#ifdef AUDIO_REACTIVE - o.Emission = o.Albedo; - o.Albedo = .2; - o.Specular *= .5; -#endif - - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Lacewing" { + Properties{ + _Color("Main Color", Color) = (1,1,1,1) + _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess("Shininess", Range(0.01, 1)) = 0.078125 + _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + _SpecTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap("Normalmap", 2D) = "bump" {} + _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + SubShader{ + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } + Cull Back + LOD 100 + + CGPROGRAM + + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float2 uv_SpecTex; + float4 color : Color; + float3 worldPos; + uint id : SV_VertexID; + float4 screenPos; + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + sampler2D _SpecTex; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + float t = 0.0; + + float strokeWidth = abs(v.texcoord.z) * 1.2; + +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.z * 5; + float waveIntensity = _BeatOutput.z * .1 * strokeWidth; + v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) + * cross(v.tangent.xyz, v.normal.xyz) + * waveIntensity) + ; +#endif + o.id = v.id; + + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 spectex = tex2D(_SpecTex, IN.uv_SpecTex); + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + + float scroll = GetTime().z; +#ifdef AUDIO_REACTIVE + float3 localPos = mul(xf_I_CS, float4(IN.worldPos, 1.0)).xyz; + float t = length(localPos) * .5; + scroll = _BeatOutputAccum.y * 30; + float angle = atan2(localPos.x, localPos.y); + float waveform = tex2D(_WaveFormTex, float2(angle * 6, 0)).g * 2; + + spectex.rgb = float3(1, 0, 0) * (sin(spectex.r * 2 + scroll*0.5 - t) + 1); + spectex.rgb += float3(0, 1, 0) * (sin(spectex.r * 3 + scroll * 1 - t) + 1); + spectex.rgb += float3(0, 0, 1) * (sin(spectex.r * 4 + scroll*0.25 - t) + 1); +#else + spectex.rgb = float3(1, 0, 0) * (sin(spectex.r * 2 + scroll*0.5 - IN.uv_SpecTex.x) + 1) * 1; + spectex.rgb += float3(0, 1, 0) * (sin(spectex.r * 3.3 + scroll * 1 - IN.uv_SpecTex.x) + 1) * 1; + spectex.rgb += float3(0, 0, 1) * (sin(spectex.r * 4.66 + scroll*0.25 - IN.uv_SpecTex.x) + 1) * 1; +#endif + + o.Albedo = SrgbToNative(tex * IN.color).rgb; + o.Smoothness = _Shininess; + o.Specular = SrgbToNative(_SpecColor * spectex).rgb; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Alpha = tex.a * IN.color.a; + +#ifdef AUDIO_REACTIVE + o.Emission = o.Albedo; + o.Albedo = .2; + o.Specular *= .5; +#endif + + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/X/Brushes/LeakyPen/LeakyPen.shader b/Assets/Resources/X/Brushes/LeakyPen/LeakyPen.shader index 2c1d8a0451..106528d6ac 100644 --- a/Assets/Resources/X/Brushes/LeakyPen/LeakyPen.shader +++ b/Assets/Resources/X/Brushes/LeakyPen/LeakyPen.shader @@ -1,69 +1,98 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/LeakyPen" { - Properties { - _MainTex ("Alpha Mask", 2D) = "white" {} - _SecondaryTex("Diffuse Tex", 2D) = "white" {} - _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 - - } - Category { - Cull Back - SubShader { - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - - LOD 200 - CGPROGRAM - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - - sampler2D _MainTex; - sampler2D _SecondaryTex; - - struct Input { - - float2 uv_MainTex; - float2 uv_SecondaryTex; - float4 color : Color; - }; - - void vert(inout appdata_full i) { - PrepForOds(i.vertex); - i.color = TbVertToNative(i.color); - } - - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - - float3 secondary_tex = tex2D(_MainTex, IN.uv_SecondaryTex).rgb; - - // Apply the alpha mask - float primary_tex = tex2D(_MainTex, IN.uv_MainTex).w; - - // Combine the two texture elements - float3 tex = secondary_tex * primary_tex; - o.Specular = 0; - o.Albedo = IN.color.rgb; - o.Alpha = tex * IN.color.a; - - } - ENDCG - } - } - FallBack "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/LeakyPen" { + Properties { + _MainTex ("Alpha Mask", 2D) = "white" {} + _SecondaryTex("Diffuse Tex", 2D) = "white" {} + _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + Category { + Cull Back + SubShader { + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } + + LOD 200 + CGPROGRAM + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma target 4.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + + sampler2D _MainTex; + sampler2D _SecondaryTex; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float2 uv_MainTex; + float2 uv_SecondaryTex; + float4 color : Color; + uint id : SV_VertexID; + float4 screenPos; + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id i, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(i.vertex); + i.color = TbVertToNative(i.color); + o.id = i.id; + } + + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + float3 secondary_tex = tex2D(_MainTex, IN.uv_SecondaryTex).rgb; + + // Apply the alpha mask + float primary_tex = tex2D(_MainTex, IN.uv_MainTex).w; + + // Combine the two texture elements + float3 tex = secondary_tex * primary_tex; + o.Specular = 0; + o.Albedo = IN.color.rgb; + o.Alpha = tex * IN.color.a; + + } + ENDCG + } + } + FallBack "Diffuse" +} diff --git a/Assets/Resources/X/Brushes/LoftedHueShift/LoftedHueShift.shader b/Assets/Resources/X/Brushes/LoftedHueShift/LoftedHueShift.shader index 0797626d11..48c564e0b1 100644 --- a/Assets/Resources/X/Brushes/LoftedHueShift/LoftedHueShift.shader +++ b/Assets/Resources/X/Brushes/LoftedHueShift/LoftedHueShift.shader @@ -1,67 +1,98 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/LoftedHueShift" { - Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - } - Category { - Cull Back - SubShader { - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/ColorSpace.cginc" - - struct Input { - float2 uv_MainTex; - float4 color : Color; - float3 worldPos; - float4 screenPos; - }; - - sampler2D _MainTex; - fixed4 _Color; - half _Shininess; - - void vert (inout appdata_full v) { - PrepForOds(v.vertex); - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex) * IN.color; - - // Hijack colorspace to make a hue shift..this is probably awful and technically wrong? - float shift = 5; - shift += IN.color; - float3 hueshift = hue06_to_base_rgb(IN.color * shift); - fixed4 _ColorShift = float4(hueshift, 1); - float huevignette = pow(abs(IN.uv_MainTex - .5) * 2.0, 2.0); - - o.Albedo = lerp(tex, _ColorShift, saturate(huevignette)); - o.Smoothness = _Shininess; - o.Specular = _SpecColor; - } - ENDCG - } -} - - //FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/LoftedHueShift" { + Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + + Category { + Cull Back + SubShader { + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/ColorSpace.cginc" + + struct Input { + float2 uv_MainTex; + float4 color : Color; + float3 worldPos; + float4 screenPos; + uint id : SV_VertexID; + }; + + sampler2D _MainTex; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert (inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + o.id = v.id; + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex) * IN.color; + + // Hijack colorspace to make a hue shift..this is probably awful and technically wrong? + float shift = 5; + shift += IN.color; + float3 hueshift = hue06_to_base_rgb(IN.color * shift); + fixed4 _ColorShift = float4(hueshift, 1); + float huevignette = pow(abs(IN.uv_MainTex - .5) * 2.0, 2.0); + + o.Albedo = lerp(tex, _ColorShift, saturate(huevignette)); + o.Smoothness = _Shininess; + o.Specular = _SpecColor; + } + ENDCG + } +} + + //FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/X/Brushes/MarbledRainbow/MarbledRainbow.shader b/Assets/Resources/X/Brushes/MarbledRainbow/MarbledRainbow.shader index 9d8ef007ad..786e8c10e0 100644 --- a/Assets/Resources/X/Brushes/MarbledRainbow/MarbledRainbow.shader +++ b/Assets/Resources/X/Brushes/MarbledRainbow/MarbledRainbow.shader @@ -1,89 +1,120 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/MarbledRainbow" { - Properties{ - _Color("Main Color", Color) = (1,1,1,1) - _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess("Shininess", Range(0.01, 1)) = 0.078125 - _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - _SpecTex("Base (RGB) TransGloss (A)", 2D) = "white" {} - _BumpMap("Normalmap", 2D) = "bump" {} - _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 - } - SubShader{ - Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } - Cull Back - LOD 100 - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "Assets/Shaders/Include/Brush.cginc" - - struct Input { - float2 uv_MainTex; - float2 uv_BumpMap; - float2 uv_SpecTex; - float4 color : Color; - float3 worldPos; - }; - - sampler2D _MainTex; - sampler2D _BumpMap; - sampler2D _SpecTex; - fixed4 _Color; - half _Shininess; - - void vert(inout appdata_full v) { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - float t = 0.0; - - float strokeWidth = abs(v.texcoord.z) * 1.2; - -#ifdef AUDIO_REACTIVE - t = _BeatOutputAccum.z * 5; - float waveIntensity = _BeatOutput.z * .1 * strokeWidth; - v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) - * cross(v.tangent.xyz, v.normal.xyz) - * waveIntensity); -#endif - } - - void surf(Input IN, inout SurfaceOutputStandardSpecular o) { - fixed4 spectex = tex2D(_SpecTex, IN.uv_SpecTex); - fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); - - o.Albedo = SrgbToNative(tex * IN.color).rgb; - o.Smoothness = _Shininess; - o.Specular = SrgbToNative(_SpecColor * spectex).rgb; - o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); - o.Alpha = tex.a * IN.color.a; - -#ifdef AUDIO_REACTIVE - o.Emission = o.Albedo; - o.Albedo = .2; - o.Specular *= .5; -#endif - - } - ENDCG - } - - FallBack "Transparent/Cutout/VertexLit" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/MarbledRainbow" { + Properties{ + _Color("Main Color", Color) = (1,1,1,1) + _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess("Shininess", Range(0.01, 1)) = 0.078125 + _MainTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + _SpecTex("Base (RGB) TransGloss (A)", 2D) = "white" {} + _BumpMap("Normalmap", 2D) = "bump" {} + _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 + } + SubShader{ + Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } + Cull Back + LOD 100 + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert alphatest:_Cutoff addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #include "Assets/Shaders/Include/Brush.cginc" + + struct Input { + float2 uv_MainTex; + float2 uv_BumpMap; + float2 uv_SpecTex; + float4 color : Color; + float3 worldPos; + uint id : SV_VertexID; + float4 screenPos; + }; + + sampler2D _MainTex; + sampler2D _BumpMap; + sampler2D _SpecTex; + fixed4 _Color; + half _Shininess; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id v, out Input o) { + UNITY_INITIALIZE_OUTPUT(Input, o); + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + float t = 0.0; + + float strokeWidth = abs(v.texcoord.z) * 1.2; + +#ifdef AUDIO_REACTIVE + t = _BeatOutputAccum.z * 5; + float waveIntensity = _BeatOutput.z * .1 * strokeWidth; + v.vertex.xyz += (pow(1 - (sin(t + v.texcoord.x * 5 + v.texcoord.y * 10) + 1), 2) + * cross(v.tangent.xyz, v.normal.xyz) + * waveIntensity); +#endif + o.id = v.id; + } + + void surf(Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + fixed4 spectex = tex2D(_SpecTex, IN.uv_SpecTex); + fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); + + o.Albedo = SrgbToNative(tex * IN.color).rgb; + o.Smoothness = _Shininess; + o.Specular = SrgbToNative(_SpecColor * spectex).rgb; + o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); + o.Alpha = tex.a * IN.color.a; + +#ifdef AUDIO_REACTIVE + o.Emission = o.Albedo; + o.Albedo = .2; + o.Specular *= .5; +#endif + + } + ENDCG + } + + FallBack "Transparent/Cutout/VertexLit" +} diff --git a/Assets/Resources/X/Brushes/MylarTube/MylarTube.mat b/Assets/Resources/X/Brushes/MylarTube/MylarTube.mat index 146d53aece..43203246ef 100644 --- a/Assets/Resources/X/Brushes/MylarTube/MylarTube.mat +++ b/Assets/Resources/X/Brushes/MylarTube/MylarTube.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: MylarTube m_Shader: {fileID: 4800000, guid: 073d6ba13e511e24bb3ba4f7c8f744ee, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 5 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -31,11 +32,16 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: + - _ClipEnd: -1 + - _ClipStart: 0 - _Cutoff: 0.5 - _DisplacementIntensity: 0.1 - _EmissionGain: 0.25 - _InvFade: 1 + - _Opacity: 1 + - _OverrideTime: 0 - _Scroll1: 2 - _Scroll2: -2 - _ScrollJitterFrequency: 1 @@ -45,10 +51,14 @@ Material: - _Smoothness: 0.078125 - _SqueezeAmount: 0.873 - _Strength: 0.5 + - _TimeBlend: 0 + - _TimeSpeed: 1 m_Colors: - _Color: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.75, g: 0.75, b: 0.75, a: 0} + - _TimeOverrideValue: {r: 0, g: 0, b: 0, a: 0} - _TintColor: {r: 0.61764705, g: 0.61764705, b: 0.61764705, a: 1} + m_BuildTextureStacks: [] --- !u!1002 &2100001 EditorExtensionImpl: serializedVersion: 6 diff --git a/Assets/Resources/X/Brushes/MylarTube/MylarTube.shader b/Assets/Resources/X/Brushes/MylarTube/MylarTube.shader index 71cce05811..b45e2bd1f2 100644 --- a/Assets/Resources/X/Brushes/MylarTube/MylarTube.shader +++ b/Assets/Resources/X/Brushes/MylarTube/MylarTube.shader @@ -1,86 +1,123 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/MylarTube" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _Color ("Main Color", Color) = (1,1,1,1) - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) - _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 - _SqueezeAmount("Squeeze Amount", Range(0.0,1)) = 0.825 -} -Category { - Cull Back - SubShader { - - CGPROGRAM - #pragma target 3.0 - #pragma surface surf StandardSpecular vertex:vert addshadow - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - fixed4 _Color; - half _Shininess; - half _SqueezeAmount; - - struct Input { - float4 color : Color; - float2 tex : TEXCOORD0; - float3 viewDir; - INTERNAL_DATA - }; - - void vert (inout appdata_full v, out Input o) { - PrepForOds(v.vertex); - - float radius = v.texcoord.z; - - // Squeeze displacement - float squeeze = sin(v.texcoord.x*3.14159); - float3 squeeze_displacement = radius * v.normal.xyz * squeeze; - v.vertex.xyz -= squeeze_displacement * _SqueezeAmount; - - // Perturb normal - v.normal = normalize(v.normal + squeeze_displacement * 2.5); - - o.color = TbVertToSrgb(o.color); - UNITY_INITIALIZE_OUTPUT(Input, o); - o.tex = v.texcoord.xy; - } - - // Input color is srgb - void surf (Input IN, inout SurfaceOutputStandardSpecular o) { - o.Albedo = _Color.rgb * IN.color.rgb; - //o.Emission = _Color.rgb * IN.color.rgb; - o.Smoothness = _Shininess; - o.Specular = _SpecColor * IN.color.rgb; - - // Calculate rim - float3 n = WorldNormalVector (IN, o.Normal); - half rim = 1.0 - abs(dot (normalize(IN.viewDir), n)); - rim *= 1-pow(rim,5); - - //Thin slit diffraction texture ramp lookup - float3 diffraction = tex2D(_MainTex, half2(rim + _Time.x + o.Normal.y, rim + o.Normal.y)).xyz; - o.Emission = rim*(.25 * diffraction * rim + .75 * diffraction * IN.color); - - } - ENDCG - } -} - FallBack "Diffuse" -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/MylarTube" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Color ("Main Color", Color) = (1,1,1,1) + _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0) + _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 + _SqueezeAmount("Squeeze Amount", Range(0.0,1)) = 0.825 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0,1)) = 1.0 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Cull Back + SubShader { + + CGPROGRAM + #pragma target 4.0 + #pragma surface surf StandardSpecular vertex:vert addshadow + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + fixed4 _Color; + half _Shininess; + half _SqueezeAmount; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct Input { + float4 color : Color; + float2 tex : TEXCOORD0; + float3 viewDir; + uint id : SV_VertexID; + float4 screenPos; + INTERNAL_DATA + }; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + void vert(inout appdata_full_plus_id v, out Input o) { + PrepForOds(v.vertex); + + float radius = v.texcoord.z; + + // Squeeze displacement + float squeeze = sin(v.texcoord.x*3.14159); + float3 squeeze_displacement = radius * v.normal.xyz * squeeze; + v.vertex.xyz -= squeeze_displacement * _SqueezeAmount; + + // Perturb normal + v.normal = normalize(v.normal + squeeze_displacement * 2.5); + + o.color = TbVertToSrgb(o.color); + UNITY_INITIALIZE_OUTPUT(Input, o); + o.tex = v.texcoord.xy; + o.id = v.id; + } + + // Input color is srgb + void surf (Input IN, inout SurfaceOutputStandardSpecular o) { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(IN.id.x > _ClipStart && IN.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(IN.screenPos.xy / IN.screenPos.w * _ScreenParams) >= _Dissolve) discard; + #endif + + o.Albedo = _Color.rgb * IN.color.rgb; + //o.Emission = _Color.rgb * IN.color.rgb; + o.Smoothness = _Shininess; + o.Specular = _SpecColor * IN.color.rgb; + + // Calculate rim + float3 n = WorldNormalVector (IN, o.Normal); + half rim = 1.0 - abs(dot (normalize(IN.viewDir), n)); + rim *= 1-pow(rim,5); + + //Thin slit diffraction texture ramp lookup + float3 diffraction = tex2D(_MainTex, half2(rim + GetTime().x + o.Normal.y, rim + o.Normal.y)).xyz; + o.Emission = rim*(.25 * diffraction * rim + .75 * diffraction * IN.color); + + } + ENDCG + } +} + FallBack "Diffuse" +} diff --git a/Assets/Resources/X/Brushes/Race/Race.shader b/Assets/Resources/X/Brushes/Race/Race.shader index c41925c035..75ad2a344c 100644 --- a/Assets/Resources/X/Brushes/Race/Race.shader +++ b/Assets/Resources/X/Brushes/Race/Race.shader @@ -1,183 +1,202 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Race" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #pragma target 3.0 - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/ColorSpace.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - #define BRUSHES_DIGITAL_ROWS 5 - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR { - // copied from Digital.shader with a modification on the chance - // that a tile will connect with its neighbor - float stroke_width = .1; - float antialias_feather_px = 4; - - float2 st = i.texcoord; - - // used for antialiasing - float2 st_per_px = fwidth(st); - - // create the grid. - // rc means row,col. rc.x actually really means x i.e. it's columns - float2 rc = floor(st); - - // get the tile coordinates - // map tile_st.y to [-1, 1] - float tile_st = frac(st); - tile_st -= .5; - tile_st *= 2; - - float lum = 0; - float r = length(tile_st); - - // for each neighboring tile... - for (int ii = -1; ii <= 1; ii++) { - if (rc.x + ii < 0) continue; - for (int jj = -1; jj <= 1; jj++) { - if (abs(ii) == abs(jj)) continue; - if (rc.y + jj < 0) continue; - if (rc.y + jj >= BRUSHES_DIGITAL_ROWS) continue; - - // me and my neighbor decide if we should connect our tiles. - // The ascii art below is copied from Digital.shader. The idea is the same, but it - // wouldn't be an exact depiction here, given the specific numbers. - // - // (x) represents random(rc) - // [x] represents random(rc) + random(rc + ij) - // - // (0.5)xx[1.3]xx(0.8) - // x - // x - // [1.1] [0.4] - // x - // x - // (0.6) [0.7] (0.1) - // - // if i'm (0.5), then i'm going to draw (0.5)xxx---(0.8) - // if i'm (0.8), then i'm going to draw (0.5)---xxx(0.8) - if (ii == 0) { - // horizontal connections are more likely to connect - if (random(rc) + random(rc + float2(ii, jj)) < 1.5) continue; - } else { - // vertical connections are less likely to connect - if (random(rc) + random(rc + float2(ii, jj)) < .5) continue; - } - - // draw a rectangle with width stroke_width through the center of - // this tile towards the other tile - // i=0,j=1 i=-1,j=0 - // ( --111-- ------- ) --111-- - // ( --111-- ------- ) --111-- - // ( --111-- 11111-- ) 11111-- - // max( --111-- , 11111-- ) = 11111-- - // ( --111-- 11111-- ) 11111-- - // ( ------- ------- ) ------- - // ( ------- ------- ) ------- - - float2 ij = float2(ii, jj); - float2 ij_perp = float2(-jj, ii); - // when ij points to the right: - // bound1 is bottomleft - // bound2 is topright - float2 bound1 = stroke_width * -ij_perp + stroke_width * -ij; - float2 bound2 = ij + stroke_width * ij_perp; - float2 min_bound = min(bound1, bound2); - float2 max_bound = max(bound1, bound2); - - float2 aa_feather = st_per_px * antialias_feather_px; - float current_lum = - smoothstep(min_bound.x - aa_feather.x, min_bound.x, st.x) * - smoothstep(max_bound.x + aa_feather.x, max_bound.x, st.x) * - smoothstep(min_bound.y - aa_feather.y, min_bound.y, st.y) * - smoothstep(max_bound.y + aa_feather.y, max_bound.y, st.y); - lum = max(lum, current_lum); - } - } - fixed4 color; - color.a = 1; - color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Race" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #pragma target 3.0 + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/ColorSpace.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + #define BRUSHES_DIGITAL_ROWS 5 + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR { + + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // copied from Digital.shader with a modification on the chance + // that a tile will connect with its neighbor + float stroke_width = .1; + float antialias_feather_px = 4; + + float2 st = i.texcoord; + + // used for antialiasing + float2 st_per_px = fwidth(st); + + // create the grid. + // rc means row,col. rc.x actually really means x i.e. it's columns + float2 rc = floor(st); + + // get the tile coordinates + // map tile_st.y to [-1, 1] + float tile_st = frac(st); + tile_st -= .5; + tile_st *= 2; + + float lum = 0; + float r = length(tile_st); + + // for each neighboring tile... + for (int ii = -1; ii <= 1; ii++) { + if (rc.x + ii < 0) continue; + for (int jj = -1; jj <= 1; jj++) { + if (abs(ii) == abs(jj)) continue; + if (rc.y + jj < 0) continue; + if (rc.y + jj >= BRUSHES_DIGITAL_ROWS) continue; + + // me and my neighbor decide if we should connect our tiles. + // The ascii art below is copied from Digital.shader. The idea is the same, but it + // wouldn't be an exact depiction here, given the specific numbers. + // + // (x) represents random(rc) + // [x] represents random(rc) + random(rc + ij) + // + // (0.5)xx[1.3]xx(0.8) + // x + // x + // [1.1] [0.4] + // x + // x + // (0.6) [0.7] (0.1) + // + // if i'm (0.5), then i'm going to draw (0.5)xxx---(0.8) + // if i'm (0.8), then i'm going to draw (0.5)---xxx(0.8) + if (ii == 0) { + // horizontal connections are more likely to connect + if (random(rc) + random(rc + float2(ii, jj)) < 1.5) continue; + } else { + // vertical connections are less likely to connect + if (random(rc) + random(rc + float2(ii, jj)) < .5) continue; + } + + // draw a rectangle with width stroke_width through the center of + // this tile towards the other tile + // i=0,j=1 i=-1,j=0 + // ( --111-- ------- ) --111-- + // ( --111-- ------- ) --111-- + // ( --111-- 11111-- ) 11111-- + // max( --111-- , 11111-- ) = 11111-- + // ( --111-- 11111-- ) 11111-- + // ( ------- ------- ) ------- + // ( ------- ------- ) ------- + + float2 ij = float2(ii, jj); + float2 ij_perp = float2(-jj, ii); + // when ij points to the right: + // bound1 is bottomleft + // bound2 is topright + float2 bound1 = stroke_width * -ij_perp + stroke_width * -ij; + float2 bound2 = ij + stroke_width * ij_perp; + float2 min_bound = min(bound1, bound2); + float2 max_bound = max(bound1, bound2); + + float2 aa_feather = st_per_px * antialias_feather_px; + float current_lum = + smoothstep(min_bound.x - aa_feather.x, min_bound.x, st.x) * + smoothstep(max_bound.x + aa_feather.x, max_bound.x, st.x) * + smoothstep(min_bound.y - aa_feather.y, min_bound.y, st.y) * + smoothstep(max_bound.y + aa_feather.y, max_bound.y, st.y); + lum = max(lum, current_lum); + } + } + fixed4 color; + color.a = 1; + color.rgb = lum*bloomColor(i.color,lum*_EmissionGain); + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Rain/Rain.shader b/Assets/Resources/X/Brushes/Rain/Rain.shader index ddb013f371..d4c91ebcb6 100644 --- a/Assets/Resources/X/Brushes/Rain/Rain.shader +++ b/Assets/Resources/X/Brushes/Rain/Rain.shader @@ -1,161 +1,187 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Rain" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _NumSides("Number of Sides", Float) = 5 - _Speed("Speed", Float) = 1 - _Bulge("Displacement Amount", Float) = 2.25 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile_particles - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - float4 _MainTex_ST; - float _NumSides; - float _Speed; - float _Bulge; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - float4 worldPos : TEXCOORD1; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - - v2f vert (appdata_full v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - // Inflate the tube outward to explode it into - // strips - giving us negative space w/o as much overdraw. - _Bulge = 2.25; - float radius = v.texcoord.z; - v.vertex.xyz += v.normal.xyz * _Bulge * radius; - - o.worldPos = mul(unity_ObjectToWorld, v.vertex); - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = TbVertToNative(v.color); - return o; - } - - float rand_1_05(in float2 uv) - { - float2 noise = (frac(sin(dot(uv, float2(12.9898, 78.233)*2.0)) * 4550)); - return abs(noise.x) * 0.7; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - float u_scale = _Speed; - float t = fmod(_Time.y * 4 * u_scale, u_scale); - - // Rescale U coord in range 0 : u_scale. - // Note that we subtract "t" because we want to move the origin (i.e. the "0" value) - // of the U coordinate along the length of the stroke - // - // e.g. - // 0 1 2 3 4 5 6 ... - // -1 0 1 2 3 4 5 - // -2 -1 0 1 2 3 4 - // - // where the texture will begin at u = 0 - // - float2 uvs = i.texcoord; - float u = uvs.x * u_scale - t; - - // Calculate a an ID value for each face. - // on a 4 sided tube, the v coords are 0:.25, .25:.5, .5,.75, .75:1 - // so multiplying by number of sides and taking the integer is the ID - // *NOTE: we should ask jeremy I think this only actually works because of float precisions - - float row_id = (int) (uvs.y *(_NumSides)); - float rand = rand_1_05(row_id.xx); - - // Randomize by row ID, add _Time offset by row and add an offset back into U - // so the strips don't animate together - u += rand * _Time.y * 2.75 * u_scale; - - // Wrap the u coordinate in the 0:u_scale range. - // If we don't do this, then the strokes we offset previously - // will have values that are too large - u = fmod(u, u_scale); - - // Rescale the V coord of each strip in the 0:1 range - float v = uvs.y * _NumSides; - - // Sample final texture - half4 tex = tex2D(_MainTex, half2(u,v)); - - tex = u < 0 ? 0 : tex; - tex = u > 1 ? 0 : tex; - - // Fade at edges of a given stroke - float fade = pow(abs(i.texcoord.x * 0.25), 9); - float4 color = i.color * tex; - float4 finalColor = lerp(color, float4(0, 0, 0, 0), saturate(fade)); - - color = encodeHdr(finalColor.rgb * finalColor.a); - color = SrgbToNative(color); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Rain" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _NumSides("Number of Sides", Float) = 5 + _Speed("Speed", Float) = 1 + _Bulge("Displacement Amount", Float) = 2.25 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile_particles + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + float4 _MainTex_ST; + float _NumSides; + float _Speed; + float _Bulge; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_full_plus_id { + float4 vertex : POSITION; + float4 tangent : TANGENT; + float3 normal : NORMAL; + float4 texcoord : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + float4 texcoord3 : TEXCOORD3; + fixed4 color : COLOR; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + float4 worldPos : TEXCOORD1; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + v2f vert (appdata_full_plus_id v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + // Inflate the tube outward to explode it into + // strips - giving us negative space w/o as much overdraw. + _Bulge = 2.25; + float radius = v.texcoord.z; + v.vertex.xyz += v.normal.xyz * _Bulge * radius; + + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = TbVertToNative(v.color); + o.id = (float2)v.id; + return o; + } + + float rand_1_05(in float2 uv) + { + float2 noise = (frac(sin(dot(uv, float2(12.9898, 78.233)*2.0)) * 4550)); + return abs(noise.x) * 0.7; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float u_scale = _Speed; + float t = fmod(GetTime().y * 4 * u_scale, u_scale); + + // Rescale U coord in range 0 : u_scale. + // Note that we subtract "t" because we want to move the origin (i.e. the "0" value) + // of the U coordinate along the length of the stroke + // + // e.g. + // 0 1 2 3 4 5 6 ... + // -1 0 1 2 3 4 5 + // -2 -1 0 1 2 3 4 + // + // where the texture will begin at u = 0 + // + float2 uvs = i.texcoord; + float u = uvs.x * u_scale - t; + + // Calculate a an ID value for each face. + // on a 4 sided tube, the v coords are 0:.25, .25:.5, .5,.75, .75:1 + // so multiplying by number of sides and taking the integer is the ID + // *NOTE: we should ask jeremy I think this only actually works because of float precisions + + float row_id = (int) (uvs.y *(_NumSides)); + float rand = rand_1_05(row_id.xx); + + // Randomize by row ID, add GetTime() offset by row and add an offset back into U + // so the strips don't animate together + u += rand * GetTime().y * 2.75 * u_scale; + + // Wrap the u coordinate in the 0:u_scale range. + // If we don't do this, then the strokes we offset previously + // will have values that are too large + u = fmod(u, u_scale); + + // Rescale the V coord of each strip in the 0:1 range + float v = uvs.y * _NumSides; + + // Sample final texture + half4 tex = tex2D(_MainTex, half2(u,v)); + + tex = u < 0 ? 0 : tex; + tex = u > 1 ? 0 : tex; + + // Fade at edges of a given stroke + float fade = pow(abs(i.texcoord.x * 0.25), 9); + float4 color = i.color * tex; + float4 finalColor = lerp(color, float4(0, 0, 0, 0), saturate(fade)); + + color = encodeHdr(finalColor.rgb * finalColor.a); + color = SrgbToNative(color); + return color * _Opacity; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.mat b/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.mat index fa11a06db3..dd42d34388 100644 --- a/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.mat +++ b/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.mat @@ -2,14 +2,16 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: RisingBubbles m_Shader: {fileID: 4800000, guid: c4285dcf87bf5b84d8d4bbec752f1883, type: 3} - m_ShaderKeywords: _EMISSION + m_ValidKeywords: [] + m_InvalidKeywords: + - _EMISSION m_LightmapFlags: 1 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -55,9 +57,12 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _BaseGain: 0.4 - _BumpScale: 1 + - _ClipEnd: -1 + - _ClipStart: 0 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 - _DstBlend: 0 @@ -68,6 +73,8 @@ Material: - _Metallic: 0 - _Mode: 0 - _OcclusionStrength: 1 + - _Opacity: 1 + - _OverrideTime: 0 - _Parallax: 0.02 - _ScrollJitterFrequency: 5 - _ScrollJitterIntensity: 0.2 @@ -79,6 +86,8 @@ Material: - _SpreadRate: 1.25 - _SpreadSize: 1.25 - _SrcBlend: 1 + - _TimeBlend: 0 + - _TimeSpeed: 1 - _UVSec: 0 - _WaveformFreq: 0.1 - _ZWrite: 1 @@ -87,5 +96,7 @@ Material: - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _ScrollDistance: {r: 0.5, g: 5, b: 0, a: 0.5} - _SpecColor: {r: 0.5, g: 0.5, b: 0.5, a: 0} + - _TimeOverrideValue: {r: 0, g: 0, b: 0, a: 0} - _TintColor: {r: 1, g: 1, b: 1, a: 1} - _WaveformIntensity: {r: 0, g: 15, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.shader b/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.shader index fbdeac431a..ee7f4f1340 100644 --- a/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.shader +++ b/Assets/Resources/X/Brushes/RisingBubbles/RisingBubbles.shader @@ -1,155 +1,178 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Particle/RisingBubbles" { -Properties { - _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) - _MainTex ("Particle Texture", 2D) = "white" {} - _ScrollRate("Scroll Rate", Float) = 1.0 - _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) - _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 - _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 - _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } - Blend One One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/Particles.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - fixed4 _TintColor; - - struct v2f { - float4 vertex : SV_POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - float _ScrollRate; - // In decimeters - float3 _ScrollDistance; - // Amplitude: in decimeters - float _ScrollJitterIntensity; - float _ScrollJitterFrequency; - float _SpreadRate; - - // pos and seed should be stable values. - // seed is a value in [0, 1] - // t01 is a time value in [0, 1] - float3 ComputeDisplacement(float3 pos, float seed, float t01) { - float t2 = _Time.y / 3; - - // Animate the motion of the bubbles - // Accumulate all displacement into a common, pre-transformed space. - float4 dispVec = float4(_ScrollDistance, 0.0) * t01; - - // Overall motion of the bubbles - dispVec.x += sin(t01 * _ScrollJitterFrequency + seed * 10 + t2 + pos.z) * _ScrollJitterIntensity; - dispVec.y += (fmod(seed * 100, 1) - 0.5) * _ScrollDistance.y * t01; - dispVec.z += cos(t01 * _ScrollJitterFrequency + seed * 7 + t2 + pos.x) * _ScrollJitterIntensity; - - return dispVec * kDecimetersToWorldUnits; - } - - v2f vert (ParticleVertexWithSpread_t v) { - v.color = TbVertToSrgb(v.color); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - // Used as a random-ish seed for various calculations - float seed = v.color.a; - float t01 = fmod(_Time.y*_ScrollRate + seed * 10, 1); - float birthTime = v.texcoord.w; - float rotation = v.texcoord.z; - float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); - float spreadProgress = SpreadProgress(birthTime, _SpreadRate); - float4 center = SpreadParticle(v, spreadProgress); - float3 disp = ComputeDisplacement(center.xyz, seed, t01); - disp = spreadProgress * disp; - - // Dim over lifetime - v.color.rgb *= pow (1 - t01, 1)*5; - - // Custom vertex animation -#if 1 - // Displacement is in scene space - // Note that xf_CS is actually scene, not canvas - // The problem with this is that if you scale up a layer, the particles - // get big but the overall motion stays the same. - float4 center_WS = mul(unity_ObjectToWorld, center); - center_WS.xyz += mul(xf_CS, disp); - PrepForOdsWorldSpace(center_WS); - float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); - o.vertex = mul(UNITY_MATRIX_VP, corner_WS); -#else - // Displacement is in canvas space - // Note that we assume object space == canvas space (which it is, for TB) - - PrepForOds(center); - float4 corner = OrientParticle(center + disp, halfSize, v.vid, rotation); - o.vertex UnityObjectToClipPos(corner); -#endif - - o.color = v.color; - o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); - - return o; - } - - // i.color is srgb - fixed4 frag (v2f i) : SV_Target - { - float4 tex = tex2D(_MainTex, i.texcoord); - - // RGB Channels of the texture are affected by color - float3 basecolor = i.color * tex.rgb; - // Alpha channel of the texture is not affected by color. It is the fake "highlight" bubble effect. - float3 highlightcolor = tex.a; - - float4 color = float4(basecolor + highlightcolor, 1); - return SrgbToNative(color); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Particle/RisingBubbles" { +Properties { + _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) + _MainTex ("Particle Texture", 2D) = "white" {} + _ScrollRate("Scroll Rate", Float) = 1.0 + _ScrollDistance("Scroll Distance", Vector) = (1.0, 0, 0) + _ScrollJitterIntensity("Scroll Jitter Intensity", Float) = 1.0 + _ScrollJitterFrequency("Scroll Jitter Frequency", Float) = 1.0 + _SpreadRate ("Spread Rate", Range(0.3, 5)) = 1.539 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True" } + Blend One One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/Particles.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + fixed4 _TintColor; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct v2f { + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + float _ScrollRate; + // In decimeters + float3 _ScrollDistance; + // Amplitude: in decimeters + float _ScrollJitterIntensity; + float _ScrollJitterFrequency; + float _SpreadRate; + + // pos and seed should be stable values. + // seed is a value in [0, 1] + // t01 is a time value in [0, 1] + float3 ComputeDisplacement(float3 pos, float seed, float t01) { + float t2 = GetTime().y / 3; + + // Animate the motion of the bubbles + // Accumulate all displacement into a common, pre-transformed space. + float4 dispVec = float4(_ScrollDistance, 0.0) * t01; + + // Overall motion of the bubbles + dispVec.x += sin(t01 * _ScrollJitterFrequency + seed * 10 + t2 + pos.z) * _ScrollJitterIntensity; + dispVec.y += (fmod(seed * 100, 1) - 0.5) * _ScrollDistance.y * t01; + dispVec.z += cos(t01 * _ScrollJitterFrequency + seed * 7 + t2 + pos.x) * _ScrollJitterIntensity; + + return dispVec * kDecimetersToWorldUnits; + } + + v2f vert (ParticleVertexWithSpread_t v) { + v.color = TbVertToSrgb(v.color); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + // Used as a random-ish seed for various calculations + float seed = v.color.a; + float t01 = fmod(GetTime().y*_ScrollRate + seed * 10, 1); + float birthTime = v.texcoord.w; + float rotation = v.texcoord.z; + float halfSize = GetParticleHalfSize(v.corner.xyz, v.center, birthTime); + float spreadProgress = SpreadProgress(birthTime, _SpreadRate); + float4 center = SpreadParticle(v, spreadProgress); + float3 disp = ComputeDisplacement(center.xyz, seed, t01); + disp = spreadProgress * disp; + + // Dim over lifetime + v.color.rgb *= pow (1 - t01, 1)*5; + + // Custom vertex animation +#if 1 + // Displacement is in scene space + // Note that xf_CS is actually scene, not canvas + // The problem with this is that if you scale up a layer, the particles + // get big but the overall motion stays the same. + float4 center_WS = mul(unity_ObjectToWorld, center); + center_WS.xyz += mul(xf_CS, disp); + PrepForOdsWorldSpace(center_WS); + float4 corner_WS = OrientParticle_WS(center_WS.xyz, halfSize, v.vid, rotation); + o.vertex = mul(UNITY_MATRIX_VP, corner_WS); +#else + // Displacement is in canvas space + // Note that we assume object space == canvas space (which it is, for TB) + + PrepForOds(center); + float4 corner = OrientParticle(center + disp, halfSize, v.vid, rotation); + o.vertex UnityObjectToClipPos(corner); +#endif + + o.color = v.color; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy,_MainTex); + o.id = (float2)v.id; + return o; + } + + // i.color is srgb + fixed4 frag (v2f i) : SV_Target + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float4 tex = tex2D(_MainTex, i.texcoord); + + // RGB Channels of the texture are affected by color + float3 basecolor = i.color * tex.rgb; + // Alpha channel of the texture is not affected by color. It is the fake "highlight" bubble effect. + float3 highlightcolor = tex.a; + + float4 color = float4(basecolor + highlightcolor, 1); + color.a *= _Opacity; + + return SrgbToNative(color * _Opacity); + return color; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Slice/Slice.shader b/Assets/Resources/X/Brushes/Slice/Slice.shader index a24e42c769..1a56bfb05c 100644 --- a/Assets/Resources/X/Brushes/Slice/Slice.shader +++ b/Assets/Resources/X/Brushes/Slice/Slice.shader @@ -1,98 +1,116 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Slice" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend SrcAlpha OneMinusSrcAlpha - AlphaTest Greater .01 - ColorMask RGB - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile_particles - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/ColorSpace.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - // fixed4 color : COLOR; - // float3 normal : NORMAL; - float3 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - // fixed4 color : COLOR; - float3 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = v.texcoord; - return o; - } - - float random( float2 p ) - { - const float2 r = float2(23.14079263, 2.7651234); - return frac( cos( fmod( 123432189., 1e-7 + 256. * dot(p,r) ) ) ); - } - - fixed4 frag (v2f i) : COLOR - { - //float rubbishRand = random(i.texcoord.xz); - //clip(rubbishRand-.9); - - float4 tex; - float hue = fmod(i.texcoord.z * 5, 6); - float3 base_rgb = hue06_to_base_rgb(hue); - tex.rgb = cy_to_rgb(base_rgb, i.texcoord.x, i.texcoord.y); - tex.a = .3; - - // With MSAA enabled, RGB values in tex are > 1.0, but was not intented. - return saturate(tex); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Slice" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend SrcAlpha OneMinusSrcAlpha + AlphaTest Greater .01 + ColorMask RGB + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_particles + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/ColorSpace.cginc" + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + // fixed4 color : COLOR; + // float3 normal : NORMAL; + float3 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + // fixed4 color : COLOR; + float3 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + v2f vert (appdata_t v) + { + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = v.texcoord; + o.id = (float2)v.id; + return o; + } + + float random( float2 p ) + { + const float2 r = float2(23.14079263, 2.7651234); + return frac( cos( fmod( 123432189., 1e-7 + 256. * dot(p,r) ) ) ); + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.pos.xy) >= _Dissolve) discard; + #endif + + //float rubbishRand = random(i.texcoord.xz); + //clip(rubbishRand-.9); + + float4 tex; + float hue = fmod(i.texcoord.z * 5, 6); + float3 base_rgb = hue06_to_base_rgb(hue); + tex.rgb = cy_to_rgb(base_rgb, i.texcoord.x, i.texcoord.y); + tex.a = _Opacity; + + // With MSAA enabled, RGB values in tex are > 1.0, but was not intented. + return saturate(tex); + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Space/Space.shader b/Assets/Resources/X/Brushes/Space/Space.shader index 1f7620cdc4..7817e97264 100644 --- a/Assets/Resources/X/Brushes/Space/Space.shader +++ b/Assets/Resources/X/Brushes/Space/Space.shader @@ -1,144 +1,166 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Space" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One // SrcAlpha One - BlendOp Add, Min - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - - #pragma target 3.0 - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - #include "Assets/Shaders/Include/ColorSpace.cginc" - #include "Assets/Shaders/Include/Math.cginc" - #include "Assets/ThirdParty/Shaders/Noise.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = v.color; - return o; - } - - // Input color is srgb - fixed4 frag (v2f i) : COLOR - { - float analog_spread = .1; // how far the analogous hues are from the primary - float gain = 10; - float gain2 = 0; - - // primary hue is chosen by user - float3 i_HSV = RGBtoHSV(i.color.rgb); - - // we're gonna mix these 3 colors together - float primary_hue = i_HSV.x; - float analog1_hue = frac(primary_hue - analog_spread); - float analog2_hue = frac(primary_hue + analog_spread); - - float r = abs(i.texcoord.y * 2 - 1); // distance from center of stroke - - // determine the contributions of each hue - float primary_a = .2 * fbm(i.texcoord + _Time.x) * gain + gain2; - float analog1_a = .2 * fbm(float3(i.texcoord.x + 12.52, i.texcoord.y + 12.52, _Time.x * 5.2)) * gain + gain2; - float analog2_a = .2 * fbm(float3(i.texcoord.x + 6.253, i.texcoord.y + 6.253, _Time.x * .8)) * gain + gain2; - - // the main hue is present in the center and falls off with randomized radius - primary_a = clampedRemap(0, .5, primary_a, 0, r + fbm(float2(_Time.x + 50, i.texcoord.x)) * 2); - - // the analog hues start a little out from the center and increase with intensity going out - analog1_a = clampedRemap(.2, 1, 0, analog1_a * 1.2, r); - analog2_a = clampedRemap(.2, 1, 0, analog2_a * 1.2, r); - - fixed4 color; - color.a = primary_a + analog1_a + analog2_a; - - float final_hue = - primary_a * (primary_hue) + - analog1_a * (analog1_hue) + - analog2_a * (analog2_hue); - final_hue /= color.a; - - // now sculpt the overall shape of the stroke - float lum = 1 - r; - float rfbm = fbm(float2(i.texcoord.x, _Time.x)); - rfbm += 1.2; - rfbm *= .8; - lum *= step(r, rfbm); // shorten the radius with fbm - - // blur the edge a little bit - lum *= smoothstep(rfbm, rfbm - .2, r); - - color.rgb = HSVToRGB(float3(final_hue, i_HSV.y, i_HSV.z * lum)); - color = saturate(color); // i'm not sure why it's so bright without this - color = bloomColor(color,_EmissionGain); - color = SrgbToNative(color); - color = encodeHdr(color.rgb); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Space" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One // SrcAlpha One + BlendOp Add, Min + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #pragma target 3.0 + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + #include "Assets/Shaders/Include/ColorSpace.cginc" + #include "Assets/Shaders/Include/Math.cginc" + #include "Assets/ThirdParty/Shaders/Noise.cginc" + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = v.color; + o.id = (float2)v.id; + return o; + } + + // Input color is srgb + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + float analog_spread = .1; // how far the analogous hues are from the primary + float gain = 10; + float gain2 = 0; + + // primary hue is chosen by user + float3 i_HSV = RGBtoHSV(i.color.rgb); + + // we're gonna mix these 3 colors together + float primary_hue = i_HSV.x; + float analog1_hue = frac(primary_hue - analog_spread); + float analog2_hue = frac(primary_hue + analog_spread); + + float r = abs(i.texcoord.y * 2 - 1); // distance from center of stroke + + // determine the contributions of each hue + float primary_a = .2 * fbm(i.texcoord + GetTime().x) * gain + gain2; + float analog1_a = .2 * fbm(float3(i.texcoord.x + 12.52, i.texcoord.y + 12.52, GetTime().x * 5.2)) * gain + gain2; + float analog2_a = .2 * fbm(float3(i.texcoord.x + 6.253, i.texcoord.y + 6.253, GetTime().x * .8)) * gain + gain2; + + // the main hue is present in the center and falls off with randomized radius + primary_a = clampedRemap(0, .5, primary_a, 0, r + fbm(float2(GetTime().x + 50, i.texcoord.x)) * 2); + + // the analog hues start a little out from the center and increase with intensity going out + analog1_a = clampedRemap(.2, 1, 0, analog1_a * 1.2, r); + analog2_a = clampedRemap(.2, 1, 0, analog2_a * 1.2, r); + + fixed4 color; + color.a = primary_a + analog1_a + analog2_a; + + float final_hue = + primary_a * (primary_hue) + + analog1_a * (analog1_hue) + + analog2_a * (analog2_hue); + final_hue /= color.a; + + // now sculpt the overall shape of the stroke + float lum = 1 - r; + float rfbm = fbm(float2(i.texcoord.x, GetTime().x)); + rfbm += 1.2; + rfbm *= .8; + lum *= step(r, rfbm); // shorten the radius with fbm + + // blur the edge a little bit + lum *= smoothstep(rfbm, rfbm - .2, r); + + color.rgb = HSVToRGB(float3(final_hue, i_HSV.y, i_HSV.z * lum)); + color = saturate(color); // i'm not sure why it's so bright without this + color = bloomColor(color,_EmissionGain); + color = SrgbToNative(color); + color = encodeHdr(color.rgb); + + return color; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/Sparks/Sparks.shader b/Assets/Resources/X/Brushes/Sparks/Sparks.shader index 263b1fa546..53c7cb55c4 100644 --- a/Assets/Resources/X/Brushes/Sparks/Sparks.shader +++ b/Assets/Resources/X/Brushes/Sparks/Sparks.shader @@ -1,173 +1,193 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Sparks" { -Properties { - _MainTex ("Particle Texture", 2D) = "white" {} - _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 - _DisplacementAmount ("Displacement Amount", Float) = 1 - _DisplacementExponent ("Displacement Exponent", Float) = 3 - _StretchDistortionExponent ("Stretch Distortion Exponent", Float) = 3 - _NumSides ("Number of Sides", Float) = 5 - _Speed ("Speed", Float) = 1 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile_particles - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma target 3.0 - - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - float4 _MainTex_ST; - half _EmissionGain; - float _DisplacementAmount; - float _DisplacementExponent; - float _StretchDistortionExponent; - float _NumSides; - float _Speed; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v.color = TbVertToSrgb(v.color); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - // This multiplier is a magic number but it's still not right. Is there a better - // multiplciation for this (not using fmod) so I can count on the "lifetime" being contstant? - /* - float t01 = fmod(_Time.y * 0.95, 1); - float3 incolor = v.color.rgb; - v.color.rgb *= incolor * pow(1 - t01, 2) * 10; - */ - - float displacement = pow(v.texcoord.x,_DisplacementExponent); - v.vertex.xyz += v.normal * displacement * _DisplacementAmount; - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = TbVertToNative(v.color); - return o; - } - - float rand_1_05(in float2 uv) - { - float2 noise = (frac(sin(dot(uv, float2(12.9898, 78.233)*2.0)) * 50)); - return abs(noise.x + noise.y) * 0.75; - } - - fixed4 frag (v2f i) : COLOR - { - - // Distort U coord to taste. This makes the effect to "slow down" towards the end of the stroke - // by clumping UV's closer together toward the beginning of the stroke - i.texcoord.x = pow(i.texcoord.x, _StretchDistortionExponent); - - // Rescale time to go between 0 : u_scale, where u_scale is the range of warped u coords on the stroke - float u_scale = _Speed; - float t = fmod(_Time.w * u_scale, u_scale); - - // Rescale U coord in range 0 : u_scale. - // Note that we subtract "t" because we want to move the origin (i.e. the "0" value) - // of the U coordinate along the length of the stroke - // - // e.g. - // 0 1 2 3 4 5 6 ... - // -1 0 1 2 3 4 5 - // -2 -1 0 1 2 3 4 - // - // where the texture will begin at u = 0 - // - float2 uvs = i.texcoord; - float u = uvs.x * u_scale - t; - - // Calculate a an ID value for each face. - // on a 4 sided tube, the v coords are 0:.25, .25:.5, .5,.75, .75:1 - // so multiplying by number of sides and taking the integer is the ID - // *NOTE: we should ask jeremy I think this only actually works because of float precision - float row_id = (int) (uvs.y * (_NumSides)); - float rand = rand_1_05(row_id.xx); - - // Randomize by row ID and add an offset back into U, so the strips don't animate together - u += rand * u_scale; - - // Wrap the u coordinate in the 0:u_scale range. - // If we don't do this, then the strokes we offset previously - // will have values that are too large - u = fmod(u, u_scale); - - // Rescale the V coord of each strip in the 0:1 range - float v = uvs.y * _NumSides; - - // Sample texture - float4 tex = tex2D(_MainTex, half2(u, v)); - - // Because texture is set to repeat, manually clamp - // to zero outside texture bounds - tex = u < 0 ? 0 : tex; - tex = u > 1 ? 0 : tex; - - // Apply bloom based on a falloff down the stroke - float bloom = exp(_EmissionGain * 5.0f) * (1 - i.texcoord.x); - - float4 color = i.color * tex * bloom; - color = encodeHdr(color.rgb * color.a); - color = SrgbToNative(color); - return color; - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Sparks" { +Properties { + _MainTex ("Particle Texture", 2D) = "white" {} + _EmissionGain ("Emission Gain", Range(0, 1)) = 0.5 + _DisplacementAmount ("Displacement Amount", Float) = 1 + _DisplacementExponent ("Displacement Exponent", Float) = 3 + _StretchDistortionExponent ("Stretch Distortion Exponent", Float) = 3 + _NumSides ("Number of Sides", Float) = 5 + _Speed ("Speed", Float) = 1 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Dissolve("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile_particles + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma target 3.0 + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + float4 _MainTex_ST; + half _EmissionGain; + float _DisplacementAmount; + float _DisplacementExponent; + float _StretchDistortionExponent; + float _NumSides; + float _Speed; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v.color = TbVertToSrgb(v.color); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + // This multiplier is a magic number but it's still not right. Is there a better + // multiplciation for this (not using fmod) so I can count on the "lifetime" being contstant? + /* + float t01 = fmod(GetTime().y * 0.95, 1); + float3 incolor = v.color.rgb; + v.color.rgb *= incolor * pow(1 - t01, 2) * 10; + */ + + float displacement = pow(v.texcoord.x,_DisplacementExponent); + v.vertex.xyz += v.normal * displacement * _DisplacementAmount; + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = TbVertToNative(v.color); + o.id = (float2)v.id; + return o; + } + + float rand_1_05(in float2 uv) + { + float2 noise = (frac(sin(dot(uv, float2(12.9898, 78.233)*2.0)) * 50)); + return abs(noise.x + noise.y) * 0.75; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // Distort U coord to taste. This makes the effect to "slow down" towards the end of the stroke + // by clumping UV's closer together toward the beginning of the stroke + i.texcoord.x = pow(i.texcoord.x, _StretchDistortionExponent); + + // Rescale time to go between 0 : u_scale, where u_scale is the range of warped u coords on the stroke + float u_scale = _Speed; + float t = fmod(GetTime().w * u_scale, u_scale); + + // Rescale U coord in range 0 : u_scale. + // Note that we subtract "t" because we want to move the origin (i.e. the "0" value) + // of the U coordinate along the length of the stroke + // + // e.g. + // 0 1 2 3 4 5 6 ... + // -1 0 1 2 3 4 5 + // -2 -1 0 1 2 3 4 + // + // where the texture will begin at u = 0 + // + float2 uvs = i.texcoord; + float u = uvs.x * u_scale - t; + + // Calculate a an ID value for each face. + // on a 4 sided tube, the v coords are 0:.25, .25:.5, .5,.75, .75:1 + // so multiplying by number of sides and taking the integer is the ID + // *NOTE: we should ask jeremy I think this only actually works because of float precision + float row_id = (int) (uvs.y * (_NumSides)); + float rand = rand_1_05(row_id.xx); + + // Randomize by row ID and add an offset back into U, so the strips don't animate together + u += rand * u_scale; + + // Wrap the u coordinate in the 0:u_scale range. + // If we don't do this, then the strokes we offset previously + // will have values that are too large + u = fmod(u, u_scale); + + // Rescale the V coord of each strip in the 0:1 range + float v = uvs.y * _NumSides; + + // Sample texture + float4 tex = tex2D(_MainTex, half2(u, v)); + + // Because texture is set to repeat, manually clamp + // to zero outside texture bounds + tex = u < 0 ? 0 : tex; + tex = u > 1 ? 0 : tex; + + // Apply bloom based on a falloff down the stroke + float bloom = exp(_EmissionGain * 5.0f) * (1 - i.texcoord.x); + + float4 color = i.color * tex * bloom; + color = encodeHdr(color.rgb * color.a); + color = SrgbToNative(color); + return color * _Dissolve; + } + ENDCG + } + } +} +} diff --git a/Assets/Resources/X/Brushes/TaperedHueShift/TaperedHueShift.shader b/Assets/Resources/X/Brushes/TaperedHueShift/TaperedHueShift.shader index 80e4db5187..766a428dc9 100644 --- a/Assets/Resources/X/Brushes/TaperedHueShift/TaperedHueShift.shader +++ b/Assets/Resources/X/Brushes/TaperedHueShift/TaperedHueShift.shader @@ -1,104 +1,119 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/TaperedHueShift" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 - -} - -SubShader { - Pass { - Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} - Lighting Off - Cull Off - - CGPROGRAM - - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #pragma multi_compile_fog - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/ColorSpace.cginc" - #include "UnityCG.cginc" - - sampler2D _MainTex; - float _Cutoff; - - struct appdata_t { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - float2 texcoord : TEXCOORD0; - float4 color : COLOR; - UNITY_FOG_COORDS(1) - - UNITY_VERTEX_OUTPUT_STEREO - }; - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - - o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = v.texcoord; - o.color = TbVertToNative(v.color); - UNITY_TRANSFER_FOG(o, o.vertex); - return o; - } - - fixed4 frag (v2f i) : COLOR - { - UNITY_APPLY_FOG(i.fogCoord, i.color); - fixed4 c = tex2D(_MainTex, i.texcoord) * i.color; - - // Hijack colorspace to make a hue shift..this is probably awful and technically wrong? - float shift = 5; - shift += i.color; - float3 hueshift = hue06_to_base_rgb(i.color * shift); - fixed4 _ColorShift = float4(hueshift, 1); - - // Discard transparent pixels - if (c.a < _Cutoff) { - discard; - } - - c.a = 1; - - float huevignette = pow(abs(i.texcoord - .5) * 2.0, 2.0); - return lerp(c, _ColorShift, saturate(huevignette)); - } - - ENDCG - } -} - -Fallback "Unlit/Diffuse" - -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/TaperedHueShift" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + + _Dissolve("Dissolve", Range(0,1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +SubShader { + Pass { + Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} + Lighting Off + Cull Off + + CGPROGRAM + + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + #pragma multi_compile_fog + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/ColorSpace.cginc" + #include "UnityCG.cginc" + + sampler2D _MainTex; + float _Cutoff; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + float4 color : COLOR; + uint id : TEXCOORD2; + UNITY_FOG_COORDS(1) + + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = v.texcoord; + o.color = TbVertToNative(v.color); + UNITY_TRANSFER_FOG(o, o.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + UNITY_APPLY_FOG(i.fogCoord, i.color); + fixed4 c = tex2D(_MainTex, i.texcoord) * i.color; + + // Hijack colorspace to make a hue shift..this is probably awful and technically wrong? + float shift = 5; + shift += i.color; + float3 hueshift = hue06_to_base_rgb(i.color * shift); + fixed4 _ColorShift = float4(hueshift, 1); + + // Discard transparent pixels + if (c.a < _Cutoff) { + discard; + } + + c.a = 1; + + float huevignette = pow(abs(i.texcoord - .5) * 2.0, 2.0); + return lerp(c, _ColorShift, saturate(huevignette)); + } + + ENDCG + } +} + +Fallback "Unlit/Diffuse" + +} diff --git a/Assets/Resources/X/Brushes/Wind/Wind.shader b/Assets/Resources/X/Brushes/Wind/Wind.shader index d1d9d9bfc0..c6f7c855fa 100644 --- a/Assets/Resources/X/Brushes/Wind/Wind.shader +++ b/Assets/Resources/X/Brushes/Wind/Wind.shader @@ -1,95 +1,118 @@ -// Copyright 2020 The Tilt Brush Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -Shader "Brush/Special/Wind" { -Properties { - _MainTex ("Texture", 2D) = "white" {} - _Speed ("Animation Speed", Range (0,1)) = 1 -} - -Category { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - Blend One One - BlendOp Add, Min - AlphaTest Greater .01 - ColorMask RGBA - Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } - - SubShader { - Pass { - - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #pragma multi_compile __ AUDIO_REACTIVE - #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE - #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM - #include "UnityCG.cginc" - #include "Assets/Shaders/Include/Brush.cginc" - #include "Assets/Shaders/Include/Hdr.cginc" - - sampler2D _MainTex; - sampler2D _AlphaMask; - float4 _MainTex_ST; - float _Speed; - - struct appdata_t { - float4 vertex : POSITION; - fixed4 color : COLOR; - float3 normal : NORMAL; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct v2f { - float4 vertex : POSITION; - fixed4 color : COLOR; - float2 texcoord : TEXCOORD0; - - UNITY_VERTEX_OUTPUT_STEREO - }; - - - v2f vert (appdata_t v) - { - PrepForOds(v.vertex); - v2f o; - - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_OUTPUT(v2f, o); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); - o.color = TbVertToNative(v.color); - o.vertex = UnityObjectToClipPos(v.vertex); - - return o; - } - - fixed4 frag (v2f i) : COLOR - { - // Simple scrollin' - float time = _Time.y * _Speed; - fixed2 scrollUV = i.texcoord; - scrollUV.x += time * 0.5; - - float4 tex = tex2D(_MainTex, scrollUV); - return encodeHdr(tex * i.color.rgb * i.color.a); - } - ENDCG - } - } -} -} +// Copyright 2020 The Tilt Brush Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Shader "Brush/Special/Wind" { +Properties { + _MainTex ("Texture", 2D) = "white" {} + _Speed ("Animation Speed", Range (0,1)) = 1 + + + _TimeOverrideValue("Time Override Value", Vector) = (0,0,0,0) + _TimeBlend("Time Blend", Float) = 0 + _TimeSpeed("Time Speed", Float) = 1.0 + + _Opacity ("Opacity", Range(0, 1)) = 1 + _Dissolve ("Dissolve", Range(0, 1)) = 1 + _ClipStart("Clip Start", Float) = 0 + _ClipEnd("Clip End", Float) = -1 +} + +Category { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Blend One One + BlendOp Add, Min + AlphaTest Greater .01 + ColorMask RGBA + Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } + + SubShader { + Pass { + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile __ AUDIO_REACTIVE + #pragma multi_compile __ HDR_EMULATED HDR_SIMPLE + #pragma multi_compile __ ODS_RENDER ODS_RENDER_CM + + #include "UnityCG.cginc" + #include "Assets/Shaders/Include/Brush.cginc" + #include "Assets/Shaders/Include/Hdr.cginc" + + sampler2D _MainTex; + sampler2D _AlphaMask; + float4 _MainTex_ST; + float _Speed; + + uniform half _ClipStart; + uniform half _ClipEnd; + uniform half _Dissolve; + uniform half _Opacity; + + struct appdata_t { + float4 vertex : POSITION; + fixed4 color : COLOR; + float3 normal : NORMAL; + float2 texcoord : TEXCOORD0; + uint id : SV_VertexID; + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : POSITION; + fixed4 color : COLOR; + float2 texcoord : TEXCOORD0; + uint id : TEXCOORD2; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + v2f vert (appdata_t v) + { + PrepForOds(v.vertex); + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); + o.color = TbVertToNative(v.color); + o.vertex = UnityObjectToClipPos(v.vertex); + o.id = (float2)v.id; + return o; + } + + fixed4 frag (v2f i) : COLOR + { + #ifdef SHADER_SCRIPTING_ON + if (_ClipEnd > 0 && !(i.id.x > _ClipStart && i.id.x < _ClipEnd)) discard; + if (_Dissolve < 1 && Dither8x8(i.vertex.xy) >= _Dissolve) discard; + #endif + + // Simple scrollin' + float time = GetTime().y * _Speed; + fixed2 scrollUV = i.texcoord; + scrollUV.x += time * 0.5; + + float4 tex = tex2D(_MainTex, scrollUV); + return encodeHdr(tex * i.color.rgb * i.color.a) * _Opacity; + } + ENDCG + } + } +} +}