diff options
author | Lukas Steiblys <imbusy@imbusy.org> | 2009-10-02 02:29:15 +0400 |
---|---|---|
committer | Lukas Steiblys <imbusy@imbusy.org> | 2009-10-02 02:29:15 +0400 |
commit | 0677398a649b6b8c293df3ce3c6668f0a3be3bc8 (patch) | |
tree | 9d510a5bd23559bf4fae670ed04d7e5d6c12578c /source/blender/editors/space_view3d/drawvolume.c | |
parent | 59248e9f62006ba05e3098e4d213f3dcb23fe711 (diff) | |
parent | bc942eceacb638735dc4f4f68252c4c207147a70 (diff) |
merge from 23153 to 23595soc-2009-imbusy
Diffstat (limited to 'source/blender/editors/space_view3d/drawvolume.c')
-rw-r--r-- | source/blender/editors/space_view3d/drawvolume.c | 150 |
1 files changed, 113 insertions, 37 deletions
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index c8eda10566c..ef3627e2b12 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -121,31 +121,7 @@ struct GPUTexture; -/* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */ -static float cv[][3] = { - {1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, - {1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f} -}; - -// edges have the form edges[n][0][xyz] + t*edges[n][1][xyz] -static float edges[12][2][3] = { - {{1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, - {{-1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, - {{-1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, - {{1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, - - {{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}}, - {{-1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}}, - {{-1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}}, - {{1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}}, - - {{-1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, - {{-1.0f, -1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, - {{-1.0f, -1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}}, - {{-1.0f, 1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}} -}; - -int intersect_edges(float *points, float a, float b, float c, float d) +int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3]) { int i; float t; @@ -154,7 +130,7 @@ int intersect_edges(float *points, float a, float b, float c, float d) for (i=0; i<12; i++) { t = -(a*edges[i][0][0] + b*edges[i][0][1] + c*edges[i][0][2] + d) / (a*edges[i][1][0] + b*edges[i][1][1] + c*edges[i][1][2]); - if ((t>0)&&(t<2)) { + if ((t>0)&&(t<1)) { points[numpoints * 3 + 0] = edges[i][0][0] + edges[i][1][0]*t; points[numpoints * 3 + 1] = edges[i][0][1] + edges[i][1][1]*t; points[numpoints * 3 + 2] = edges[i][0][2] + edges[i][1][2]*t; @@ -191,9 +167,8 @@ static int larger_pow2(int n) return n*2; } -void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture *tex, int res[3], float dx, GPUTexture *tex_shadow) +void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture *tex, float *min, float *max, int res[3], float dx, GPUTexture *tex_shadow) { - Object *ob = base->object; RegionView3D *rv3d= ar->regiondata; float viewnormal[3]; @@ -204,6 +179,30 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture float cor[3] = {1.,1.,1.}; int gl_depth = 0, gl_blend = 0; + /* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */ + float cv[][3] = { + {1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, + {1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f} + }; + + // edges have the form edges[n][0][xyz] + t*edges[n][1][xyz] + float edges[12][2][3] = { + {{1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 2.0f}}, + {{-1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 2.0f}}, + {{-1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 2.0f}}, + {{1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 2.0f}}, + + {{1.0f, -1.0f, 1.0f}, {0.0f, 2.0f, 0.0f}}, + {{-1.0f, -1.0f, 1.0f}, {0.0f, 2.0f, 0.0f}}, + {{-1.0f, -1.0f, -1.0f}, {0.0f, 2.0f, 0.0f}}, + {{1.0f, -1.0f, -1.0f}, {0.0f, 2.0f, 0.0f}}, + + {{-1.0f, 1.0f, 1.0f}, {2.0f, 0.0f, 0.0f}}, + {{-1.0f, -1.0f, 1.0f}, {2.0f, 0.0f, 0.0f}}, + {{-1.0f, -1.0f, -1.0f}, {2.0f, 0.0f, 0.0f}}, + {{-1.0f, 1.0f, -1.0f}, {2.0f, 0.0f, 0.0f}} + }; + /* Fragment program to calculate the 3dview of smoke */ /* using 2 textures, density and shadow */ const char *text = "!!ARBfp1.0\n" @@ -223,13 +222,84 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture "MUL temp.b, temp.b, shadow.r;\n" "MOV result.color, temp;\n" "END\n"; - unsigned int prog; + GLuint prog; + + + float size[3]; + + VECSUB(size, max, min); + + // maxx, maxy, maxz + cv[0][0] = max[0]; + cv[0][1] = max[1]; + cv[0][2] = max[2]; + // minx, maxy, maxz + cv[1][0] = min[0]; + cv[1][1] = max[1]; + cv[1][2] = max[2]; + // minx, miny, maxz + cv[2][0] = min[0]; + cv[2][1] = min[1]; + cv[2][2] = max[2]; + // maxx, miny, maxz + cv[3][0] = max[0]; + cv[3][1] = min[1]; + cv[3][2] = max[2]; + + // maxx, maxy, minz + cv[4][0] = max[0]; + cv[4][1] = max[1]; + cv[4][2] = min[2]; + // minx, maxy, minz + cv[5][0] = min[0]; + cv[5][1] = max[1]; + cv[5][2] = min[2]; + // minx, miny, minz + cv[6][0] = min[0]; + cv[6][1] = min[1]; + cv[6][2] = min[2]; + // maxx, miny, minz + cv[7][0] = max[0]; + cv[7][1] = min[1]; + cv[7][2] = min[2]; + + VECCOPY(edges[0][0], cv[4]); // maxx, maxy, minz + VECCOPY(edges[1][0], cv[5]); // minx, maxy, minz + VECCOPY(edges[2][0], cv[6]); // minx, miny, minz + VECCOPY(edges[3][0], cv[7]); // maxx, miny, minz + + VECCOPY(edges[4][0], cv[3]); // maxx, miny, maxz + VECCOPY(edges[5][0], cv[2]); // minx, miny, maxz + VECCOPY(edges[6][0], cv[6]); // minx, miny, minz + VECCOPY(edges[7][0], cv[7]); // maxx, miny, minz + + VECCOPY(edges[8][0], cv[1]); // minx, maxy, maxz + VECCOPY(edges[9][0], cv[2]); // minx, miny, maxz + VECCOPY(edges[10][0], cv[6]); // minx, miny, minz + VECCOPY(edges[11][0], cv[5]); // minx, maxy, minz + + // printf("size x: %f, y: %f, z: %f\n", size[0], size[1], size[2]); + + edges[0][1][2] = size[2]; + edges[1][1][2] = size[2]; + edges[2][1][2] = size[2]; + edges[3][1][2] = size[2]; + + edges[4][1][1] = size[1]; + edges[5][1][1] = size[1]; + edges[6][1][1] = size[1]; + edges[7][1][1] = size[1]; + + edges[8][1][0] = size[0]; + edges[9][1][0] = size[0]; + edges[10][1][0] = size[0]; + edges[11][1][0] = size[0]; glGetBooleanv(GL_BLEND, (GLboolean *)&gl_blend); glGetBooleanv(GL_DEPTH_TEST, (GLboolean *)&gl_depth); wmLoadMatrix(rv3d->viewmat); - wmMultMatrix(ob->obmat); + // wmMultMatrix(ob->obmat); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); @@ -248,17 +318,19 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture y = cv[i][1] + viewnormal[1]; z = cv[i][2] + viewnormal[2]; - if ((x>=-1.0f)&&(x<=1.0f) - &&(y>=-1.0f)&&(y<=1.0f) - &&(z>=-1.0f)&&(z<=1.0f)) { + if ((x>=min[0])&&(x<=max[0]) + &&(y>=min[1])&&(y<=max[1]) + &&(z>=min[2])&&(z<=max[2])) { break; } } - if(GLEW_ARB_fragment_program) + // printf("i: %d\n", i); + + if (GL_TRUE == glewIsSupported("GL_ARB_fragment_program")) { - glGenProgramsARB(1, &prog); glEnable(GL_FRAGMENT_PROGRAM_ARB); + glGenProgramsARB(1, &prog); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog); glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(text), text); @@ -268,10 +340,14 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture // custom parameter for smoke style (higher = thicker) glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 1, 7.0, 7.0, 7.0, 1.0); } + else + printf("Your gfx card does not support 3dview smoke drawing.\n"); GPU_texture_bind(tex, 0); if(tex_shadow) GPU_texture_bind(tex_shadow, 1); + else + printf("No volume shadow\n"); if (!GLEW_ARB_texture_non_power_of_two) { cor[0] = (float)res[0]/(float)larger_pow2(res[0]); @@ -295,7 +371,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture float p0[3]; // intersect_edges returns the intersection points of all cube edges with // the given plane that lie within the cube - numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d); + numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d, edges); if (numpoints > 2) { VECCOPY(p0, points); @@ -318,7 +394,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture glBegin(GL_POLYGON); for (i = 0; i < numpoints; i++) { glColor3f(1.0, 1.0, 1.0); - glTexCoord3d((points[i * 3 + 0] + 1.0)*cor[0]/2.0, (points[i * 3 + 1] + 1)*cor[1]/2.0, (points[i * 3 + 2] + 1.0)*cor[2]/2.0); + glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]); glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]); } glEnd(); |