Skip to content

Commit

Permalink
fixing gsplat code
Browse files Browse the repository at this point in the history
  • Loading branch information
arhik committed Jul 7, 2024
1 parent 1950107 commit 2ab13f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions examples/splat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function runApp(renderer)
end

mainApp = () -> begin
scene.camera.eye = [0, 0, -4]
# scene.camera.up = [0, -1, 0]
# scene.camera.eye = [1, -1, -2]
try
global renderer
if !GLFW.is_initialized()
Expand All @@ -57,7 +58,7 @@ mainApp = () -> begin
attachEventSystem(renderer, mouseState, keyboardState)
splatDataCopy = WGPUCore.readBuffer(scene.gpuDevice, pc.splatBuffer, 0, pc.splatBuffer.size)
gsplatInCopy = reinterpret(WGSLTypes.GSplatIn, splatDataCopy)
sortIdxs = sortperm(gsplatInCopy, by=x->-x.pos[3])
sortIdxs = sortperm(gsplatInCopy, by=x->x.pos[3])
gsplatInSorted = gsplatInCopy[sortIdxs]
storageData = reinterpret(UInt8, gsplatInSorted)
WGPUCore.writeBuffer(
Expand Down
8 changes: 4 additions & 4 deletions src/primitives/camera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function lookAtLeftHanded(camera::Camera)
eye = camera.eye
lookAt = camera.lookAt
up = camera.up
w = (lookAt .- eye) |> normalize
w = ((lookAt .- eye) |> normalize)
u = cross(up, w) |> normalize
v = cross(w, u)
m = MMatrix{4, 4, Float32}(I)
Expand All @@ -278,7 +278,7 @@ function perspectiveMatrix(camera::Camera)
ar = camera.aspectRatio
n = camera.nearPlane
f = camera.farPlane
t = abs(n)*tan(fov/2)
t = n*tan(fov/2)
b = -t
r = ar*t
l = -r
Expand All @@ -287,8 +287,8 @@ end


function perspectiveMatrix(near::Float32, far::Float32, l::Float32, r::Float32, t::Float32, b::Float32)
n = abs(near)
f = far |> abs
n = near
f = far
xS = 2*n/(r-l) # r-l is width
yS = 2*n/(t-b) # (t-b) is height
xR = (r+l)/(r-l)
Expand Down
11 changes: 6 additions & 5 deletions src/ui/gaussiansplat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ function getShaderCode(gsplat::GSplat, cameraId::Int; binding=0)
out.pos = camera.projMatrix*t
out.pos = out.pos/out.pos.w
# out.mu = out.pos
out.pos = Vec4{Float32}(out.pos.xy + 2.0*radiusNDC*quadpos.xy, out.pos.zw)
# out.pos = out.pos/out.pos.w
out.pos = Vec4{Float32}(out.pos.xy - 2.0*radiusNDC*quadpos.xy, out.pos.zw)
out.pos = out.pos/out.pos.w
out.pos = SVector{4, Float32}(out.pos.x, -out.pos.y, out.pos.z, out.pos.w)
# splatIn.pos = out.pos.xyz
out.mu = radiusBB*quadpos.xy
@let SH_C0 = 0.28209479177387814
Expand All @@ -263,7 +264,7 @@ function getShaderCode(gsplat::GSplat, cameraId::Int; binding=0)
splatIn.sh[2][0], splatIn.sh[2][1], splatIn.sh[2][2], splatIn.sh[2][3]
);
#@let eye = Vec3{Float32}(0.0, 0.0, 4.0)
@let dir = normalize(out.pos.xyz + (camera.eye.xyz - camera.lookAt.xyz))
@let dir = normalize(out.pos.xyz - (camera.lookAt.xyz - camera.eye.xyz))

@let x = dir.x;
@let y = dir.y;
Expand All @@ -279,7 +280,7 @@ function getShaderCode(gsplat::GSplat, cameraId::Int; binding=0)
end

@fragment function fs_main(splatOut::GSplatOut)::@location 0 Vec4{Float32}
@let mu = -splatOut.mu
@let mu = splatOut.mu
@var fragPos = splatOut.pos
@var fragColor = splatOut.color
@let opacity = splatOut.opacity
Expand Down Expand Up @@ -536,7 +537,7 @@ function getRenderPipelineOptions(renderer, splat::GSplat)
],
WGPUCore.GPUPrimitiveState => [
:topology => splat.topology,
:frontFace => "CW",
:frontFace => "CCW",
:cullMode => "None",
:stripIndexFormat => "Undefined"
],
Expand Down

0 comments on commit 2ab13f8

Please sign in to comment.