Skip to content

Commit

Permalink
Make noise fx disable when knob is very low.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keijiro Takahashi authored and Keijiro Takahashi committed Jan 22, 2015
1 parent 572972d commit ea54bda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Assets/VJ04/Shaders/VJ04 Vfx.shader
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Shader "Hidden/VJ04 Vfx"

CGINCLUDE

#pragma multi_compile NOISE_OFF NOISE_ON

#include "UnityCG.cginc"

sampler2D _MainTex;
Expand All @@ -27,9 +29,13 @@ Shader "Hidden/VJ04 Vfx"

float4 frag(v2f_img i) : SV_Target
{
#if NOISE_ON
// Noise displacement.
float r = (nrand(float2(i.uv.y * 2, _Time.x)) - 0.5) * 2;
float d = r * _NoiseDisplace * step(_NoiseThreshold, abs(r));
#else
float d = 0;
#endif

// Source color.
float4 s = tex2D(_MainTex, i.uv + float2(d, 0));
Expand Down
14 changes: 12 additions & 2 deletions Assets/VJ04/VJ04Vfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)

if (_noise > 0.01f || _invert > 0.01f || _whiteout > 0.01f)
{
_material.SetFloat("_NoiseThreshold", Mathf.Clamp01(1.0f - _noise * 1.2f));
_material.SetFloat("_NoiseDisplace", 0.01f + Mathf.Pow(_noise, 3) * 0.1f);
if (_noise > 0.01f)
{
_material.EnableKeyword("NOISE_ON");
_material.SetFloat("_NoiseThreshold", Mathf.Clamp01(1.0f - _noise * 1.2f));
_material.SetFloat("_NoiseDisplace", 0.01f + Mathf.Pow(_noise, 3) * 0.1f);
}
else
{
_material.DisableKeyword("NOISE_ON");
}

_material.SetFloat("_Invert", _invert);
_material.SetFloat("_Whiteout", _whiteout);

Graphics.Blit(source, destination, _material);
}
else
Expand Down

0 comments on commit ea54bda

Please sign in to comment.