I have a shader that when applied to an object, will render everything behind that object to a texture and then warp it using a bumpmap. The result is something that looks like light refraction but isn’t.
The shader I’m talking about is applied to the sphere on the left. To the right is a sphere using the standard shader with it’s smoothness and metallic turned up to 1.0.
The sphere on the right is using a cubemap from a reflection probe that is higher up in the scene, and it’s warping the image spherically, because it’s a sphere. this makes sense. The sphere on the left doesn’t really make sense because it’s warping its texture with this bumpmap
I was hoping someone could help me find a way to warp the image the way the standard shader warps its cubemap instead of using a bumpmap. I would appreciate it, and thanks in advance.
oh, here’s the actual code for the shader… that might be useful
Shader "Custom/GlassShader"
{
Properties
{
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Colour ("Colour", Color) = (1,1,1,1)
_BumpMap ("Noise text", 2D) = "bump" {}
_Magnitude ("Magnitude", Range(0,1)) = 0.05
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque"}
ZWrite On Lighting Off Cull Off Fog { Mode Off } Blend One Zero
GrabPass { "_GrabTexture" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _GrabTexture;
sampler2D _MainTex;
fixed4 _Colour;
sampler2D _BumpMap;
float _Magnitude;
struct vin_vct
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f_vct
{
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 uvgrab : TEXCOORD1;
};
// Vertex function
v2f_vct vert (vin_vct v)
{
v2f_vct o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = v.texcoord;
o.uvgrab = ComputeGrabScreenPos(o.vertex);
return o;
}
// Fragment function
half4 frag (v2f_vct i) : COLOR
{
half4 mainColour = tex2D(_MainTex, i.texcoord);
half4 bump = tex2D(_BumpMap, i.texcoord);
half2 distortion = UnpackNormal(bump).rg;
i.uvgrab.xy += distortion * _Magnitude;
fixed4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
return col * mainColour * _Colour;
}
ENDCG
}
}
}