RefractionEffect

From Unify Community Wiki
Jump to: navigation, search


Author: Nils Daumann.

Contents

Description

The shader in action.

[1]

This is some basic fullscreen refraction effect. It shifts a refraction texture which disorts the screen and also allows to color specific parts.

Works on fragment program capable cards (Radeon 9500+, GeForce FX+, Intel 9xx).

Requires Unity PRO. This script uses texture rendering and Post-processing only available in Unity Pro

Usage

Typical setup

  • Speed (XY) the movement speed.
  • Strength (ZW) the strengths of disortion.
  • Refraction Tilefac is the tiling of the refraction texture.
  • Refraction (RG) is the refraction texture, where usually the red and blue channel of a normalmap are doing a good job.
  • Colormask (B) is a factor defining how much Color effects the refracted pixel.
  • Color is the color you want to give the refracted pixels.


Download

Media:Refraction.zip


ShaderLab - ImageRefractionEffect.shader

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


Shader "Image Effects/Refraction"
{
	Properties
	{
		_SpeedStrength ("Speed (XY), Strength (ZW)", Vector) = (1, 1, 1, 1)
		_RefractTexTiling ("Refraction Tilefac", Float) = 1
		_RefractTex ("Refraction (RG), Colormask (B)", 2D) = "bump" {}
		_Color ("Color (RGB)", Color) = (1, 1, 1, 1)
		_MainTex ("Base (RGB) DON`T TOUCH IT! :)", RECT) = "white" {}
	}

	SubShader
	{
		Pass
		{
			ZTest Always Cull Off ZWrite Off
			Fog{Mode off}
			
			CGPROGRAM
			#pragma vertex vert_img
			#pragma fragment frag
			#pragma fragmentoption ARB_precision_hint_fastest 
			#include "UnityCG.cginc"

			uniform samplerRECT _MainTex;
			uniform sampler2D _RefractTex;
			uniform float4 _SpeedStrength;
			uniform float _RefractTexTiling;
			uniform float4 _Color;

			float4 frag (v2f_img i) : COLOR
			{
				float2 refrtc = i.uv*_RefractTexTiling;
				float4 refract = tex2D(_RefractTex, refrtc+_SpeedStrength.xy*_Time.x);
				refract.rg = refract.rg*2.0-1.0;
				
				float4 original = texRECT(_MainTex, i.uv+refract.rg*_SpeedStrength.zw);
				
				float4 output = lerp(original, original*_Color, refract.b);
				output.a = original.a;
				
				return output;
			}
			ENDCG
		}
	}
	Fallback off
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox