-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy dissolve/completion control across from plugin scripting branch
- Loading branch information
Showing
72 changed files
with
10,461 additions
and
8,650 deletions.
There are no files selected for viewing
300 changes: 162 additions & 138 deletions
300
Assets/Resources/Brushes/Basic/Bubbles/Bubbles.shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.