From 831ba43e40057cb63fdac10b1cbac8690043f312 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 19 Nov 2024 19:58:18 -0800 Subject: [PATCH] DebugDraw: Line thickness --- src/SuperMarioGalaxy/RailRider.ts | 10 ++++++++++ src/ZeldaWindWaker/d_a.ts | 4 ++-- src/gfx/helpers/DebugDraw.ts | 30 +++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/SuperMarioGalaxy/RailRider.ts b/src/SuperMarioGalaxy/RailRider.ts index 4100472f8..bf28e3cc4 100644 --- a/src/SuperMarioGalaxy/RailRider.ts +++ b/src/SuperMarioGalaxy/RailRider.ts @@ -591,6 +591,9 @@ export class RailRider { const totalLength = this.getTotalLength(); const speed = totalLength / nPoints; + if (this.bezierRail.isClosed) + nPoints++; + this.bezierRail.calcPos(scratchVec3b, 0); debugDraw.beginBatchLine(nPoints); for (let i = 0; i < nPoints; i++) { @@ -598,6 +601,13 @@ export class RailRider { debugDraw.drawLine(scratchVec3b, scratchVec3c, Magenta); vec3.copy(scratchVec3b, scratchVec3c); } + + if (this.bezierRail.isClosed) { + this.bezierRail.calcPos(scratchVec3b, totalLength); + this.bezierRail.calcPos(scratchVec3c, 0); + debugDraw.drawLine(scratchVec3b, scratchVec3c, Magenta); + } + debugDraw.endBatch(); } } diff --git a/src/ZeldaWindWaker/d_a.ts b/src/ZeldaWindWaker/d_a.ts index fea25cc2e..2493bb69d 100644 --- a/src/ZeldaWindWaker/d_a.ts +++ b/src/ZeldaWindWaker/d_a.ts @@ -3841,8 +3841,8 @@ class d_a_oship extends fopAc_ac_c implements ModeFuncExec { const angleY = cLib_targetAngleY(this.pos, this.targetPos); // TODO(jstpierre): Figure out the bad aim system. - // this.targetPos[0] -= badAimRadius * Math.sin(cM__Short2Rad(angleY)); - // this.targetPos[2] -= badAimRadius * Math.cos(cM__Short2Rad(angleY)); + // this.targetPos[0] -= badAimRadius * Math.sin(cM_s2rad(angleY)); + // this.targetPos[2] -= badAimRadius * Math.cos(cM_s2rad(angleY)); } private attackCannon(globals: dGlobals): boolean { diff --git a/src/gfx/helpers/DebugDraw.ts b/src/gfx/helpers/DebugDraw.ts index 2b9c9fdcf..ab2eb5d65 100644 --- a/src/gfx/helpers/DebugDraw.ts +++ b/src/gfx/helpers/DebugDraw.ts @@ -20,21 +20,19 @@ import { assert } from "../platform/GfxPlatformUtil.js"; // - Integrate text renderer? // - More primitive types // - Support view-space and screen-space primitives -// - Line width emulation? interface DebugDrawOptions { flags?: DebugDrawFlags; }; export const enum DebugDrawFlags { - Default = 0, - WorldSpace = 0, ViewSpace = 1 << 0, ScreenSpace = 1 << 1, - BillboardSpace = 1 << 2, DepthTint = 1 << 3, + + Default = DepthTint, }; const bindingLayouts: GfxBindingLayoutDescriptor[] = [ @@ -63,6 +61,16 @@ flat out uint v_Flags; void main() { uint t_Flags = uint(a_Color.a); gl_Position = Mul(u_ClipFromView, Mul(_Mat4x4(u_ViewFromWorld), vec4(a_Position.xyz, 1.0))); + + if (gl_InstanceID >= 1) { + uint t_LineIndex = uint(gl_InstanceID - 1); + vec2 t_PosOffs; + t_PosOffs.x = (t_LineIndex & 1u) != 0u ? 1.0f : -1.0f; + t_PosOffs.y = (t_LineIndex & 2u) != 0u ? 1.0f : -1.0f; + t_PosOffs.xy *= float((t_LineIndex / 4u) + 1u); + gl_Position.xy += (t_PosOffs / u_ScreenSize) * gl_Position.w; + } + v_Color = a_Color; v_Color.a = 1.0 - fract(a_Color.a); v_Color.rgb *= v_Color.aaa; @@ -85,10 +93,11 @@ bool IsSomethingInFront(float t_DepthSample) { void main() { vec4 t_Color = v_Color; + if ((v_Flags & uint(${DebugDrawFlags.DepthTint})) != 0u) { float t_DepthSample = texelFetch(SAMPLER_2D(u_TextureFramebufferDepth), ivec2(gl_FragCoord.xy), 0).r; if (IsSomethingInFront(t_DepthSample)) - t_Color.rgba *= 0.2; + t_Color.rgba *= 0.15; } gl_FragColor = t_Color; @@ -123,7 +132,7 @@ class BufferPage { public renderInst = new GfxRenderInst(); - constructor(cache: GfxRenderCache, public behaviorType: BehaviorType, vertexCount: number, indexCount: number) { + constructor(cache: GfxRenderCache, public behaviorType: BehaviorType, vertexCount: number, indexCount: number, private lineThickness: number) { const device = cache.device; this.vertexData = new Float32Array(vertexCount * this.vertexStride); @@ -188,10 +197,12 @@ class BufferPage { ], { buffer: this.indexBuffer, byteOffset: 0 }); setAttachmentStateSimple(this.renderInst.getMegaStateFlags(), { blendMode: GfxBlendMode.Add, blendSrcFactor: GfxBlendFactor.One, blendDstFactor: GfxBlendFactor.OneMinusSrcAlpha }); - if (this.behaviorType === BehaviorType.Lines) + if (this.behaviorType === BehaviorType.Lines) { this.renderInst.setMegaStateFlags({ depthCompare: GfxCompareMode.Always, depthWrite: false }); - else if (this.behaviorType === BehaviorType.Transparent) + this.renderInst.setInstanceCount(1 + (this.lineThickness - 1) * 4); + } else if (this.behaviorType === BehaviorType.Transparent) { this.renderInst.setMegaStateFlags({ depthWrite: false }); + } this.renderInst.setDrawCount(this.indexDataOffs); @@ -216,6 +227,7 @@ export class DebugDraw { private debugDrawProgram: GfxProgram; private depthSampler: GfxSampler; private currentPage: BufferPage | null = null; // for the batch system + private lineThickness = 3; public static scratchVec3 = nArray(4, () => vec3.create()); @@ -273,7 +285,7 @@ export class DebugDraw { vertexCount = align(vertexCount, this.defaultPageVertexCount); indexCount = align(indexCount, this.defaultPageIndexCount); - const page = new BufferPage(this.cache, behaviorType, vertexCount, indexCount); + const page = new BufferPage(this.cache, behaviorType, vertexCount, indexCount, this.lineThickness); this.pages.push(page); return page; }