phong.pix

来自「G3D游戏引擎的库」· PIX 代码 · 共 60 行

PIX
60
字号
/**
 Per-pixel Phong Shading
 */

/** Diffuse/ambient surface color */
uniform vec3 diffuseColor;

/** Specular surface color.  Used for both glossy and perfect reflection. */
uniform vec3 specularColor;

/** Intensity of the diffuse term. */
uniform float diffuse;

/** Intensity of the specular term. */
uniform float specular;

/** Phong exponent; 100 = sharp highlight, 1 = broad highlight */
uniform float shine;

/** Intensity of perfect reflections */
uniform float reflect;

/** Unit world space direction to the (infinite, directional) light source */
uniform vec3 wsLight;

/** Color of the light source */
uniform vec3 lightColor;

/** Color of ambient light */
uniform vec3 ambientLightColor;

/** Environment cube map used for reflections */
uniform samplerCube environmentMap;

/** Modulates the environment map values to simulate darkness or increase
   dynamic range when tone mapping*/
uniform vec3 environmentMapColor;

varying vec3 wsInterpolatedNormal;
varying vec3 wsInterpolatedEye;

void main() {

    // Unit normal in world space
    vec3 wsNormal = normalize(wsInterpolatedNormal);

    // Unit vector from the pixel to the eye in world space
    vec3 wsEye = normalize(wsInterpolatedEye);

    // Unit vector giving the direction of perfect reflection into the eye
    vec3 wsReflect = 2.0 * dot(wsEye, wsNormal) * wsNormal - wsEye;
    // The "reflect" function is part of the GLSL specification but some NVIDIA drivers do not include it
    //vec3 wsReflect = -reflect(wsEye, wsNormal);

    gl_FragColor.rgb =
        diffuse  * diffuseColor  * (ambientLightColor + (max(dot(wsNormal, wsLight), 0.0) * lightColor)) +
        specular * specularColor * pow(max(dot(wsReflect, wsLight), 0.0), shine) * lightColor +
        reflect  * specularColor * textureCube(environmentMap, wsReflect).rgb;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?