Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Phong Lighting in Lighting/GLSL Patches



I know this is mainly a GLSL issue, but it does relate to the way the Lighting environment and GLSL patches work specifically in Quartz Composer, so maybe someone will have tried to do this themselves and will be able to help. 

I'm trying to implement a really basic Phong Directional GLSL shader inside a Lighting environment patch, and have been having problems getting the specular contribution to work.

I've attached a QTZ example, which has a very simple setup:
A Lighting macro patch at the top-level
Inside this is a GLSL Shader patch containing the shader code
Inside the GLSL Shader is a Sphere primitive patch.

This is the Vertex Shader code:

varying vec3 normal, lightDir, halfVector;
varying vec4 diffuse, ambient;

void phongVS(in vec3 N)
{
// Normal to FS
normal = normalize(gl_NormalMatrix * N);
// Light direction vector to FS
lightDir = normalize(vec3(gl_LightSource[0].position));
// Halfvector to FS
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
// Diffuse and Ambient terms to FS
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;
}

void main()
{
vec4 Vertex = gl_ModelViewMatrix * gl_Vertex;
phongVS(gl_Normal);
gl_Position = ftransform();
}

and the Fragment Shader code:

varying vec3 normal, lightDir, halfVector;
varying vec4 diffuse, ambient;

vec4 phongDirectionalFS()
{
vec3 n, halfV;
float NdotL, NdotHV;
// Ambient term (always present)
vec4 final_color = ambient;
// Normal
n = normalize(normal);
NdotL = max(dot(n,lightDir),0.0);
if (NdotL > 0.0) {
final_color += diffuse * NdotL;
halfV = normalize(halfVector);
final_color += gl_FrontMaterial.specular
* gl_LightSource[0].specular
* pow(NdotHV, gl_FrontMaterial.shininess);
}
return final_color;
}

void main (void)
{
gl_FragColor = phongDirectionalFS();
}

Any tips much appreciated.

Cheers.

a|x
http://machinesdontcare.wordpress.com 




Sent from Yahoo! Mail.
A Smarter Email.

Attachment: PhongDirectional (QCDevList).qtz
Description: application/quartzcomposer

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden

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 © 2007 Apple Inc. All rights reserved.