From Unify Community Wiki
Jump to: navigation, search

This shader shows helpes you to visualize the loss of detail to a texture from any particular compression option, in order to allow you to select the option that best matches your priorities for any given texture.

It does this by subtracting a compressed texture from an uncompressed version of the same texture, taking the absolute value of the difference, magnifying it by a specified amount to help highlight the difference.

If there's no differences, the result would be black. More color means more difference. If magnification is set to 1, subtle differences may be harder to spot, but if magnification is larger, the perceptual importance of differences will tend to be overstated.


The same object, compressed as RGB16, DXT1, PVRTC 2BPP RGB, and PVRTC 4BPP RGB with magnification turned up to 10x.


To use this, find a texture you're interested in. Make a duplicate of it. Change the texture compression settings of one to be either RGB24 or ARGB32 if it has an alpha channel. Change the other to be compressed. Make sure mip-map settings, filtering, and wrap-mode are identical. Apply each image to one of the slots provided by the shader, and apply the material to a plane mesh. Set the view to orthographic projection. Zoom in/out to see how mip-levels fare.

To view changes in the alpha channel, change the scene view from color to alpha.

The slider labeled "White, Red, Green, Blue, Alpha" will let you visualize the error on a per-channel basis, which can be useful since human color discrimination is less precise for some colors (red, blue) than others (green). High-intensity spots in the green channel are thus worse than such spots in the red channel, which is worse than the blue channel.

NOTE: By default, Unity will NOT compress the texture immediately and you'll just see black. In preferences, set "Compress Textures when Importing", and ensure that you do NOT see "(not compressed yet)" on the Format line when inspecting the texture. If you don't want to enable this option, perform a build after setting compression options, to actually compress the textures.

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 "Debug/DeltaShader" {
	Properties {
		_Magnifier ("Magnifier", Range(1.0,10.0)) = 1.0
        _Mask ("White, Red, Green, Blue, Alpha", Range(0, 4)) = 0
		_Uncompressed ("Uncompressed (RGBA)", 2D) = "black" {}
		_Compressed ("Compressed (RGBA)", 2D) = "black" {}
	SubShader {
	    Pass {
	        Blend Off
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_builtin_noshadows
            #pragma fragmentoption ARB_fog_exp2
            #pragma fragmentoption ARB_precision_hint_fastest

            #include "UnityCG.cginc"

            struct appdata_simple {
                float4 vertex : POSITION;
                float4 texcoord : TEXCOORD0;

            struct v2f {
            	float2	uv;

            uniform float4 _Compressed_ST, _Uncompressed_ST;

            v2f vert (appdata_simple v)
            	v2f o;
            	o.pos = mul( glstate.matrix.mvp, v.vertex );
            	o.uv = TRANSFORM_TEX(v.texcoord,_Compressed);
            	return o;

            uniform sampler2D _Compressed;
            uniform sampler2D _Uncompressed;
            uniform float _Magnifier;
            uniform float _Mask;

            float4 frag (v2f i) : COLOR
            	float4 texcolA = tex2D(_Compressed,i.uv);
            	float4 texcolB = tex2D(_Uncompressed,i.uv);

                half4 dT = abs(texcolA - texcolB) * _Magnifier;
                int tmp = round(_Mask);
                half4 colorMask = half4(
                    ((tmp == 0) || (tmp == 1)) ? 1.0 : 0.0,
                    ((tmp == 0) || (tmp == 2)) ? 1.0 : 0.0,
                    ((tmp == 0) || (tmp == 3)) ? 1.0 : 0.0,
                    ((tmp == 0) || (tmp == 4)) ? 1.0 : 0.0
                dT *= colorMask;
            	return dT;
Personal tools