Lambertian Shader not working

柔情痞子 提交于 2019-12-12 03:31:53

问题


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

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.

来源:https://stackoverflow.com/questions/29563842/lambertian-shader-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!