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

📄 envmap.frag

📁 java 3d编程的一些例子源代码
💻 FRAG
字号:
//// Fragment shader for environment mapping with an// equirectangular 2D texture//// Authors: John Kessenich, Randi Rost//// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.//// See 3Dlabs-License.txt for license information//const vec3 Xunitvec = vec3 (1.0, 0.0, 0.0);const vec3 Yunitvec = vec3 (0.0, 1.0, 0.0);uniform vec3  BaseColor;uniform float MixRatio;uniform sampler2D EnvMap;varying vec3  Normal;varying vec3  EyeDir;varying float LightIntensity;void main (void){    // Compute reflection vector       vec3 reflectDir = reflect(EyeDir, Normal);    // Compute altitude and azimuth angles    vec2 index;    index.y = dot(normalize(reflectDir), Yunitvec);    reflectDir.y = 0.0;    index.x = dot(normalize(reflectDir), Xunitvec) * 0.5;    // Translate index values into proper range    if (reflectDir.z >= 0.0)        index = (index + 1.0) * 0.5;    else    {        index.t = (index.t + 1.0) * 0.5;        index.s = (-index.s) * 0.5 + 1.0;    }        // if reflectDir.z >= 0.0, s will go from 0.25 to 0.75    // if reflectDir.z <  0.0, s will go from 0.75 to 1.25, and    // that's OK, because we've set the texture to wrap.      // Do a lookup into the environment map.    vec3 envColor = vec3 (texture2D(EnvMap, index));    // Add lighting to base color and mix    vec3 base = LightIntensity * BaseColor;    envColor = mix(envColor, base, MixRatio);    gl_FragColor = vec4 (envColor, 1.0);}

⌨️ 快捷键说明

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