-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GS WebGPU * debugging wgsl * nme fixes * missing imports * wgsl imports * clean up shaders, coroutine batch size * more missing imports * webgpu + nme * removed empty line
- Loading branch information
1 parent
ae594bf
commit 1598912
Showing
15 changed files
with
236 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/dev/core/src/Materials/Node/Blocks/GaussianSplatting/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export * from "./gaussianSplattingBlock"; | ||
export * from "./splatReaderBlock"; | ||
export * from "./gaussianBlock"; | ||
|
||
// Gaussian | ||
export * from "../../../../ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration"; | ||
export * from "../../../../Shaders/ShadersInclude/gaussianSplattingVertexDeclaration"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/dev/core/src/ShadersWGSL/ShadersInclude/gaussianSplatting.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
fn getDataUV(index: f32, dataTextureSize: vec2f) -> vec2<f32> { | ||
let y: f32 = floor(index / dataTextureSize.x); | ||
let x: f32 = index - y * dataTextureSize.x; | ||
return vec2f((x + 0.5), (y + 0.5)); | ||
} | ||
|
||
struct Splat { | ||
center: vec4f, | ||
color: vec4f, | ||
covA: vec4f, | ||
covB: vec4f, | ||
}; | ||
|
||
fn readSplat(splatIndex: f32, dataTextureSize: vec2f) -> Splat { | ||
var splat: Splat; | ||
let splatUV = getDataUV(splatIndex, dataTextureSize); | ||
let splatUVi32 = vec2<i32>(i32(splatUV.x), i32(splatUV.y)); | ||
splat.center = textureLoad(centersTexture, splatUVi32, 0); | ||
splat.color = textureLoad(colorsTexture, splatUVi32, 0); | ||
splat.covA = textureLoad(covariancesATexture, splatUVi32, 0) * splat.center.w; | ||
splat.covB = textureLoad(covariancesBTexture, splatUVi32, 0) * splat.center.w; | ||
|
||
return splat; | ||
} | ||
|
||
fn gaussianSplatting( | ||
meshPos: vec2<f32>, | ||
worldPos: vec3<f32>, | ||
scale: vec2<f32>, | ||
covA: vec3<f32>, | ||
covB: vec3<f32>, | ||
worldMatrix: mat4x4<f32>, | ||
viewMatrix: mat4x4<f32>, | ||
projectionMatrix: mat4x4<f32>, | ||
focal: vec2f, | ||
invViewport: vec2f | ||
) -> vec4f { | ||
let modelView = viewMatrix * worldMatrix; | ||
let camspace = viewMatrix * vec4f(worldPos, 1.0); | ||
let pos2d = projectionMatrix * camspace; | ||
|
||
let bounds = 1.2 * pos2d.w; | ||
if (pos2d.z < 0. || pos2d.x < -bounds || pos2d.x > bounds || pos2d.y < -bounds || pos2d.y > bounds) { | ||
return vec4f(0.0, 0.0, 2.0, 1.0); | ||
} | ||
|
||
let Vrk = mat3x3<f32>( | ||
covA.x, covA.y, covA.z, | ||
covA.y, covB.x, covB.y, | ||
covA.z, covB.y, covB.z | ||
); | ||
|
||
let J = mat3x3<f32>( | ||
focal.x / camspace.z, 0.0, -(focal.x * camspace.x) / (camspace.z * camspace.z), | ||
0.0, focal.y / camspace.z, -(focal.y * camspace.y) / (camspace.z * camspace.z), | ||
0.0, 0.0, 0.0 | ||
); | ||
|
||
let invy = mat3x3<f32>( | ||
1.0, 0.0, 0.0, | ||
0.0, -1.0, 0.0, | ||
0.0, 0.0, 1.0 | ||
); | ||
|
||
let T = invy * transpose(mat3x3<f32>( | ||
modelView[0].xyz, | ||
modelView[1].xyz, | ||
modelView[2].xyz)) * J; | ||
let cov2d = transpose(T) * Vrk * T; | ||
|
||
let mid = (cov2d[0][0] + cov2d[1][1]) / 2.0; | ||
let radius = length(vec2<f32>((cov2d[0][0] - cov2d[1][1]) / 2.0, cov2d[0][1])); | ||
let lambda1 = mid + radius; | ||
let lambda2 = mid - radius; | ||
|
||
if (lambda2 < 0.0) { | ||
return vec4f(0.0, 0.0, 2.0, 1.0); | ||
} | ||
|
||
let diagonalVector = normalize(vec2<f32>(cov2d[0][1], lambda1 - cov2d[0][0])); | ||
let majorAxis = min(sqrt(2.0 * lambda1), 1024.0) * diagonalVector; | ||
let minorAxis = min(sqrt(2.0 * lambda2), 1024.0) * vec2<f32>(diagonalVector.y, -diagonalVector.x); | ||
|
||
let vCenter = vec2<f32>(pos2d.x, pos2d.y); | ||
return vec4f( | ||
vCenter + ((meshPos.x * majorAxis + meshPos.y * minorAxis) * invViewport * pos2d.w) * scale, | ||
pos2d.z, | ||
pos2d.w | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/dev/core/src/ShadersWGSL/ShadersInclude/gaussianSplattingFragmentDeclaration.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fn gaussianColor(inColor: vec4f, inPosition: vec2f) -> vec4f | ||
{ | ||
var A : f32 = -dot(inPosition, inPosition); | ||
if (A > -4.0) | ||
{ | ||
var B: f32 = exp(A) * inColor.a; | ||
|
||
#include<logDepthFragment> | ||
|
||
var color: vec3f = inColor.rgb; | ||
|
||
#ifdef FOG | ||
#include<fogFragment> | ||
#endif | ||
|
||
return vec4f(color, B); | ||
} else { | ||
return vec4f(0.0); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/dev/core/src/ShadersWGSL/ShadersInclude/gaussianSplattingUboDeclaration.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include<sceneUboDeclaration> | ||
#include<meshUboDeclaration> | ||
|
||
attribute position: vec2f; |
1 change: 1 addition & 0 deletions
1
packages/dev/core/src/ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
attribute position: vec2f; |
15 changes: 15 additions & 0 deletions
15
packages/dev/core/src/ShadersWGSL/gaussianSplatting.fragment.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include<clipPlaneFragmentDeclaration> | ||
#include<logDepthDeclaration> | ||
#include<fogFragmentDeclaration> | ||
|
||
varying vColor: vec4f; | ||
varying vPosition: vec2f; | ||
|
||
#include<gaussianSplattingFragmentDeclaration> | ||
|
||
@fragment | ||
fn main(input: FragmentInputs) -> FragmentOutputs { | ||
#include<clipPlaneFragment> | ||
|
||
fragmentOutputs.color = gaussianColor(input.vColor, input.vPosition); | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/dev/core/src/ShadersWGSL/gaussianSplatting.vertex.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include<sceneUboDeclaration> | ||
#include<meshUboDeclaration> | ||
|
||
#include<clipPlaneVertexDeclaration> | ||
#include<fogVertexDeclaration> | ||
#include<logDepthDeclaration> | ||
|
||
// Attributes | ||
attribute splatIndex: f32; | ||
attribute position: vec2f; | ||
|
||
// Uniforms | ||
uniform invViewport: vec2f; | ||
uniform dataTextureSize: vec2f; | ||
uniform focal: vec2f; | ||
|
||
// textures | ||
var covariancesATexture: texture_2d<f32>; | ||
var covariancesBTexture: texture_2d<f32>; | ||
var centersTexture: texture_2d<f32>; | ||
var colorsTexture: texture_2d<f32>; | ||
|
||
// Output | ||
varying vColor: vec4f; | ||
varying vPosition: vec2f; | ||
|
||
#include<gaussianSplatting> | ||
|
||
@vertex | ||
fn main(input : VertexInputs) -> FragmentInputs { | ||
|
||
var splat: Splat = readSplat(input.splatIndex, uniforms.dataTextureSize); | ||
var covA: vec3f = splat.covA.xyz; | ||
var covB: vec3f = vec3f(splat.covA.w, splat.covB.xy); | ||
|
||
let worldPos: vec4f = mesh.world * vec4f(splat.center.xyz, 1.0); | ||
|
||
vertexOutputs.vColor = splat.color; | ||
vertexOutputs.vPosition = input.position; | ||
vertexOutputs.position = gaussianSplatting(input.position, worldPos.xyz, vec2f(1.0, 1.0), covA, covB, mesh.world, scene.view, scene.projection, uniforms.focal, uniforms.invViewport); | ||
|
||
#include<clipPlaneVertex> | ||
#include<fogVertex> | ||
#include<logDepthVertex> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters