Hey guys,
This material was pretty cool so I wanted to see how easy it would be to do in code so that it will work automatically in any material. Turns out it is pretty easy to modify this code to do it.
You can add this code after line 57 in DistortApplyScreenPS.usf. Replace from there up to OutColor=DistColor;
float2 NewTexCoord2 = TexCoord.xy + DistOffset * 1.05;
FLATTEN if ( NewTexCoord2.x < SceneColorRect.x || NewTexCoord2.x > SceneColorRect.z ||
NewTexCoord2.y < SceneColorRect.y || NewTexCoord2.y > SceneColorRect.w )
{
NewTexCoord2 = TexCoord.xy;
}
float2 NewTexCoord3 = TexCoord.xy + DistOffset * 1.1;
FLATTEN if ( NewTexCoord3.x < SceneColorRect.x || NewTexCoord3.x > SceneColorRect.z ||
NewTexCoord3.y < SceneColorRect.y || NewTexCoord3.y > SceneColorRect.w )
{
NewTexCoord3 = TexCoord.xy;
}
half4 DistColorR = Texture2DSample(SceneColorTexture, SceneColorTextureSampler, NewTexCoord);
half4 DistColorG = Texture2DSample(SceneColorTexture, SceneColorTextureSampler, NewTexCoord2);
half4 DistColorB = Texture2DSample(SceneColorTexture, SceneColorTextureSampler, NewTexCoord3);
half4 DistColor = float4(DistColorR.x, DistColorG.y, DistColorB.z, DistColorR.w);
This will actually be more performant since since sampling scene texture inside of translucent materials causes some overhead cost each time it is used whereas doing it in code will have a constant overhead.
Of course you probably also want to make the 1.05 and 1.1 values I hard coded into parameters or something. But these values are just approximations since there is no real raytracing or correct refraction calculation going on.
After pasting that in you simply have to recompile shaders in the editor with ctrl+shift+period and it only takes a few seconds with this file.