⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phong.pix

📁 G3D游戏引擎的库
💻 PIX
字号:
/**
 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -