Skip to content
Snippets Groups Projects
Commit 175e35a4 authored by Alexander Rose's avatar Alexander Rose
Browse files

direct volume rendering fixes

parent 4e3d01dd
No related branches found
No related tags found
No related merge requests found
...@@ -86,17 +86,12 @@ export namespace DirectVolume { ...@@ -86,17 +86,12 @@ export namespace DirectVolume {
const counts = { drawCount: VolumeBox.indices.length, groupCount, instanceCount } const counts = { drawCount: VolumeBox.indices.length, groupCount, instanceCount }
const vertices = new Float32Array(VolumeBox.vertices) const boundingSphere = getBoundingSphere(gridDimension.ref.value, gridTransform.ref.value, transform.aTransform.ref.value, transform.instanceCount.ref.value)
transformPositionArray(gridTransform.ref.value, vertices, 0, vertices.length / 3)
const boundingSphere = calculateBoundingSphere(
vertices, vertices.length / 3,
transform.aTransform.ref.value, transform.instanceCount.ref.value
)
const controlPoints = getControlPointsFromVec2Array(props.controlPoints) const controlPoints = getControlPointsFromVec2Array(props.controlPoints)
const transferTex = createTransferFunctionTexture(controlPoints) const transferTex = createTransferFunctionTexture(controlPoints)
const maxSteps = Math.ceil(Vec3.magnitude(gridDimension.ref.value)) * 2 const maxSteps = Math.ceil(Vec3.magnitude(gridDimension.ref.value)) * 2 * 5
return { return {
...color, ...color,
...@@ -135,12 +130,7 @@ export namespace DirectVolume { ...@@ -135,12 +130,7 @@ export namespace DirectVolume {
} }
export function updateBoundingSphere(values: DirectVolumeValues, directVolume: DirectVolume) { export function updateBoundingSphere(values: DirectVolumeValues, directVolume: DirectVolume) {
const vertices = new Float32Array(values.aPosition.ref.value) const boundingSphere = getBoundingSphere(values.uGridDim.ref.value, values.uTransform.ref.value, values.aTransform.ref.value, values.instanceCount.ref.value)
transformPositionArray(values.uTransform.ref.value, vertices, 0, vertices.length / 3)
const boundingSphere = calculateBoundingSphere(
vertices, Math.floor(vertices.length / 3),
values.aTransform.ref.value, values.instanceCount.ref.value
)
if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) { if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
ValueCell.update(values.boundingSphere, boundingSphere) ValueCell.update(values.boundingSphere, boundingSphere)
} }
...@@ -156,4 +146,19 @@ export namespace DirectVolume { ...@@ -156,4 +146,19 @@ export namespace DirectVolume {
Geometry.updateRenderableState(state, props) Geometry.updateRenderableState(state, props)
state.opaque = false state.opaque = false
} }
}
//
const mTmp = Mat4.identity()
const mTmp2 = Mat4.identity()
const vHalfUnit = Vec3.create(0.5, 0.5, 0.5)
const tmpVertices = new Float32Array(VolumeBox.vertices.length)
function getBoundingSphere(gridDimension: Vec3, gridTransform: Mat4, transform: Float32Array, transformCount: number) {
tmpVertices.set(VolumeBox.vertices)
Mat4.fromTranslation(mTmp, vHalfUnit)
Mat4.mul(mTmp, Mat4.fromScaling(mTmp2, gridDimension), mTmp)
Mat4.mul(mTmp, gridTransform, mTmp)
transformPositionArray(mTmp, tmpVertices, 0, tmpVertices.length / 3)
return calculateBoundingSphere(tmpVertices, tmpVertices.length / 3, transform, transformCount)
} }
\ No newline at end of file
...@@ -209,7 +209,7 @@ void main () { ...@@ -209,7 +209,7 @@ void main () {
vec3 rayDir = normalize(origPos - cameraPos); vec3 rayDir = normalize(origPos - cameraPos);
vec3 startLoc = unitCoord; vec3 startLoc = unitCoord;
vec3 step = rayDir * (1.0 / uGridDim) * 0.5; vec3 step = rayDir * (1.0 / uGridDim) * 0.1;
gl_FragColor = raymarch(startLoc, step, normalize(cameraPos)); gl_FragColor = raymarch(startLoc, step, normalize(cameraPos));
if (length(gl_FragColor.rgb) < 0.00001) discard; if (length(gl_FragColor.rgb) < 0.00001) discard;
......
...@@ -30,4 +30,11 @@ void main() { ...@@ -30,4 +30,11 @@ void main() {
origPos = unitCoord * uBboxSize + uBboxMin; origPos = unitCoord * uBboxSize + uBboxMin;
instance = aInstance; instance = aInstance;
gl_Position = uProjection * mvPosition; gl_Position = uProjection * mvPosition;
// clamp z position to clip space
if(gl_Position.z > gl_Position.w) {
gl_Position.z = gl_Position.w - 0.0001;
} else if(gl_Position.z < -gl_Position.w) {
gl_Position.z = -gl_Position.w + 0.0001;
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment