Twinklebear / webgl-volume-raycaster

A WebGL Volume Raycaster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

change cubeStrip value

kt7456 opened this issue · comments

var kyiv = {
x: 0.58,
y: 0.33
}
var cubeStrip = [
kyiv.x, kyiv.y, 0,
kyiv.x-0.1, kyiv.y, 0,
kyiv.x, kyiv.y, 0.1,
kyiv.x-0.1, kyiv.y, 0.1,
kyiv.x-0.1, kyiv.y-0.1, 0.1,
kyiv.x-0.1, kyiv.y, 0,
kyiv.x-0.1, kyiv.y-0.1,0,
kyiv.x, kyiv.y, 0,
kyiv.x, kyiv.y-0.1,0,
kyiv.x, kyiv.y, 0.1,
kyiv.x, kyiv.y-0.1, 0.1,
kyiv.x-0.1, kyiv.y-0.1, 0.1,
kyiv.x, kyiv.y-0.1, 0,
kyiv.x-0.1, kyiv.y-0.1, 0
];
I changed the value of cube but it doesn't render correctly,
please help me

The shaders are written with the assumption that the cube is a [0, 1] box: https://github.com/Twinklebear/webgl-volume-raycaster/blob/master/js/shader-srcs.js#L15 , https://github.com/Twinklebear/webgl-volume-raycaster/blob/master/js/shader-srcs.js#L69 . Since you've changed the position and size of the cube it breaks those assumptions, so the ray won't be set up properly to traverse the volume data.

If you want to rescale the volume you should change the volume_scale parameter: https://github.com/Twinklebear/webgl-volume-raycaster/blob/master/js/volume-raycaster.js#L124 . If you want to translate it, you'll need to adjust the vec3(0.5) here: https://github.com/Twinklebear/webgl-volume-raycaster/blob/master/js/shader-srcs.js#L15 . For a [0, 1] cube volume that translates the cube drawn so that it's from [-0.5, 0.5] and here: https://github.com/Twinklebear/webgl-volume-raycaster/blob/master/js/shader-srcs.js#L17 the eye is translated from the world (where the cube is in [-0.5, 0.5] so that it's centered in view), to the space where the cube is at [0, 1].

If you want the volume at the position and size you have above, you'll need to change the scale and the translation. You'll also need to change the translation into the world so that it's at the coordinates you have there and not from [-0.5, 0.5]