Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/src/examples/gizmos/transform-rotate.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const cc = /** @type {CameraControls} */ (camera.script.create(CameraControls));
Object.assign(cc, {
focusPoint: pc.Vec3.ZERO,
sceneSize: 5,
rotateDamping: 0.97,
moveDamping: 0.97,
zoomDamping: 0.97,
rotateDamping: 0.95,
moveDamping: 0.95,
zoomDamping: 0.95,
pitchRange: new pc.Vec2(-89.999, 89.999),
zoomRange: new pc.Vec2(2, 10),
enableFly: false
Expand Down
6 changes: 3 additions & 3 deletions examples/src/examples/gizmos/transform-scale.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const cc = /** @type {CameraControls} */ (camera.script.create(CameraControls));
Object.assign(cc, {
focusPoint: pc.Vec3.ZERO,
sceneSize: 5,
rotateDamping: 0.97,
moveDamping: 0.97,
zoomDamping: 0.97,
rotateDamping: 0.95,
moveDamping: 0.95,
zoomDamping: 0.95,
pitchRange: new pc.Vec2(-89.999, 89.999),
zoomRange: new pc.Vec2(2, 10),
enableFly: false
Expand Down
6 changes: 3 additions & 3 deletions examples/src/examples/gizmos/transform-translate.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const cc = /** @type {CameraControls} */ (camera.script.create(CameraControls));
Object.assign(cc, {
focusPoint: pc.Vec3.ZERO,
sceneSize: 5,
rotateDamping: 0.97,
moveDamping: 0.97,
zoomDamping: 0.97,
rotateDamping: 0.95,
moveDamping: 0.95,
zoomDamping: 0.95,
pitchRange: new pc.Vec2(-89.999, 89.999),
zoomRange: new pc.Vec2(2, 10),
enableFly: false
Expand Down
3 changes: 2 additions & 1 deletion src/extras/gizmo/mesh-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class MeshLine {
this._thickness = args.thickness ?? this._thickness;

this._material.blendState = BlendState.ALPHABLEND;
this._material.setDefine('DEPTH_WRITE', '0');
this._material.setDefine('DEPTH_WRITE', '1');
this._material.setParameter('uDepth', 0);
this._material.update();

const mesh = Mesh.fromGeometry(app.graphicsDevice, new CylinderGeometry());
Expand Down
12 changes: 7 additions & 5 deletions src/extras/gizmo/scale-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,34 @@ class ScaleGizmo extends TransformGizmo {
layers: [this._layer.id],
defaultColor: this._theme.shapeBase.xyz,
hoverColor: this._theme.shapeHover.xyz,
disabledColor: this._theme.disabled,
depth: false
disabledColor: this._theme.disabled
}),
yz: new PlaneShape(this._device, {
axis: 'x',
layers: [this._layer.id],
rotation: new Vec3(0, 0, -90),
defaultColor: this._theme.shapeBase.x,
hoverColor: this._theme.shapeHover.x,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
xz: new PlaneShape(this._device, {
axis: 'y',
layers: [this._layer.id],
rotation: new Vec3(0, 0, 0),
defaultColor: this._theme.shapeBase.y,
hoverColor: this._theme.shapeHover.y,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
xy: new PlaneShape(this._device, {
axis: 'z',
layers: [this._layer.id],
rotation: new Vec3(90, 0, 0),
defaultColor: this._theme.shapeBase.z,
hoverColor: this._theme.shapeHover.z,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
x: new BoxLineShape(this._device, {
axis: 'x',
Expand Down
10 changes: 6 additions & 4 deletions src/extras/gizmo/shaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export const unlitShader = {
precision highp float;

uniform vec4 uColor;
uniform float uDepth;

void main(void) {
if (uColor.a < 1.0 / 255.0) {
discard;
}
gl_FragColor = vec4(gammaCorrectOutput(decodeGamma(uColor)), uColor.a);
#if DEPTH_WRITE == 0
gl_FragDepth = 0.0;
#if DEPTH_WRITE == 1
gl_FragDepth = uDepth;
#endif
}
`,
Expand All @@ -57,6 +58,7 @@ export const unlitShader = {
#include "gammaPS"

uniform uColor: vec4f;
uniform uDepth: f32;

@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
Expand All @@ -65,8 +67,8 @@ export const unlitShader = {
discard;
}
output.color = vec4f(gammaCorrectOutput(decodeGamma(uniform.uColor)), uniform.uColor.a);
#if DEPTH_WRITE == 0
output.fragDepth = 0.0;
#if DEPTH_WRITE == 1
output.fragDepth = uniform.uDepth;
#endif
return output;
}
Expand Down
11 changes: 6 additions & 5 deletions src/extras/gizmo/shape/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tmpG.normals = [];
* @property {Color} [hoverColor] - The hover color of the shape.
* @property {Color} [disabledColor] - The disabled color of the shape.
* @property {number} [cull] - The culling mode of the shape.
* @property {boolean} [depth] - Whether the shape is rendered with depth testing.
* @property {number} [depth] - The depth of the shape. -1 is depth is interpolated.
*/

/**
Expand Down Expand Up @@ -129,12 +129,12 @@ class Shape {
_cull = CULLFACE_BACK;

/**
* The internal depth state of the shape.
* The internal depth state of the shape. -1 is depth is interpolated.
*
* @type {boolean}
* @type {number}
* @protected
*/
_depth = true;
_depth = -1;

/**
* The graphics device.
Expand Down Expand Up @@ -269,7 +269,8 @@ class Shape {
*/
_createRenderComponent(entity, meshes) {
const color = this._disabled ? this._disabledColor : this._defaultColor;
this._material.setDefine('DEPTH_WRITE', this._depth ? '1' : '0');
this._material.setDefine('DEPTH_WRITE', this._depth > 0 ? '1' : '0');
this._material.setParameter('uDepth', this._depth);
this._material.setParameter('uColor', color.toArray());
this._material.cull = this._cull;
this._material.blendType = BLEND_NORMAL;
Expand Down
12 changes: 7 additions & 5 deletions src/extras/gizmo/translate-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,34 @@ class TranslateGizmo extends TransformGizmo {
layers: [this._layer.id],
defaultColor: this._theme.shapeBase.xyz,
hoverColor: this._theme.shapeHover.xyz,
disabledColor: this._theme.disabled,
depth: false
disabledColor: this._theme.disabled
}),
yz: new PlaneShape(this._device, {
axis: 'x',
layers: [this._layer.id],
rotation: new Vec3(0, 0, -90),
defaultColor: this._theme.shapeBase.x,
hoverColor: this._theme.shapeHover.x,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
xz: new PlaneShape(this._device, {
axis: 'y',
layers: [this._layer.id],
rotation: new Vec3(0, 0, 0),
defaultColor: this._theme.shapeBase.y,
hoverColor: this._theme.shapeHover.y,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
xy: new PlaneShape(this._device, {
axis: 'z',
layers: [this._layer.id],
rotation: new Vec3(90, 0, 0),
defaultColor: this._theme.shapeBase.z,
hoverColor: this._theme.shapeHover.z,
disabledColor: this._theme.disabled
disabledColor: this._theme.disabled,
depth: 1
}),
x: new ArrowShape(this._device, {
axis: 'x',
Expand Down