0

I'm trying to make a Lambertian shader for my ray tracer, but am having trouble. The scence still seems to be flat shaded, just a little darker. Such as in this picture enter image description here

This is my Shader Class:

public class LambertianShader {

    public Colour diffuseColour;

    public LambertianShader(Colour diffuseColour){
        this.diffuseColour = diffuseColour;
    }

    public Colour shade(Intersection intersection, Light light){
        Vector3D lightDirection =  light.location.subtract(intersection.point);
        lightDirection.normalise();


        Colour finalColour = new Colour();
        float lambCoef = (float) intersection.normal.dot(lightDirection);

        if(lambCoef>0){
            finalColour.r = Math.max(0.0f, diffuseColour.r * lambCoef * light.intensity.r);
            finalColour.g = Math.max(0.0f, diffuseColour.g * lambCoef * light.intensity.g);
            finalColour.b = Math.max(0.0f, diffuseColour.b * lambCoef * light.intensity.b);


        }
        return finalColour;

    }

}

If you would like to see any more of my code let me know.

user2320239
  • 1,021
  • 2
  • 18
  • 43
  • Are you just taking the color returned from shade, setting that as the color then drawing the circles? Because if that is the case it makes sense that the circles are flatly shaded. If you want them to look correct you would need to shade every pixel. – CMilby Apr 10 '15 at 14:42
  • No the shading occurs individually for each pixel (and each sample of a pixel) the colour of each sphere is a property of the sphere. – user2320239 Apr 10 '15 at 14:52
  • From the looks of it your shader should work then. I'm thinking it must be somewhere else. How are you determining the normal of the Intersection? – CMilby Apr 10 '15 at 17:58
  • Obviously it depends on the object but for spheres I use. public Normal getNormalAt(Vector3D point) { Normal normal = new Normal(point); normal = normal.subtract(center); normal = normal.multiply(-1); normal.normalise(); return normal; } – user2320239 Apr 10 '15 at 18:18
  • Double check that all your color values are in the same range. I mean, for example the **diffuseColour** could be in a range of 0 - 255, but you expect the **finalColour** to be in a range of 0.0 - 1.0 – Pidhorskyi May 15 '15 at 19:50

0 Answers0