diff --git a/Cancerspace.shader b/Cancerspace.shader index 0eac1cb..ac9bd33 100644 --- a/Cancerspace.shader +++ b/Cancerspace.shader @@ -31,6 +31,11 @@ [PowerSlider(2.0)]_XWobbleSpeed ("X Speed", Range(0, 100)) = 100 [PowerSlider(2.0)]_YWobbleSpeed ("Y Speed", Range(0, 100)) = 100 + _BumpMap ("Distortion Map (Normal)", 2D) = "bump" {} + _DistortionAmplitude ("Amplitude", Range(-1, 1)) = 0.1 + _BumpMapScrollSpeedX ("Scroll Speed X", Range(-2, 2)) = 0 + _BumpMapScrollSpeedY ("Scroll Speed Y", Range(-2, 2)) = 0 + [PowerSlider(2.0)]_XShake ("X Shake", Range(0, 1)) = 0 [PowerSlider(2.0)]_YShake ("Y Shake", Range(0, 1)) = 0 _XShakeSpeed ("X Shake Speed", Range(0, 300)) = 200 @@ -193,6 +198,11 @@ float _AnimatedSampling; float _BlurRadius; + sampler2D _BumpMap; + float4 _BumpMap_ST; + float _DistortionAmplitude; + float _BumpMapScrollSpeedX, _BumpMapScrollSpeedY; + float2 hash23(float3 p) { if (_AnimatedSampling) p.z += frac(_Time.z) * 4; p = frac(p * float3(400, 450, .1)); @@ -261,9 +271,12 @@ VRFix = .5; #endif - float4 color = tex2D(_MainTex, TRANSFORM_TEX(computeScreenSpaceOverlayUV(i.posWorld), _MainTex)) * _OverlayColor; + float2 screenSpaceOverlayUV = computeScreenSpaceOverlayUV(i.posWorld); + float4 color = tex2D(_MainTex, TRANSFORM_TEX(screenSpaceOverlayUV, _MainTex)) * _OverlayColor; - float2 displace = float2(_XShake * VRFix, _YShake) * sin(_Time.yy * float2(_XShakeSpeed, _YShakeSpeed)) * _ShakeAmplitude; + float2 displace = float2(_XShake, _YShake) * sin(_Time.yy * float2(_XShakeSpeed, _YShakeSpeed)) * _ShakeAmplitude; + displace += UnpackNormal(tex2D(_BumpMap, TRANSFORM_TEX(screenSpaceOverlayUV + _Time.yy * float2(_BumpMapScrollSpeedX, _BumpMapScrollSpeedY), _BumpMap))).xy * _DistortionAmplitude; + displace.x *= VRFix; float2 grabUV = i.projPos.xy / i.projPos.w; diff --git a/Editor/CancerspaceInspector.cs b/Editor/CancerspaceInspector.cs index 51d2ae1..5b881a3 100644 --- a/Editor/CancerspaceInspector.cs +++ b/Editor/CancerspaceInspector.cs @@ -26,6 +26,7 @@ public static class Styles { public static string falloffSettingsTitle = "Falloff Settings"; public static string wobbleSettingsTitle = "Wave Distortion"; public static string blurSettingsTitle = "Blur"; + public static string distortionMapSettingsTitle = "Distortion Mapping"; public static string screenShakeSettingsTitle = "Screen Shake"; public static string overlaySettingsTitle = "Overlay"; public static string screenColorAdjustmentsTitle = "Screen Color Adjustment"; @@ -123,6 +124,11 @@ public CSCategory(string nname, GUIStyle sstyle, CSCategorySetup ssetupDelegate) protected MaterialProperty mirrorReflectionMode; + protected MaterialProperty distortionMap; + protected MaterialProperty distortionAmplitude; + protected MaterialProperty distortionScrollSpeedX; + protected MaterialProperty distortionScrollSpeedY; + protected int customRenderQueue; protected bool initialized; @@ -157,6 +163,11 @@ public void FindProperties(MaterialProperty[] props) { wobbleYTiling = FindProperty("_YWobbleTiling", props); wobbleXSpeed = FindProperty("_XWobbleSpeed", props); wobbleYSpeed = FindProperty("_YWobbleSpeed", props); + + distortionMap = FindProperty("_BumpMap", props); + distortionAmplitude = FindProperty("_DistortionAmplitude", props); + distortionScrollSpeedX = FindProperty("_BumpMapScrollSpeedX", props); + distortionScrollSpeedY = FindProperty("_BumpMapScrollSpeedY", props); shakeXAmount = FindProperty("_XShake", props); shakeYAmount = FindProperty("_YShake", props); @@ -248,6 +259,19 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro me.ShaderProperty(blurSamplingAnimated, blurSamplingAnimated.displayName); }), + new CSCategory(Styles.distortionMapSettingsTitle, defaultStyle, me => { + me.ShaderProperty(distortionMap, distortionMap.displayName); + if (sliderMode) { + me.ShaderProperty(distortionAmplitude, distortionAmplitude.displayName); + me.ShaderProperty(distortionScrollSpeedX, distortionScrollSpeedX.displayName); + me.ShaderProperty(distortionScrollSpeedY, distortionScrollSpeedY.displayName); + } else { + me.FloatProperty(distortionAmplitude, distortionAmplitude.displayName); + me.FloatProperty(distortionScrollSpeedX, distortionScrollSpeedX.displayName); + me.FloatProperty(distortionScrollSpeedY, distortionScrollSpeedY.displayName); + } + }), + new CSCategory(Styles.screenShakeSettingsTitle, defaultStyle, me => { if (sliderMode) { me.ShaderProperty(shakeXAmount, shakeXAmount.displayName);