Blinn-Phong Shader Model Implementation Issue

I made this very simple, perfectly working, implementation of the Phong Relflection Model (there is no environment yet, but this does not bother me now). Functions should be self-learning.

/**
 * Implements the classic Phong illumination Model using a reflected light
 * vector.
 */
public class PhongIllumination implements IlluminationModel {

    @RGBParam(r = 0, g = 0, b = 0)
    public Vec3 ambient;

    @RGBParam(r = 1, g = 1, b = 1)
    public Vec3 diffuse;

    @RGBParam(r = 1, g = 1, b = 1)
    public Vec3 specular;

    @FloatParam(value = 20, min = 1, max = 200.0f)
    public float shininess;

    /*
     * Calculate the intensity of light reflected to the viewer .
     * 
     * @param P = The surface position expressed in world coordinates.
     * 
     * @param V = Normalized viewing vector from surface to eye in world
     * coordinates.
     * 
     * @param N = Normalized normal vector at surface point in world
     * coordinates.
     * 
     * @param surfaceColor = surfaceColor Color of the surface at the current
     * position.
     * 
     * @param lights = The active light sources in the scene.
     * 
     * @return Reflected light intensity I.
     */
    public Vec3 shade(Vec3 P, Vec3 V, Vec3 N, Vec3 surfaceColor, Light lights[]) {
        Vec3 surfaceColordiffused = Vec3.mul(surfaceColor, diffuse);
        Vec3 totalintensity = new Vec3(0, 0, 0);
        for (int i = 0; i < lights.length; i++) {
            Vec3 L = lights[i].calcDirection(P);
            N = N.normalize();
            V = V.normalize();
            Vec3 R = Vec3.reflect(L, N); // reflection vector
            float diffuseLight = Vec3.dot(N, L);
            float specularLight = Vec3.dot(V, R);
            if (diffuseLight > 0) {
                totalintensity = Vec3.add(Vec3.mul(Vec3.mul(
                        surfaceColordiffused, lights[i].calcIntensity(P)),
                        diffuseLight), totalintensity);
                if (specularLight > 0) {

                    Vec3 Il = lights[i].calcIntensity(P);

                    Vec3 Ilincident = Vec3.mul(Il, Math.max(0.0f, Vec3
                            .dot(N, L)));

                    Vec3 intensity = Vec3.mul(Vec3.mul(specular, Ilincident),
                            (float) Math.pow(specularLight, shininess));

                    totalintensity = Vec3.add(totalintensity, intensity);
                }

            }
        }
        return totalintensity;
    }
}

Now I need to adapt it to become a Blinn-Phong lighting model

I used the formulas from hearn and baker, followed the pseudo-codes and tried to implement it several times according to wikipedia articles in several languages, but it never worked. I just don’t see mirror reflections or they are so weak and / or are in the wrong place and / or have the wrong color.

, . Half Way :

Vec3 H = Vec3.mul(Vec3.add(L.normalize(), V), Vec3.add(L.normalize(), V).length());
float specularLight = Vec3.dot(H, N);

( , ). .

. , , .

rightwrong

, : lower shininess

, blinn phong. . .

Edit:

, mutiplying |L+V| , H. :

Vec3 H = Vec3.mul(Vec3.add(L.normalize(), V), 1/Vec3.add(L.normalize(), V).length());

, . :

div

, :

div2

.

, . .

: http://en.wikipedia.org/wiki/File:Blinn-Phong_vectors.svg

H N , V R. V , , "". .

, - ( R). , anywehre ...

: ( ), - .

, - , . ?

: , N/H V/R. , 4, . , .

+3
2

!

.

+5

H , , L+V , : H = (L+V)*|L+V| (, Vec3.mul(v,x) v x). , H = (L+V)/|L+V|.

+3

Source: https://habr.com/ru/post/1784170/


All Articles