UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

3 lines (2 loc) 2.39 kB
declare const _default: "\n#ifdef PIXELSNAP\n uniform uScreenSize: vec4f;\n#endif\n\n#ifdef SCREENSPACE\n uniform projectionFlipY: f32;\n#endif\n\nfn evalWorldPosition(vertexPosition: vec3f, modelMatrix: mat4x4f) -> vec4f {\n\n var localPos: vec3f = getLocalPosition(vertexPosition);\n\n #ifdef NINESLICED\n // outer and inner vertices are at the same position, scale both\n var localPosXZ: vec2f = localPos.xz;\n localPosXZ = localPosXZ * uniform.outerScale;\n\n // offset inner vertices inside\n // (original vertices must be in [-1;1] range)\n let positiveUnitOffset: vec2f = clamp(vertexPosition.xz, vec2f(0.0), vec2f(1.0));\n let negativeUnitOffset: vec2f = clamp(-vertexPosition.xz, vec2f(0.0), vec2f(1.0));\n localPosXZ = localPosXZ + (-positiveUnitOffset * uniform.innerOffset.xy + negativeUnitOffset * uniform.innerOffset.zw) * vertex_texCoord0.xy;\n\n dTiledUvGlobal = (localPosXZ - uniform.outerScale + uniform.innerOffset.xy) * -0.5 + 1.0; // uv = local pos - inner corner\n\n localPosXZ = localPosXZ * -0.5;\n localPos = vec3f(localPosXZ.x, localPosXZ.y, localPos.y);\n #endif\n\n var posW: vec4f = modelMatrix * vec4f(localPos, 1.0);\n\n #ifdef SCREENSPACE\n posW = vec4f(posW.xy, 0.0, 1.0);\n #endif\n\n return posW;\n}\n\nfn getPosition() -> vec4f {\n\n dModelMatrix = getModelMatrix();\n\n let posW: vec4f = evalWorldPosition(vertex_position.xyz, dModelMatrix);\n dPositionW = posW.xyz;\n\n var screenPos: vec4f;\n #ifdef UV1LAYOUT\n screenPos = vec4f(vertex_texCoord1.xy * 2.0 - 1.0, 0.5, 1.0);\n screenPos.y *= -1.0;\n #else\n #ifdef SCREENSPACE\n screenPos = posW;\n screenPos.y *= uniform.projectionFlipY;\n #else\n screenPos = uniform.matrix_viewProjection * posW;\n #endif\n\n #ifdef PIXELSNAP\n // snap vertex to a pixel boundary\n screenPos.xy = (screenPos.xy * 0.5) + 0.5;\n screenPos.xy *= uniforms.uScreenSize.xy;\n screenPos.xy = floor(screenPos.xy);\n screenPos.xy *= uniforms.uScreenSize.zw;\n screenPos.xy = (screenPos.xy * 2.0) - 1.0;\n #endif\n #endif\n\n return screenPos;\n}\n\nfn getWorldPosition() -> vec3f {\n return dPositionW;\n}\n"; export default _default;