appleGuy
07-17-2007, 04:52 AM
Hi,
Ive tried to implement the phong shading model. However I cant seem to get it to work correctly. Its based of a lambert shader and the shader actually looks like a lambert shader, however there are no specular highlights or other defining features that make a phong shader.
Code That calculates Shader Colour at pixel level:
public colourRGBA calcPhongShader(ray Ray, float distance, Vector Lights){
Vector3f cameraSpherePath = new Vector3f(Ray.getDirection());
cameraSpherePath.scaleAdd(distance, Ray.getOrigin());
//Calculate Sphere Normal
float oneOverRadius = (1 / _radius);
Vector3f normal = new Vector3f();
normal.sub(cameraSpherePath, _centre);
normal.scale(oneOverRadius);
normal.normalize();
//Calculate The Bounce Point (Sphere) light Vector
Vector lightPathArray = new Vector();
Vector lightPathReflectionArray = new Vector();
lightObject light;
for(int lightIter = 0; lightIter < Lights.size(); lightIter++){
//ObjectToLight
Vector3f sphereLight = new Vector3f();
light = (lightObject)Lights.get(lightIter);
sphereLight.sub(light.lightPosition, cameraSpherePath);
sphereLight.normalize();
lightPathArray.add(sphereLight);
//Reflection Of Object To Light
Vector3f reflect = new Vector3f();
Vector3f reflectVar = new Vector3f();
reflectVar.scale(Ray.getDirection().dot(normal), normal);
reflectVar.scale(2.0f);
reflect.sub(Ray.getDirection(), reflectVar);
//R = V – 2 * (V·N) * N
reflect.normalize();
lightPathReflectionArray.add(reflect);
}
//View Direction Object To Camera
Vector3f objToCam = new Vector3f();
objToCam.sub(Ray.getOrigin(), cameraSpherePath);
objToCam.normalize();
colourRGBA colour = new colourRGBA();
colour.red = this.Ka[0]; // MULTIPLIES BY IAMBENT?
colour.green = this.Ka[1]; // MULTIPLIES BY IAMBENT?
colour.blue = this.Ka[2]; // MULTIPLIES BY IAMBENT?
for(int lightIter = 0; lightIter < Lights.size(); lightIter++){
Vector3f currentLightPath = (Vector3f)lightPathArray.get(lightIter);
Vector3f currentLightReflection = (Vector3f)lightPathReflectionArray.get(lightIter);
lightObject currentLight = (lightObject)Lights.get(lightIter);
float cameraDOTReflection = objToCam.dot(currentLightReflection);
float camDotRefPOW = (float)java.lang.Math.pow(cameraDOTReflection, this.shinyness);
colour.red += (((this.Kd[0] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[0]) + (this.Ks[0] * camDotRefPOW));
colour.green += (((this.Kd[1] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[1]) + (this.Ks[1] * camDotRefPOW));
colour.blue += (((this.Kd[2] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[2]) + (this.Ks[2] * camDotRefPOW));
}
return colour;
}
Thanks For Any Help
Cheers,
-Alex
Ive tried to implement the phong shading model. However I cant seem to get it to work correctly. Its based of a lambert shader and the shader actually looks like a lambert shader, however there are no specular highlights or other defining features that make a phong shader.
Code That calculates Shader Colour at pixel level:
public colourRGBA calcPhongShader(ray Ray, float distance, Vector Lights){
Vector3f cameraSpherePath = new Vector3f(Ray.getDirection());
cameraSpherePath.scaleAdd(distance, Ray.getOrigin());
//Calculate Sphere Normal
float oneOverRadius = (1 / _radius);
Vector3f normal = new Vector3f();
normal.sub(cameraSpherePath, _centre);
normal.scale(oneOverRadius);
normal.normalize();
//Calculate The Bounce Point (Sphere) light Vector
Vector lightPathArray = new Vector();
Vector lightPathReflectionArray = new Vector();
lightObject light;
for(int lightIter = 0; lightIter < Lights.size(); lightIter++){
//ObjectToLight
Vector3f sphereLight = new Vector3f();
light = (lightObject)Lights.get(lightIter);
sphereLight.sub(light.lightPosition, cameraSpherePath);
sphereLight.normalize();
lightPathArray.add(sphereLight);
//Reflection Of Object To Light
Vector3f reflect = new Vector3f();
Vector3f reflectVar = new Vector3f();
reflectVar.scale(Ray.getDirection().dot(normal), normal);
reflectVar.scale(2.0f);
reflect.sub(Ray.getDirection(), reflectVar);
//R = V – 2 * (V·N) * N
reflect.normalize();
lightPathReflectionArray.add(reflect);
}
//View Direction Object To Camera
Vector3f objToCam = new Vector3f();
objToCam.sub(Ray.getOrigin(), cameraSpherePath);
objToCam.normalize();
colourRGBA colour = new colourRGBA();
colour.red = this.Ka[0]; // MULTIPLIES BY IAMBENT?
colour.green = this.Ka[1]; // MULTIPLIES BY IAMBENT?
colour.blue = this.Ka[2]; // MULTIPLIES BY IAMBENT?
for(int lightIter = 0; lightIter < Lights.size(); lightIter++){
Vector3f currentLightPath = (Vector3f)lightPathArray.get(lightIter);
Vector3f currentLightReflection = (Vector3f)lightPathReflectionArray.get(lightIter);
lightObject currentLight = (lightObject)Lights.get(lightIter);
float cameraDOTReflection = objToCam.dot(currentLightReflection);
float camDotRefPOW = (float)java.lang.Math.pow(cameraDOTReflection, this.shinyness);
colour.red += (((this.Kd[0] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[0]) + (this.Ks[0] * camDotRefPOW));
colour.green += (((this.Kd[1] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[1]) + (this.Ks[1] * camDotRefPOW));
colour.blue += (((this.Kd[2] * currentLightPath.dot(normal)) * currentLight.lightDiffuse[2]) + (this.Ks[2] * camDotRefPOW));
}
return colour;
}
Thanks For Any Help
Cheers,
-Alex