avr-aics-riken / HIVE

Heterogeneously Integrated Visual-analytic Environment
10 stars 4 forks source link

CreateVolumeModel data cannot be scaled nor rotated. #8

Open siriusxiv opened 9 years ago

siriusxiv commented 9 years ago

When scaling or rotating CreateVolumeModel data, only the "container" is shifted while the actual data inside does not move.

You can reproduce that bug (if it is actually a bug) with the files in the following folder: https://github.com/siriusxiv/RandomFiles/tree/master/date_cannot_be_scaled_nor_rotated

See this picture for an example: output The cube has been rotated by a 45° rotation, but the data inside did not rotate (it seems that the data is repeated at the edges, in the sense: "reach the end -> back at the beginning").

syoyo commented 9 years ago

The cube has been rotated by a 45° rotation, but the data inside did not rotate

This is expected behaviour since the voxel access is done in world coordinate. To make it local coordinate(i.e. data rotate with shape), you need to apply the inverse transformation matrix to the texture coordinate in the shader.

We'll soon prepare an example how to do it.

siriusxiv commented 9 years ago

I see. I indeed thought this was the reason, but that may be very impractical if one must edit both the shader and the VolumeModel node. Maybe automatizing it would be a good idea. I'm looking forward to the example!

syoyo commented 9 years ago

Added lsgl_WorldInverse and lsgl_WorldInverseTranspose uniform variable in hrender. Please pull recent master of HIVE.git

https://github.com/avr-aics-riken/HIVE/commit/941f452a7b6b35ca2979d3bd61f0e6e751bb7591

You can simply use these values in the fragment shader to do inverse transform.

// framgment shader
uniform mat4 lsgl_WorldInverse;

void main() {
  // Use lsgl_WorldInverse here.
  ...
}

No manual scene description required for HIVE(hrender and HIVE UI) side.

Also, there's bug fix in GLSL compiler to use mat4 type in the fragment shader, thus you need to update SURFACE submodule.

siriusxiv commented 9 years ago

Thank you very much for the fix. I have updated everything to the latest commit.

However, I do not understand how to use the inverse transform (sorry I have never done OpenGL Shading Language before).

void main(void)
{
    vec3 p;
    vec3 n;
    vec3 dir;
    isectinfo(p, n, dir);
    vec3 rayorg = eye;
    vec3 raydir = p - eye;
    vec3 scale = vec3(width, height, depth);
    vec3 texpos = (p - offset) / scale + 0.5; // [0, 1]^3
    vec4 dens = texture3D(tex0, texpos);
    gl_FragColor = vec4(normalize(dens.xyz), 1.0);
    return;
}

Where should I use the lsgl_WorldInverse variable?

syoyo commented 9 years ago

Knowledge on 3D transformation is mandatory for visualisation.

This article would be a good introduction.

http://www.codinglabs.net/article_world_view_projection_matrix.aspx

siriusxiv commented 9 years ago

Sorry, this is not what I meant. I know 3D transforms. Anyway, thanks for the article, I will still read it.

What I do not know is how to use them in OpenGL Shading Language (is that actually the language used in .frag files?), and I know absolutely nothing about the structure of the .frag files you use, nor how they work.