UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

92 lines (88 loc) 2.8 kB
var glslGsplatCopyToWorkBufferPS = ` #define GSPLAT_CENTER_NOPROJ #include "gsplatStructsVS" #include "gsplatCenterVS" #include "gsplatEvalSHVS" #include "gsplatQuatToMat3VS" #include "gsplatSourceFormatVS" #include "packHalfPS" uniform int uStartLine; uniform int uViewportWidth; #ifdef GSPLAT_LOD uniform usampler2D uIntervalsTexture; #endif uniform vec3 uColorMultiply; uniform int uActiveSplats; void main(void) { ivec2 localFragCoords = ivec2(int(gl_FragCoord.x), int(gl_FragCoord.y) - uStartLine); int targetIndex = localFragCoords.y * uViewportWidth + localFragCoords.x; if (targetIndex >= uActiveSplats) { #ifdef GSPLAT_COLOR_UINT pcFragColor0 = uvec4(0u); #else pcFragColor0 = vec4(0.0); #endif #ifndef GSPLAT_COLOR_ONLY pcFragColor1 = uvec4(0u); pcFragColor2 = uvec2(0u); #endif } else { #ifdef GSPLAT_LOD int intervalsSize = int(textureSize(uIntervalsTexture, 0).x); ivec2 intervalUV = ivec2(targetIndex % intervalsSize, targetIndex / intervalsSize); uint originalIndex = texelFetch(uIntervalsTexture, intervalUV, 0).r; #else uint originalIndex = uint(targetIndex); #endif #if defined(GSPLAT_SOGS_DATA) || defined(GSPLAT_COMPRESSED_DATA) uint srcSize = uint(textureSize(packedTexture, 0).x); #else uint srcSize = uint(textureSize(splatColor, 0).x); #endif SplatSource source; source.id = uint(originalIndex); source.uv = ivec2(source.id % srcSize, source.id / srcSize); vec3 modelCenter = readCenter(source); vec3 worldCenter = (matrix_model * vec4(modelCenter, 1.0)).xyz; SplatCenter center; initCenter(modelCenter, center); vec3 covA, covB; readCovariance(source, covA, covB); mat3 C = mat3( covA.x, covA.y, covA.z, covA.y, covB.x, covB.y, covA.z, covB.y, covB.z ); mat3 linear = mat3(matrix_model); mat3 Ct = linear * C * transpose(linear); covA = Ct[0]; covB = vec3(Ct[1][1], Ct[1][2], Ct[2][2]); vec4 color = readColor(source); #if SH_BANDS > 0 vec3 dir = normalize(center.view * mat3(center.modelView)); vec3 sh[SH_COEFFS]; float scale; readSHData(source, sh, scale); color.xyz += evalSH(sh, dir) * scale; #endif color.xyz *= uColorMultiply; #ifdef GSPLAT_COLOR_UINT uint packed_rg = packHalf2x16(color.rg); uint packed_ba = packHalf2x16(color.ba); pcFragColor0 = uvec4( packed_rg & 0xFFFFu, packed_rg >> 16u, packed_ba & 0xFFFFu, packed_ba >> 16u ); #else pcFragColor0 = color; #endif #ifndef GSPLAT_COLOR_ONLY pcFragColor1 = uvec4(floatBitsToUint(worldCenter.x), floatBitsToUint(worldCenter.y), floatBitsToUint(worldCenter.z), packHalf2x16Safe(vec2(covA.z, covB.z))); pcFragColor2 = uvec2(packHalf2x16Safe(covA.xy), packHalf2x16Safe(covB.xy)); #endif } } `; export { glslGsplatCopyToWorkBufferPS as default };