Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 1x 17x 17x 3x 14x 14x 14x 17x 17x 1x 1x 1x 17x 15x 17x 3x 14x 14x 14x 17x 17x 17x 17x 311x 311x 311x 185x 185x 17x 17x 1x 1x 1x 1x 17x 15x 15x 17x 17x 17x 17x 1x 17x 17x | import Cartesian3 from "../Core/Cartesian3.js";
import combine from "../Core/combine.js";
import defined from "../Core/defined.js";
import ShaderBuilder from "../Renderer/ShaderBuilder.js";
import ShaderDestination from "../Renderer/ShaderDestination.js";
import VoxelUtils from "../Shaders/Voxels/VoxelUtils.js";
import VoxelFS from "../Shaders/Voxels/VoxelFS.js";
import VoxelVS from "../Shaders/Voxels/VoxelVS.js";
import IntersectionUtils from "../Shaders/Voxels/IntersectionUtils.js";
import IntersectDepth from "../Shaders/Voxels/IntersectDepth.js";
import IntersectPlane from "../Shaders/Voxels/IntersectPlane.js";
import IntersectLongitude from "../Shaders/Voxels/IntersectLongitude.js";
import IntersectBox from "../Shaders/Voxels/IntersectBox.js";
import IntersectCylinder from "../Shaders/Voxels/IntersectCylinder.js";
import IntersectEllipsoid from "../Shaders/Voxels/IntersectEllipsoid.js";
import Intersection from "../Shaders/Voxels/Intersection.js";
import convertLocalToBoxUv from "../Shaders/Voxels/convertLocalToBoxUv.js";
import convertLocalToCylinderUv from "../Shaders/Voxels/convertLocalToCylinderUv.js";
import convertLocalToEllipsoidUv from "../Shaders/Voxels/convertLocalToEllipsoidUv.js";
import Octree from "../Shaders/Voxels/Octree.js";
import Megatexture from "../Shaders/Voxels/Megatexture.js";
import VoxelMetadataOrder from "./VoxelMetadataOrder.js";
/**
* Set up render resources, including basic shader code, for rendering
* a Voxel primitive.
* The shader code generated by this function may be modified in later stages.
* @constructor
* @param {VoxelPrimitive} primitive
*
* @private
*/
function VoxelRenderResources(primitive) {
const shaderBuilder = new ShaderBuilder();
/**
* An object used to build a shader incrementally. Each pipeline stage
* may add lines of shader code to this object.
*
* @type {ShaderBuilder}
* @readonly
*
* @private
*/
this.shaderBuilder = shaderBuilder;
// Custom shader uniforms
const customShader = primitive._customShader;
const uniformMap = combine(primitive._uniformMap, customShader.uniformMap);
primitive._uniformMap = uniformMap;
const customShaderUniforms = customShader.uniforms;
for (const uniformName in customShaderUniforms) {
if (customShaderUniforms.hasOwnProperty(uniformName)) {
const uniform = customShaderUniforms[uniformName];
shaderBuilder.addUniform(
uniform.type,
uniformName,
ShaderDestination.FRAGMENT,
);
}
}
// The reason this uniform is added by shader builder is because some of the
// dynamically generated shader code reads from it.
shaderBuilder.addUniform(
"sampler2D",
"u_megatextureTextures[METADATA_COUNT]",
ShaderDestination.FRAGMENT,
);
/**
* A dictionary mapping uniform name to functions that return the uniform
* values.
* @private
* @type {Object<string, Function>}
*/
this.uniformMap = uniformMap;
const clippingPlanes = primitive._clippingPlanes;
const clippingPlanesLength =
defined(clippingPlanes) && clippingPlanes.enabled
? clippingPlanes.length
: 0;
this.clippingPlanes = clippingPlanes;
this.clippingPlanesLength = clippingPlanesLength;
const renderBoundPlanes = primitive._shape.renderBoundPlanes;
const renderBoundPlanesLength = renderBoundPlanes?.length ?? 0;
this.renderBoundPlanes = renderBoundPlanes;
this.renderBoundPlanesLength = renderBoundPlanesLength;
// Build shader
shaderBuilder.addVertexLines([VoxelVS]);
if (primitive.provider.metadataOrder === VoxelMetadataOrder.Y_UP) {
shaderBuilder.addDefine(
"Y_UP_METADATA_ORDER",
undefined,
ShaderDestination.FRAGMENT,
);
}
const shapeType = primitive._provider.shape;
if (shapeType === "BOX") {
shaderBuilder.addDefine("SHAPE_BOX", undefined, ShaderDestination.FRAGMENT);
} else Iif (shapeType === "CYLINDER") {
shaderBuilder.addDefine(
"SHAPE_CYLINDER",
undefined,
ShaderDestination.FRAGMENT,
);
} else Eif (shapeType === "ELLIPSOID") {
shaderBuilder.addDefine(
"SHAPE_ELLIPSOID",
undefined,
ShaderDestination.FRAGMENT,
);
}
shaderBuilder.addFragmentLines([
customShader.fragmentShaderText,
"#line 0",
Octree,
VoxelUtils,
Megatexture,
IntersectionUtils,
IntersectPlane,
IntersectDepth,
]);
if (clippingPlanesLength > 0) {
shaderBuilder.addDefine(
"CLIPPING_PLANES",
undefined,
ShaderDestination.FRAGMENT,
);
shaderBuilder.addDefine(
"CLIPPING_PLANES_COUNT",
clippingPlanesLength,
ShaderDestination.FRAGMENT,
);
Iif (clippingPlanes.unionClippingRegions) {
shaderBuilder.addDefine(
"CLIPPING_PLANES_UNION",
undefined,
ShaderDestination.FRAGMENT,
);
}
}
if (primitive._depthTest) {
shaderBuilder.addDefine(
"DEPTH_TEST",
undefined,
ShaderDestination.FRAGMENT,
);
}
if (shapeType === "BOX") {
shaderBuilder.addFragmentLines([
convertLocalToBoxUv,
IntersectBox,
Intersection,
]);
} else Iif (shapeType === "CYLINDER") {
shaderBuilder.addFragmentLines([
convertLocalToCylinderUv,
IntersectLongitude,
IntersectCylinder,
Intersection,
]);
} else Eif (shapeType === "ELLIPSOID") {
shaderBuilder.addFragmentLines([
convertLocalToEllipsoidUv,
IntersectLongitude,
IntersectEllipsoid,
Intersection,
]);
}
shaderBuilder.addFragmentLines([VoxelFS]);
const shape = primitive._shape;
const shapeDefines = shape.shaderDefines;
for (const key in shapeDefines) {
Eif (shapeDefines.hasOwnProperty(key)) {
let value = shapeDefines[key];
// if value is undefined, don't define it
// if value is true, define it to nothing
if (defined(value)) {
value = value === true ? undefined : value;
shaderBuilder.addDefine(key, value, ShaderDestination.FRAGMENT);
}
}
}
// Count how many intersections the shader will do.
let intersectionCount = shape.shaderMaximumIntersectionsLength;
if (clippingPlanesLength > 0) {
shaderBuilder.addDefine(
"CLIPPING_PLANES_INTERSECTION_INDEX",
intersectionCount,
ShaderDestination.FRAGMENT,
);
Iif (clippingPlanesLength === 1) {
intersectionCount += 1;
} else Iif (clippingPlanes.unionClippingRegions) {
intersectionCount += 2;
} else {
intersectionCount += 1;
}
}
if (primitive._depthTest) {
shaderBuilder.addDefine(
"DEPTH_INTERSECTION_INDEX",
intersectionCount,
ShaderDestination.FRAGMENT,
);
intersectionCount += 1;
}
shaderBuilder.addDefine(
"INTERSECTION_COUNT",
intersectionCount,
ShaderDestination.FRAGMENT,
);
// Additional fragment shader defines
Iif (
!Cartesian3.equals(primitive.paddingBefore, Cartesian3.ZERO) ||
!Cartesian3.equals(primitive.paddingAfter, Cartesian3.ZERO)
) {
shaderBuilder.addDefine("PADDING", undefined, ShaderDestination.FRAGMENT);
}
// Allow reading from log depth texture, but don't write log depth anywhere.
// Note: This needs to be set even if depthTest is off because it affects the
// derived command system.
Iif (primitive._useLogDepth) {
shaderBuilder.addDefine(
"LOG_DEPTH_READ_ONLY",
undefined,
ShaderDestination.FRAGMENT,
);
}
if (primitive._nearestSampling) {
shaderBuilder.addDefine(
"NEAREST_SAMPLING",
undefined,
ShaderDestination.FRAGMENT,
);
}
const traversal = primitive._traversal;
shaderBuilder.addDefine(
"SAMPLE_COUNT",
`${traversal._sampleCount}`,
ShaderDestination.FRAGMENT,
);
}
export default VoxelRenderResources;
|