Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
GLSL and Returns
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GLSL and Returns



I've been learning and writing a number of GLSL shaders. I'm no expert (yet :) ) -- so maybe this is a big gotcha that I don't know.

I learned by taking the lighthouse toon shader, making it a texture- toon shader and adding a couple of dim3 specific things. The shader works perfectly:

-------------------------------------------------------------
uniform sampler2D dim3Tex;
uniform bool dim3HasClosestLight;
uniform vec3 dim3ClosestLightNormal;
varying vec3 normal;
varying vec4 uv;

void main()
{
	float		intensity;
	vec4	pix;

	if (!dim3HasClosestLight) {
		gl_FragColor=vec4(0.0);
	}
	else {
		pix = texture2D(dim3Tex,uv.st);
		intensity = dot(dim3ClosestLightNormal,normal);

		if (intensity > 0.95)
			gl_FragColor = pix;
		else if (intensity > 0.5)
			gl_FragColor = pix * 0.6;
		else if (intensity > 0.25)
			gl_FragColor = pix * 0.4;
		else
			gl_FragColor = pix * 0.2;
	}
}
-------------------------------------------------------------

That's not normally how I write code though, so I originally did this which does NOT work. It doesn't put up any errors, but instead seems to completely ignore the shader. It took me a while, but it's the return that causes the problem.

-------------------------------------------------------------
uniform sampler2D dim3Tex;
uniform bool dim3HasClosestLight;
uniform vec3 dim3ClosestLightNormal;
varying vec3 normal;
varying vec4 uv;

void main()
{
	float		intensity;
	vec4	pix;

	if (!dim3HasClosestLight) {
		gl_FragColor=vec4(0.0);
		return;
	}

	pix = texture2D(dim3Tex,uv.st);
	intensity = dot(dim3ClosestLightNormal,normal);

	if (intensity > 0.95)
		gl_FragColor = pix;
	else if (intensity > 0.5)
		gl_FragColor = pix * 0.6;
	else if (intensity > 0.25)
		gl_FragColor = pix * 0.4;
	else
		gl_FragColor = pix * 0.2;
}
-------------------------------------------------------------

Is this just illegal? Note that I get no compile or link errors, just a ignored shader.

[>] Brian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.