playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
75 lines (74 loc) • 2.24 kB
JavaScript
var skybox_default = `
varying float vLinearDepth;
varying vec3 vViewDir;
uniform float skyboxHighlightMultiplier;
uniform float fisheye_k;
uniform float fisheye_invK;
uniform float fisheye_projMat00;
uniform float fisheye_projMat11;
uniform mat4 matrix_view;
uniform mat3 cubeMapRotationMatrix;
varying vec3 vClipXYW;
uniform samplerCube texture_cubeMap;
varying vec3 vWorldPos;
uniform mat3 cubeMapRotationMatrix;
uniform vec3 projectedSkydomeCenter;
uniform sampler2D texture_envAtlas;
uniform float mipLevel;
void main(void) {
gl_FragColor = float2vec4(vLinearDepth);
vec2 ndc = vClipXYW.xy / vClipXYW.z;
float px = ndc.x / fisheye_projMat00;
float py = ndc.y / fisheye_projMat11;
float r = sqrt(px * px + py * py);
float theta = fisheye_k * atan(r * fisheye_invK);
float sinT = sin(theta);
float cosT = cos(theta);
vec3 camDir = (r > 1e-6)
? vec3(px / r * sinT, py / r * sinT, -cosT)
: vec3(0.0, 0.0, -1.0);
vec3 dir = transpose(mat3(matrix_view)) * camDir;
dir = dir * cubeMapRotationMatrix;
vec3 envDir = normalize(vWorldPos - projectedSkydomeCenter);
vec3 dir = envDir * cubeMapRotationMatrix;
vec3 dir = vViewDir;
dir.x *= -1.0;
vec3 linear = {SKYBOX_DECODE_FNC}(textureCube(texture_cubeMap, dir));
dir *= vec3(-1.0, 1.0, 1.0);
vec2 uv = toSphericalUv(normalize(dir));
vec3 linear = {SKYBOX_DECODE_FNC}(texture2D(texture_envAtlas, mapRoughnessUv(uv, mipLevel)));
if (any(greaterThanEqual(linear, vec3(64.0)))) {
linear *= skyboxHighlightMultiplier;
}
gl_FragColor = vec4(gammaCorrectOutput(toneMap(processEnvironment(linear))), 1.0);
}
`;
export {
skybox_default as default
};