Lambertian Shader无法正常工作

时间:2015-04-10 14:19:46

标签: java raytracing pixel-shading

我正在尝试为我的光线追踪器制作一个Lambertian着色器,但我遇到了麻烦。场景似乎仍然是平坦的阴影,只是有点暗。比如在这张照片中 enter image description here

这是我的着色器类:

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;

    }

}

如果您想查看我的代码,请告诉我。

0 个答案:

没有答案