Skip to content

Commit cc8c6e0

Browse files
authored
Merge pull request #12681 from CesiumGS/voxel-cylinder-step
Fix step size for cylinder voxels
2 parents ed606ed + a9785d2 commit cc8c6e0

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

Apps/Sandcastle/gallery/Voxel Picking.html

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
function ProceduralMultiTileVoxelProvider(shape) {
7676
this.shape = shape;
7777
this.dimensions = new Cesium.Cartesian3(4, 4, 4);
78+
this.minBounds = Cesium.VoxelShapeType.getMinBounds(shape).clone();
79+
this.maxBounds = Cesium.VoxelShapeType.getMaxBounds(shape).clone();
7880
this.names = ["color"];
7981
this.types = [Cesium.MetadataType.VEC4];
8082
this.componentTypes = [Cesium.MetadataComponentType.FLOAT32];
@@ -134,11 +136,9 @@
134136
return dataColor;
135137
}
136138

137-
const provider = new ProceduralMultiTileVoxelProvider(Cesium.VoxelShapeType.BOX);
138-
139139
const customShader = new Cesium.CustomShader({
140140
fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
141-
{
141+
{
142142
vec3 voxelNormal = fsInput.attributes.normalEC;
143143
float diffuse = max(0.0, dot(voxelNormal, czm_lightDirectionEC));
144144
float lighting = 0.5 + 0.5 * diffuse;
@@ -147,13 +147,13 @@
147147
int sampleIndex = fsInput.voxel.sampleIndex;
148148
vec3 cellColor = fsInput.metadata.color.rgb * lighting;
149149
if (tileIndex == u_selectedTile && sampleIndex == u_selectedSample) {
150-
material.diffuse = mix(cellColor, vec3(1.0), 0.5);
151-
material.alpha = fsInput.metadata.color.a;
150+
material.diffuse = mix(cellColor, vec3(1.0), 0.5);
151+
material.alpha = fsInput.metadata.color.a;
152152
} else {
153-
material.diffuse = cellColor;
154-
material.alpha = fsInput.metadata.color.a;
153+
material.diffuse = cellColor;
154+
material.alpha = fsInput.metadata.color.a;
155155
}
156-
}`,
156+
}`,
157157
uniforms: {
158158
u_selectedTile: {
159159
type: Cesium.UniformType.INT,
@@ -166,18 +166,54 @@
166166
},
167167
});
168168

169-
const voxelPrimitive = scene.primitives.add(
170-
new Cesium.VoxelPrimitive({
169+
function createPrimitive(provider) {
170+
viewer.scene.primitives.removeAll();
171+
172+
const voxelPrimitive = new Cesium.VoxelPrimitive({
171173
provider: provider,
172174
customShader: customShader,
173-
}),
174-
);
175+
});
176+
voxelPrimitive.nearestSampling = true;
175177

176-
voxelPrimitive.nearestSampling = true;
178+
viewer.scene.primitives.add(voxelPrimitive);
179+
camera.flyToBoundingSphere(voxelPrimitive.boundingSphere, {
180+
duration: 0.0,
181+
});
177182

178-
camera.flyToBoundingSphere(voxelPrimitive.boundingSphere, {
179-
duration: 0.0,
180-
});
183+
return voxelPrimitive;
184+
}
185+
186+
Sandcastle.addToolbarMenu([
187+
{
188+
text: "Box - Procedural Tileset",
189+
onselect: function () {
190+
const provider = new ProceduralMultiTileVoxelProvider(
191+
Cesium.VoxelShapeType.BOX,
192+
);
193+
const primitive = createPrimitive(provider);
194+
},
195+
},
196+
{
197+
text: "Ellipsoid - Procedural Tileset",
198+
onselect: function () {
199+
const provider = new ProceduralMultiTileVoxelProvider(
200+
Cesium.VoxelShapeType.ELLIPSOID,
201+
);
202+
provider.minBounds.z = 0.0;
203+
provider.maxBounds.z = 1000000.0;
204+
const primitive = createPrimitive(provider);
205+
},
206+
},
207+
{
208+
text: "Cylinder - Procedural Tileset",
209+
onselect: function () {
210+
const provider = new ProceduralMultiTileVoxelProvider(
211+
Cesium.VoxelShapeType.CYLINDER,
212+
);
213+
const primitive = createPrimitive(provider);
214+
},
215+
},
216+
]);
181217

182218
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
183219
const pickedCoordinate = document.getElementById("pickedCoordinate");

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Fixes :wrench:
88

99
- Updates use of deprecated options on createImageBitmap. [#12664](https://github.com/CesiumGS/cesium/pull/12664)
10+
- Fixed raymarching step size for cylindrical voxels. [#12681](https://github.com/CesiumGS/cesium/pull/12681)
1011

1112
#### Additions :tada:
1213

packages/engine/Source/Shaders/Voxels/convertUvToCylinder.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PointJacobianT convertUvToShapeSpaceDerivative(in vec3 positionUv) {
3838
vec3 east = normalize(vec3(-position.y, position.x, 0.0));
3939

4040
vec3 point = vec3(radius, angle, height);
41-
mat3 jacobianT = mat3(radial, z, east / length(position.xy));
41+
mat3 jacobianT = mat3(radial, east / length(position.xy), z);
4242
return PointJacobianT(point, jacobianT);
4343
}
4444

0 commit comments

Comments
 (0)