image effects problem

I created some simple effects based on the image effects from the pro assets: Old school effects with shaders

I’m getting reports that it doesn’t run on some machines. The shader is very simple and I wonder what can cause it not running properly.

Here’s the source code for the plasma effect. C#:

using UnityEngine;

public class PlasmaDemo : ImageEffectBase
{
	private Texture2D colorBand;
	
	new void Start ()
	{
		int tl = 512;
		colorBand = new Texture2D (tl, 1);
		for (int i = 0; i < tl; i++) {
			float v = (float)i / (float)tl;
			Color c = new Color();
			c.a = 1;
			
			c.r = Mathf.Sin(v * Mathf.PI);
			c.g = Mathf.Sin (v * Mathf.PI * 2);
			c.b = Mathf.Sin (v * Mathf.PI * 4) * 0.5f + 0.5f;
			
			colorBand.SetPixel (i, 0, c);
		}
		colorBand.Apply();
	}

	void OnRenderImage (RenderTexture source, RenderTexture destination)
	{
		material.SetTexture ("_ColorBand", colorBand);
		Graphics.Blit (source, destination, material);
	}
}

(the ImageEffectBase class is the class from the Pro Standard Assets)

and the shader:

Shader "Effects/Plasma" {
Properties {
	_MainTex ("Base (RGB)", RECT) = "white" {}
	_ColorBand ("Base (RGB)", 2D) = "white" {}
}

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

uniform samplerRECT _MainTex;
uniform sampler2D _ColorBand;

float4 fragSh (v2f_img i) : COLOR
{
	
	float2 ca = float2(0.2, 0.2);
	float2 cb = float2(0.7, 0.9);
	float da = distance(i.uv, ca);
	float db = distance(i.uv, cb);
	
	float c1 = sin(da * _CosTime.y * 16 + _Time.x);
	float c2 = cos(i.uv.x * 8 + _Time.z);
	float c3 = cos(db * 14) + _CosTime.x;

	float p = (c1 + c2 + c3) / 3;
	
	return tex2D(_ColorBand, float2(p, 0.5));
}



ENDCG

	}
	
}

Fallback off

}

Any hints would be appreciated!

Thanks a lot
Bartek

What machines it does not run on?

Thanks Aras! I’ll trying to find this out, and I’ll let you know.

It seems however that same machines run a simple example with the pro blur filter (http://www.everyday3d.com/unity3d/effects/debug/) just fine, so the problem must be in the shader code.

Is it possible that some of the functions I use (distance(), sin() etc…) are not supported by some GPUs? Or the _Time and _CosTime does not work?

I noticed that when I used _MainTex_TexelSize property it did work in the editor but not in the webplayer (I’m on a MacBookPro/NVIDIA GeForce 9400M).

Hey there,

I was porting Iñigo Quilez’s GLSL shader toy examples to unity 3 (project attached) but unfortunately alot of the same code doesn’t seem to work too well in cg… You hit instruction arithmetic limits pretty quick - which i blame cg unrolling loops when it shouldn’t be :P) nevertheless theres a few more examples in there for you

Anyway hope the project helps
btw love your blog

378760–13112–$testshader_173.zip (559 KB)

@milkytreat Thanks for the sources!

So far it seems it doesn’t run on Mac, NVIDIA GeForce 9400M on OSX 10.6 (it does run on 10.5.8 though…)

actually i see a blue screen as well with your unity3d examples macbook pro 10.6 with ATI Radeon X1600, but i do see the cube blurred.

Now I’m completely puzzled. On this machine:

Mac OSX 10.6.4
NVIDIA Geforce GT 330M
Unity Plugin version: 2.6.1f3

it runs in Firefox but doesn’t run in Safari 5 (but it runs in Safari 5 on OSX 10.5.8 GeForce 9400M).

Reading values from SystemInfo returns the same exact values on both browsers, including supportsImageEffects = true

:-\

i ran this on my work machine, and it works on NVIDIA GeForce 8800 GTS … i noticed your 512 loop … I bet my iphone unity license its because of that loop unrolling.

Change it to something MUCH lower like <256 (for the radial blur i had to bring it down to 20 instead of 64)

I hit 512 arithmetic operations and ~1024 instruction limits on my macbook pro

I also tried on firefox on my macbook and doesn’t work

iphone licenses don’t impact it (unless you try to run it on the iphone in which case its forced to die as the shader is for high end desktop, not mobile) but if you don’t have pro, the postfx functionality will not work at all (OnRenderImage, …)

The loop is in the C# code, not in the shader and all it does is generate a texture2D 512px wide, 1px high - which is not a large texture by any means, you must admit.

I start to believe that there’s something wrong with the web player on mac (all the reports that is not working come from OSX 10.6 with either Safari 5 or Chrome, but it’s ok on Firefox). Furthermore, in all this cases, shader.isSupported returns true…

Anyway, I submitted a bug http://intra.unity3d.com/fogbugz/default.asp?372908_a1tpbd6g

UPDATE: The Pro Assets Twirl Image effect doesn’t work either… Example: http://www.everyday3d.com/unity3d/effects/debug/2.html

UPDATE 2: In both Safari and Chrome, when I get into the fullscreen mode it works. It only doesn’t work in windowed mode.

ah sorry silly me - hrmm … time for another wild speculation - could it be from the graphics update apple did for steam that rolled out around 19/aug?