UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

3 lines (2 loc) 4.08 kB
declare const _default: "\n #define LIT_SKYBOX_INTENSITY\n\n #include \"envProcPS\"\n #include \"gammaPS\"\n #include \"tonemappingPS\"\n\n #ifdef PREPASS_PASS\n varying vLinearDepth: f32;\n #include \"floatAsUintPS\"\n #endif\n\n // Varying and uniform declarations\n varying vViewDir : vec3f;\n uniform skyboxHighlightMultiplier : f32;\n\n #if defined(SKY_FISHEYE) && !defined(SKYMESH)\n uniform fisheye_k : f32;\n uniform fisheye_invK : f32;\n uniform fisheye_projMat00 : f32;\n uniform fisheye_projMat11 : f32;\n uniform matrix_view : mat4x4f;\n uniform cubeMapRotationMatrix : mat3x3f;\n varying vClipXYW : vec3f;\n #endif\n\n #ifdef SKY_CUBEMAP\n\n var texture_cubeMap : texture_cube<f32>;\n var texture_cubeMap_sampler : sampler;\n\n #ifdef SKYMESH\n varying vWorldPos : vec3f;\n uniform cubeMapRotationMatrix : mat3x3f;\n uniform projectedSkydomeCenter : vec3f;\n #endif\n\n #else // env-atlas\n\n #include \"sphericalPS\"\n #include \"envAtlasPS\"\n\n var texture_envAtlas : texture_2d<f32>;\n var texture_envAtlas_sampler : sampler;\n\n uniform mipLevel : f32;\n\n #endif\n\n @fragment\n fn fragmentMain(input : FragmentInput) -> FragmentOutput {\n\n var output: FragmentOutput;\n\n #ifdef PREPASS_PASS\n\n // output linear depth during prepass\n output.color = float2vec4(vLinearDepth);\n\n #else\n\n var linear : vec3f;\n var dir : vec3f;\n\n // --- compute view direction ---\n\n #if defined(SKY_FISHEYE) && !defined(SKYMESH)\n\n let ndc : vec2f = input.vClipXYW.xy / input.vClipXYW.z;\n let px : f32 = ndc.x / uniform.fisheye_projMat00;\n let py : f32 = ndc.y / uniform.fisheye_projMat11;\n let r : f32 = sqrt(px * px + py * py);\n let theta : f32 = uniform.fisheye_k * atan(r * uniform.fisheye_invK);\n let sinT : f32 = sin(theta);\n let cosT : f32 = cos(theta);\n var camDir : vec3f;\n if (r > 1e-6) {\n camDir = vec3f(px / r * sinT, py / r * sinT, -cosT);\n } else {\n camDir = vec3f(0.0, 0.0, -1.0);\n }\n let viewMat3 : mat3x3f = mat3x3f(\n uniform.matrix_view[0].xyz,\n uniform.matrix_view[1].xyz,\n uniform.matrix_view[2].xyz\n );\n dir = transpose(viewMat3) * camDir;\n dir = dir * uniform.cubeMapRotationMatrix;\n\n #elif defined(SKY_CUBEMAP) && defined(SKYMESH)\n\n // get vector from world space pos to tripod origin\n var envDir : vec3f = normalize(input.vWorldPos - uniform.projectedSkydomeCenter);\n dir = envDir * uniform.cubeMapRotationMatrix;\n\n #else\n\n dir = input.vViewDir;\n\n #endif\n\n // --- sample environment ---\n\n #ifdef SKY_CUBEMAP\n\n dir.x *= -1.0;\n linear = {SKYBOX_DECODE_FNC}(textureSample(texture_cubeMap, texture_cubeMap_sampler, dir));\n\n #else // env-atlas\n\n dir *= vec3f(-1.0, 1.0, 1.0);\n let uv : vec2f = toSphericalUv(normalize(dir));\n linear = {SKYBOX_DECODE_FNC}(textureSample(texture_envAtlas, texture_envAtlas_sampler, mapRoughnessUv(uv, uniform.mipLevel)));\n\n #endif\n\n // our HDR encodes values up to 64, so allow extra brightness for the clipped values\n if (any(linear >= vec3f(64.0))) {\n linear *= uniform.skyboxHighlightMultiplier;\n }\n \n output.color = vec4f(gammaCorrectOutput(toneMap(processEnvironment(linear))), 1.0);\n\n #endif\n\n return output;\n }\n"; export default _default;