00001 !!ARBfp1.0
00002 OPTION NV_fragment_program2;
00003
00004 # Copyright (c) 2005 Institute for Visualization and Interactive
00005 # Systems, University of Stuttgart, Germany
00006 #
00007 # This source code is distributed as part of the single-pass volume
00008 # rendering project. Details about this project can be found on the
00009 # project web page at http://www.vis.uni-stuttgart.de/eng/research/
00010 # fields/current/spvolren. This file may be distributed, modified,
00011 # and used free of charge as long as this copyright notice is
00012 # included in its original form. Commercial use is strictly
00013 # prohibited.
00014 #
00015 # Filename: volume_mip_sm3.fp
00016
00017 #! VOLUME = 0
00018 #! BACKGROUND = 1
00019
00020 # r = step
00021 # g = gradient scale
00022 # b = gradient offset
00023 # a = z-value of background plane
00024 PARAM params = program.local[0];
00025
00026 # r = texture coordinate scale
00027 # g = number of iterations
00028 # b = isovalue of isosurface
00029 PARAM params2 = program.local[1];
00030 PARAM center = program.local[2];
00031 PARAM texMax = program.local[3];
00032
00033 PARAM scaleFactors = program.local[5];
00034
00035 TEMP geomPos;
00036 TEMP geomDir;
00037 TEMP lightVec;
00038 TEMP texblen;
00039 TEMP diffVec;
00040 TEMP eyeVec;
00041 TEMP intens;
00042 TEMP camera;
00043 TEMP normal;
00044 TEMP weight;
00045 TEMP temp1;
00046 TEMP temp2;
00047 TEMP temp;
00048 TEMP grad;
00049 TEMP sign;
00050 TEMP pos;
00051 TEMP src;
00052 TEMP dst;
00053 TEMP dir;
00054 TEMP tex;
00055 #TEMP count;
00056
00057 # Compute the ray's starting point
00058 MOV geomPos, fragment.texcoord[0];
00059 MUL pos, geomPos, scaleFactors;
00060 MOV pos.w, 0.0;
00061
00062 # Compute the camera position by translating the origin to the center of the
00063 # volume
00064 MOV camera, state.matrix.modelview.invtrans.row[3];
00065
00066 # Compute the ray direction
00067 SUB geomDir, geomPos, camera;
00068
00069 # Normalize the direction
00070 DP3 geomDir.w, geomDir, geomDir;
00071 RSQ geomDir.w, geomDir.w;
00072 MUL geomDir, geomDir, geomDir.w;
00073 MOV geomDir.w, 0.0;
00074
00075 MUL dir, geomDir, scaleFactors;
00076
00077 TEX intens, pos, texture[0], 3D;
00078 MOV intens.g, intens.a;
00079
00080 #MOV count, 0.0;
00081
00082 REP params2.g;
00083 REP params2.g;
00084
00085 #ADD count, count, 1.0;
00086
00087 TXL tex, pos, texture[0], 3D;
00088
00089 # Already outside volume, skip the rest
00090 SGE temp1, pos, 0.0;
00091 SLE temp2, pos, texMax;
00092 DP3 weight.r, temp1, temp2;
00093 SEQC weight.r, weight.r, 3.0;
00094 #MUL tex, tex, weight.r;
00095 BRK (LE.x);
00096
00097 # Component 'b' written to circumvent driver bug
00098 MOV intens.rb, tex.a;
00099
00100 # Component 'b' written to circumvent driver bug
00101 MOV intens.rb, tex.a;
00102 MOV grad.rgb, tex;
00103
00104 # Move one step forward
00105 MAD pos.xyz, dir, params.r, pos;
00106
00107 # Only required for MIP since preintegration table
00108 # already considers multiplication by alpha
00109 MUL src.rgb, src, src.a;
00110 MAX dst, dst, intens.r;
00111 ENDREP;
00112
00113 # Already outside volume, skip the rest
00114 BRK (LE.x);
00115
00116 ENDREP;
00117
00118 # Compute the normal of the background plane (this is just the negative view
00119 # direction which initially is (0, 0, -1))
00120 MOV normal, state.matrix.modelview.row[2];
00121
00122 # Compute the plane constant (we want the plane to be located in the volume
00123 # center)
00124 DP3 temp1.r, normal, center;
00125
00126 # Move the plane behind the volume: d' = <n,(x - l n)> = <n, x> - l <n, n>;
00127 # l = 0.71 is chosen since it is greater than half the cube diagonal
00128 DP3 temp1.g, normal, normal;
00129 MAD temp1.r, temp1.g, -.71, temp1.r;
00130
00131 # Compute ray parameter
00132 DP3 temp1.g, normal, geomPos;
00133 SUB temp1.g, temp1.r, temp1.g;
00134 DP3 temp1.b, normal, geomDir;
00135 DIV temp.r, temp1.g, temp1.b;
00136
00137 # Compute ray/plane intersection
00138 MAD temp.rgb, temp.r, geomDir, geomPos;
00139
00140 # Compute the difference vector
00141 SUB diffVec, temp, center;
00142
00143 # Compute the texture coordinates
00144 DP3 temp.r, diffVec, state.matrix.modelview.row[0];
00145 DP3 temp.g, diffVec, state.matrix.modelview.row[1];
00146 MUL temp.rg, temp, params2.r;
00147
00148 # Center background image
00149 ADD temp.rg, temp, .5;
00150
00151 # Look up the texel value
00152 TEX temp.rgb, temp, texture[1], 2D;
00153 MOV temp.a, 1.0;
00154
00155 # Blend the background pixel
00156 SUB texblen, 1.0, dst.a;
00157 MAD dst, temp, texblen.x, dst;
00158
00159 # Write the output color
00160 MOV result.color, dst;
00161
00162 END