Changeset 3023 for branches


Ignore:
Timestamp:
Jun 5, 2012 12:08:41 PM (12 years ago)
Author:
ldelgass
Message:

Protocol, control for two-sided lighting in volume shader. Cutplane rendering
changes -- don't need to clip cutplanes, use simplified cutplane shader instead of switch in main volume shader. Still need to fix cutplanes of zincblende
volumes.

Location:
branches/nanovis2
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • branches/nanovis2/gui/scripts/nanovisviewer.tcl

    r3009 r3023  
    927927    PanCamera
    928928    SendCmd "camera zoom $_view(zoom)"
     929    FixSettings light2side
    929930    FixSettings light
    930931    FixSettings transp
     
    12191220                SendCmd "volume shading specularLevel $specularLevel"
    12201221                SendCmd "volume shading specularExp $specularExp"
     1222            }
     1223        }
     1224        light2side {
     1225            if {[isconnected]} {
     1226                set val $_settings($this-light2side)
     1227                SendCmd "volume shading light2side $val"
    12211228            }
    12221229        }
     
    17441751itcl::body Rappture::NanovisViewer::BuildVolumeTab {} {
    17451752    foreach { key value } {
     1753        light2side      0
    17461754        light           40
    17471755        transp          50
     
    17651773    label $inner.shading -text "Shading:" -font $fg
    17661774
     1775    checkbutton $inner.light2side -text "Two-sided lighting" -font $fg \
     1776        -variable [itcl::scope _settings($this-light2side)] \
     1777        -command [itcl::code $this FixSettings light2side]
     1778
    17671779    label $inner.dim -text "Glow" -font $fg
    17681780    ::scale $inner.light -from 0 -to 100 -orient horizontal \
     
    17961808        0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \
    17971809        1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \
    1798         2,0 $inner.dim -anchor e -pady 2 \
    1799         2,1 $inner.light -columnspan 2 -pady 2 -fill x \
    1800         2,3 $inner.bright -anchor w -pady 2 \
    1801         3,0 $inner.fog -anchor e -pady 2 \
    1802         3,1 $inner.transp -columnspan 2 -pady 2 -fill x \
    1803         3,3 $inner.plastic -anchor w -pady 2 \
    1804         4,0 $inner.thin -anchor e -pady 2 \
    1805         4,1 $inner.thickness -columnspan 2 -pady 2 -fill x\
    1806         4,3 $inner.thick -anchor w -pady 2
     1810        2,0 $inner.light2side -columnspan 4 -anchor w -pady 2 \
     1811        3,0 $inner.dim -anchor e -pady 2 \
     1812        3,1 $inner.light -columnspan 2 -pady 2 -fill x \
     1813        3,3 $inner.bright -anchor w -pady 2 \
     1814        4,0 $inner.fog -anchor e -pady 2 \
     1815        4,1 $inner.transp -columnspan 2 -pady 2 -fill x \
     1816        4,3 $inner.plastic -anchor w -pady 2 \
     1817        5,0 $inner.thin -anchor e -pady 2 \
     1818        5,1 $inner.thickness -columnspan 2 -pady 2 -fill x\
     1819        5,3 $inner.thick -anchor w -pady 2
    18071820
    18081821#        4,0 $inner.clear -anchor e -pady 2 \
     
    18121825
    18131826    blt::table configure $inner c0 c1 c3 r* -resize none
    1814     blt::table configure $inner r5 -resize expand
     1827    blt::table configure $inner r6 -resize expand
    18151828}
    18161829
  • branches/nanovis2/packages/vizservers/nanovis/Command.cpp

    r3007 r3023  
    13781378
    13791379static int
     1380VolumeShadingLight2SideOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1381                          Tcl_Obj *const *objv)
     1382{
     1383    bool twoSidedLighting;
     1384    if (GetBooleanFromObj(interp, objv[3], &twoSidedLighting) != TCL_OK) {
     1385        return TCL_ERROR;
     1386    }
     1387    std::vector<Volume *> ivol;
     1388    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
     1389        return TCL_ERROR;
     1390    }
     1391    std::vector<Volume *>::iterator iter;
     1392    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1393        (*iter)->twoSidedLighting(twoSidedLighting);
     1394    }
     1395    return TCL_OK;
     1396}
     1397
     1398static int
    13801399VolumeShadingOpacityOp(ClientData clientData, Tcl_Interp *interp, int objc,
    13811400                       Tcl_Obj *const *objv)
     
    14771496    {"diffuse",       1, VolumeShadingDiffuseOp,     4, 0, "value ?indices?",},
    14781497    {"isosurface",    1, VolumeShadingIsosurfaceOp,  4, 0, "bool ?indices?",},
     1498    {"light2side",    1, VolumeShadingLight2SideOp,  4, 0, "bool ?indices?",},
    14791499    {"opacity",       1, VolumeShadingOpacityOp,     4, 0, "value ?indices?",},
    14801500    {"specularExp",   9, VolumeShadingSpecularExpOp, 4, 0, "value ?indices?",},
  • branches/nanovis2/packages/vizservers/nanovis/ConvexPolygon.cpp

    r2902 r3023  
    2626}
    2727
    28 // Finds the intersection of the line through
    29 // p1 and p2 with the given plane, putting the
    30 // result in intersect.
    31 //
    32 // If the line lies in the plane, an arbitrary
    33 // point on the line is returned.
    34 //
    35 // http://astronomy.swin.edu.au/pbourke/geometry/planeline/
    36 bool
    37 findIntersection(const Vector4& pt1, const Vector4& pt2, const Vector4& plane, Vector4& ret)
    38 {
    39     float a = plane.x;
    40     float b = plane.y;
    41     float c = plane.z;
    42     float d = plane.w;
    43 
    44     Vector4 p1 = pt1;
    45     p1.perspectiveDivide();
    46     float x1 = p1.x;
    47     float y1 = p1.y;
    48     float z1 = p1.z;
    49 
    50     Vector4 p2 = pt2;
    51     p2.perspectiveDivide();
    52     float x2 = p2.x;
    53     float y2 = p2.y;
    54     float z2 = p2.z;
    55 
    56     float uDenom = a * (x1 - x2) + b * (y1 - y2) + c * (z1 - z2);
    57     float uNumer = a * x1 + b * y1 + c * z1 + d;
    58 
    59     if (uDenom == 0){
    60         //plane parallel to line
    61         ERROR("Unexpected code path: ConvexPolygon.cpp\n");
    62         if (uNumer == 0){
    63             ret = p1;
    64             return true;
    65         }
    66         return false;
    67     }
    68 
    69     float u = uNumer / uDenom;
    70     ret.x = x1 + u * (x2 - x1);
    71     ret.y = y1 + u * (y2 - y1);
    72     ret.z = z1 + u * (z2 - z1);
    73     ret.w = 1;
    74     return true;
    75 }
    76 
    7728void
    7829ConvexPolygon::transform(const Mat4x4& mat)
     
    9950}
    10051
    101 void
     52#define SIGN_DIFFERS(x, y) \
     53    ( ((x) < 0.0 && (y) > 0.0) || ((x) > 0.0 && (y) < 0.0) )
     54
     55bool
    10256ConvexPolygon::clip(Plane& clipPlane, bool copyToTexcoord)
    10357{
    10458    if (vertices.size() == 0) {
    105         //ERROR("ConvexPolygon: polygon has no vertices\n"); 
    106         return;
     59        ERROR("polygon has no vertices\n");
     60        return false;
    10761    }
    108    
     62
    10963    VertexVector clippedVerts;
    11064    clippedVerts.reserve(2 * vertices.size());
     
    11266    // The algorithm is as follows: for each vertex
    11367    // in the current poly, check to see which
    114     // half space it is in: clipped or retained.
     68    // half space it is in: clipped (outside) or inside.
    11569    // If the previous vertex was in the other
    116     // half space, find the intersect of that edge
    117     // with the clip plane and add that intersect
     70    // half space, find the intersection of that edge
     71    // with the clip plane and add that intersection
    11872    // point to the new list of vertices.  If the
    119     // current vertex is in the retained half-space,
     73    // current vertex is in the inside half-space,
    12074    // add it to the new list as well.
    12175
    122     Vector4 intersect;
    12376    Vector4 plane = clipPlane.getCoeffs();
    12477
    125     bool prevRetained = isRetained(vertices[0], plane);
    126     if (prevRetained)
    127         clippedVerts.push_back(vertices[0]);
    128 
    129     for (unsigned int i = 1; i < vertices.size(); i++) {
    130         bool retained = isRetained(vertices[i], plane);
    131         if (retained != prevRetained) {
    132             bool found = findIntersection(vertices[i - 1], vertices[i],
    133                                           plane, intersect);
    134             assert(found);
    135             clippedVerts.push_back(intersect);
     78    // This implementation is based on the Mesa 3D library (MIT license)
     79    int v1 = 0;
     80    // dot product >= 0 on/inside half-space, < 0 outside half-space
     81    float dot1 = vertices[v1] * plane;
     82    for (unsigned int i = 1; i <= vertices.size(); i++) {
     83        int v2 = (i == vertices.size()) ? 0 : i;
     84        float dot2 = vertices[v2] * plane;
     85        if (dot1 >= 0.0) {
     86            // on/inside
     87            clippedVerts.push_back(vertices[v1]);
    13688        }
    137         if (retained) {
    138             clippedVerts.push_back(vertices[i]);
     89        if (SIGN_DIFFERS(dot1, dot2)) {
     90            if (dot1 < 0.0) {
     91                // outside -> inside
     92                double t = dot1 / (dot1 - dot2);
     93                clippedVerts.push_back(vlerp(vertices[v1], vertices[v2], t));
     94            } else {
     95                // inside -> outside
     96                double t = dot2 / (dot2 - dot1);
     97                clippedVerts.push_back(vlerp(vertices[v2], vertices[v1], t));
     98            }
    13999        }
    140         prevRetained = retained;
    141     }
    142 
    143     bool retained = isRetained(vertices[0], plane);
    144     if (retained != prevRetained) {
    145         bool found = findIntersection(vertices[vertices.size() - 1],
    146                                       vertices[0], plane, intersect);
    147         assert(found);
    148         clippedVerts.push_back(intersect);
     100        dot1 = dot2;
     101        v1 = v2;
    149102    }
    150103
    151104    vertices.clear();
    152     vertices.insert(vertices.begin(),
    153                     clippedVerts.begin(),
    154                     clippedVerts.end());
    155105
    156     if (copyToTexcoord)
    157         copyVerticesToTexcoords();
     106    if (clippedVerts.size() < 3) {
     107        texcoords.clear();
     108        return false;
     109    } else {
     110        vertices.insert(vertices.begin(),
     111                        clippedVerts.begin(),
     112                        clippedVerts.end());
     113
     114        if (copyToTexcoord)
     115            copyVerticesToTexcoords();
     116
     117        return true;
     118    }
    158119}
     120
     121#undef SIGN_DIFFERS
    159122
    160123void
     
    180143            glVertex4fv((float *)&(vertices[i]));
    181144        }
    182     }
     145    } else {
     146        WARN("No polygons to render\n");
     147    }
    183148}
    184149
     
    199164            glVertex4fv((float *)(&tmp));
    200165        }
     166    } else {
     167        WARN("No polygons to render\n");
    201168    }
    202169}
  • branches/nanovis2/packages/vizservers/nanovis/ConvexPolygon.h

    r2877 r3023  
    3939
    4040    // Clips the polygon, retaining the portion where ax + by + cz + d >= 0
    41     void clip(Plane& clipPlane, bool copyToTexcoords);
     41    bool clip(Plane& clipPlane, bool copyToTexcoords);
    4242
    4343    void emit(bool useTexture);
     
    6363    }
    6464
    65     bool isRetained(const Vector4& point, const Vector4& plane)
    66     {
    67         return ((point * plane) >= 0); 
    68     }
    69 
    7065    VertexVector vertices;
    7166    TexVector texcoords;
  • branches/nanovis2/packages/vizservers/nanovis/Makefile.in

    r3007 r3023  
    155155shaders         = \
    156156                $(srcdir)/shaders/common.cg \
     157                $(srcdir)/shaders/cutplane_fp.cg \
     158                $(srcdir)/shaders/cutplane_vp.cg \
    157159                $(srcdir)/shaders/heightcolor.cg \
    158160                $(srcdir)/shaders/one_plane.cg \
  • branches/nanovis2/packages/vizservers/nanovis/NvRegularVolumeShader.cpp

    r3006 r3023  
    3939                     volume->isosurface(),
    4040                     volume->opacityScale(),
    41                      0.0f);
     41                     (volume->twoSidedLighting() ? 1.0f : 0.0f));
    4242
    4343    NvShader:: bind();
  • branches/nanovis2/packages/vizservers/nanovis/Vector3.h

    r3007 r3023  
    2626{
    2727public:
    28     float x, y, z;
    29 
    3028    Vector3()
    3129    {}
     
    177175    }
    178176
     177    float x, y, z;
     178
    179179private:
    180180    float radians(float degree) const
     
    186186typedef std::vector<Vector3> Vector3Array;
    187187
     188/**
     189 * \brief Linear interpolation of 2 vectors
     190 */
     191inline Vector3 vlerp(const Vector3& v1, const Vector3& v2, double t)
     192{
     193    return Vector3(v1.x * (1.0-t) + v2.x * t,
     194                   v1.y * (1.0-t) + v2.y * t,
     195                   v1.z * (1.0-t) + v2.z * t);
     196}
     197
    188198#endif
  • branches/nanovis2/packages/vizservers/nanovis/Vector4.h

    r3007 r3023  
    2424{
    2525public:
    26     float x, y, z, w;
    27 
    2826    Vector4()
    2927    {}
     
    7977        return Vector4(x / op2, y / op2, z / op2, w / op2);
    8078    }
     79
     80    float x, y, z, w;
    8181};
    8282
    8383typedef std::vector<Vector4> Vector4Array;
    8484
     85/**
     86 * \brief Linear interpolation of 2 points
     87 */
     88inline Vector4 vlerp(const Vector4& v1, const Vector4& v2, double t)
     89{
     90    return Vector4(v1.x * (1.0-t) + v2.x * t,
     91                   v1.y * (1.0-t) + v2.y * t,
     92                   v1.z * (1.0-t) + v2.z * t,
     93                   v1.w * (1.0-t) + v2.w * t);
     94}
     95
     96/**
     97 * \brief Finds the intersection of a line through
     98 * p1 and p2 with the given plane.
     99 *
     100 * If the line lies in the plane, an arbitrary
     101 * point on the line is returned.
     102 *
     103 * Reference:
     104 * http://astronomy.swin.edu.au/pbourke/geometry/planeline/
     105 *
     106 * \param[in] pt1 First point
     107 * \param[in] pt2 Second point
     108 * \param[in] plane Plane equation coefficients
     109 * \param[out] ret Point of intersection if a solution was found
     110 * \return Bool indicating if an intersection was found
     111 */
     112inline bool
     113planeLineIntersection(const Vector4& pt1, const Vector4& pt2,
     114                      const Vector4& plane, Vector4& ret)
     115{
     116    float a = plane.x;
     117    float b = plane.y;
     118    float c = plane.z;
     119    float d = plane.w;
     120
     121    Vector4 p1 = pt1;
     122    float x1 = p1.x;
     123    float y1 = p1.y;
     124    float z1 = p1.z;
     125
     126    Vector4 p2 = pt2;
     127    float x2 = p2.x;
     128    float y2 = p2.y;
     129    float z2 = p2.z;
     130
     131    float uDenom = a * (x1 - x2) + b * (y1 - y2) + c * (z1 - z2);
     132    float uNumer = a * x1 + b * y1 + c * z1 + d;
     133
     134    if (uDenom == 0.0f) {
     135        // Plane parallel to line
     136        if (uNumer == 0.0f) {
     137            // Line within plane
     138            ret = p1;
     139            return true;
     140        }
     141        // No solution
     142        TRACE("No intersection between line and plane\n");
     143        return false;
     144    }
     145
     146    float u = uNumer / uDenom;
     147    ret.x = x1 + u * (x2 - x1);
     148    ret.y = y1 + u * (y2 - y1);
     149    ret.z = z1 + u * (z2 - z1);
     150    ret.w = 1;
     151    return true;
     152}
     153
    85154#endif
  • branches/nanovis2/packages/vizservers/nanovis/Volume.cpp

    r3006 r3023  
    3737    _specular(0.3f),
    3838    _specularExp(90.0f),
     39    _lightTwoSide(false),
    3940    _opacityScale(0.5f),
    4041    _name(NULL),
  • branches/nanovis2/packages/vizservers/nanovis/Volume.h

    r3006 r3023  
    236236    }
    237237
     238    bool twoSidedLighting() const
     239    {
     240        return _lightTwoSide;
     241    }
     242
     243    void twoSidedLighting(bool value)
     244    {
     245        _lightTwoSide = value;
     246    }
     247
    238248    float opacityScale() const
    239249    {
     
    360370    float _specular;     ///< Specular level material coefficient
    361371    float _specularExp;  ///< Specular exponent
     372    bool _lightTwoSide;  ///< Two-sided lighting flag
     373
    362374    /**
    363375     * The scale multiplied to the opacity assigned by the
  • branches/nanovis2/packages/vizservers/nanovis/VolumeRenderer.cpp

    r3007 r3023  
    3838VolumeRenderer::~VolumeRenderer()
    3939{
     40    delete _cutplaneShader;
    4041    delete _zincBlendeShader;
    4142    delete _regularVolumeShader;
     
    4748void VolumeRenderer::initShaders()
    4849{
     50    _cutplaneShader = new NvShader();
     51    _cutplaneShader->loadVertexProgram("cutplane_vp.cg", "main");
     52    _cutplaneShader->loadFragmentProgram("cutplane_fp.cg", "main");
     53
    4954    //standard vertex program
    5055    _stdVertexShader = new NvStdVertexShader();
     
    102107    for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL;
    103108         hPtr = Tcl_NextHashEntry(&iter)) {
    104         Volume* volPtr;
     109        Volume *volPtr;
    105110        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
    106111        if (!volPtr->visible()) {
     
    226231        actual_slices[i] = n_actual_slices;
    227232
    228         // These are object coordinates
    229         Vector4 vert1 = (Vector4(-10, -10, -0.5, 1));
    230         Vector4 vert2 = (Vector4(-10, +10, -0.5, 1));
    231         Vector4 vert3 = (Vector4(+10, +10, -0.5, 1));
    232         Vector4 vert4 = (Vector4(+10, -10, -0.5, 1));
     233        TRACE("near: %g far: %g eye space bounds: (%g,%g)-(%g,%g) z_step: %g slices: %d",
     234              zNear, zFar, eyeMinX, eyeMaxX, eyeMinY, eyeMaxY, z_step, n_actual_slices);
     235
     236        Vector4 vert1, vert2, vert3, vert4;
    233237
    234238        // Render cutplanes first with depth test enabled.  They will mark the
     
    237241        // vice versa.
    238242
    239         ConvexPolygon static_poly;
    240243        for (int j = 0; j < volPtr->getCutplaneCount(); j++) {
    241244            if (!volPtr->isCutplaneEnabled(j)) {
     
    244247            float offset = volPtr->getCutplane(j)->offset;
    245248            int axis = volPtr->getCutplane(j)->orient;
    246            
    247             if (axis == 3) {
    248                 vert1 = Vector4(-10, -10, offset, 1);
    249                 vert2 = Vector4(-10, +10, offset, 1);
    250                 vert3 = Vector4(+10, +10, offset, 1);
    251                 vert4 = Vector4(+10, -10, offset, 1);
    252                 //continue;
    253             } else if (axis == 1) {
    254                 vert1 = Vector4(offset, -10, -10, 1);
    255                 vert2 = Vector4(offset, +10, -10, 1);
    256                 vert3 = Vector4(offset, +10, +10, 1);
    257                 vert4 = Vector4(offset, -10, +10, 1);
    258                 //continue;
    259             } else if (axis == 2) {
    260                 vert1 = Vector4(-10, offset, -10, 1);
    261                 vert2 = Vector4(+10, offset, -10, 1);
    262                 vert3 = Vector4(+10, offset, +10, 1);
    263                 vert4 = Vector4(-10, offset, +10, 1);
    264                 //continue;
     249
     250            switch (axis) {
     251            case 1:
     252                vert1 = Vector4(offset, 0, 0, 1);
     253                vert2 = Vector4(offset, 1, 0, 1);
     254                vert3 = Vector4(offset, 1, 1, 1);
     255                vert4 = Vector4(offset, 0, 1, 1);
     256                break;
     257            case 2:
     258                vert1 = Vector4(0, offset, 0, 1);
     259                vert2 = Vector4(1, offset, 0, 1);
     260                vert3 = Vector4(1, offset, 1, 1);
     261                vert4 = Vector4(0, offset, 1, 1);
     262                break;
     263            case 3:
     264            default:
     265                vert1 = Vector4(0, 0, offset, 1);
     266                vert2 = Vector4(1, 0, offset, 1);
     267                vert3 = Vector4(1, 1, offset, 1);
     268                vert4 = Vector4(0, 1, offset, 1);
     269                break;
    265270            }
    266271
    267             vert1 = model_view_no_trans.transform(vert1);
    268             vert2 = model_view_no_trans.transform(vert2);
    269             vert3 = model_view_no_trans.transform(vert3);
    270             vert4 = model_view_no_trans.transform(vert4);
    271 
    272             ConvexPolygon *p = &static_poly;
    273             p->vertices.clear();
    274 
    275             p->appendVertex(vert1);
    276             p->appendVertex(vert2);
    277             p->appendVertex(vert3);
    278             p->appendVertex(vert4);
    279 
    280             for (size_t k = 0; k < 6; k++) {
    281                 p->clip(volume_planes[k], true);
    282             }
    283 
    284             p->transform(model_view_no_trans_inverse);
    285             p->transform(model_view_trans);
     272            Vector4 texcoord1 = vert1;
     273            Vector4 texcoord2 = vert2;
     274            Vector4 texcoord3 = vert3;
     275            Vector4 texcoord4 = vert4;
     276
     277            _cutplaneShader->bind();
     278            _cutplaneShader->setFPTextureParameter("volume", volPtr->textureID());
     279            _cutplaneShader->setFPTextureParameter("tf", volPtr->transferFunction()->id());
    286280
    287281            glPushMatrix();
     282            glTranslatef(volPos.x, volPos.y, volPos.z);
    288283            glScalef(volScaling.x, volScaling.y, volScaling.z);
    289 
    290             activateVolumeShader(volPtr, true, 0.0f);
     284            _cutplaneShader->setGLStateMatrixVPParameter("modelViewProjMatrix",
     285                                                         NvShader::MODELVIEW_PROJECTION_MATRIX);
    291286            glPopMatrix();
    292287
     
    294289            glDisable(GL_BLEND);
    295290
    296             glBegin(GL_POLYGON);
    297             p->emit(true);
     291            glBegin(GL_QUADS);
     292            glTexCoord3f(texcoord1.x, texcoord1.y, texcoord1.z);
     293            glVertex3f(vert1.x, vert1.y, vert1.z);
     294            glTexCoord3f(texcoord2.x, texcoord2.y, texcoord2.z);
     295            glVertex3f(vert2.x, vert2.y, vert2.z);
     296            glTexCoord3f(texcoord3.x, texcoord3.y, texcoord3.z);
     297            glVertex3f(vert3.x, vert3.y, vert3.z);
     298            glTexCoord3f(texcoord4.x, texcoord4.y, texcoord4.z);
     299            glVertex3f(vert4.x, vert4.y, vert4.z);
    298300            glEnd();
     301
    299302            glDisable(GL_DEPTH_TEST);
    300 
    301             deactivateVolumeShader();
     303            _cutplaneShader->disableFPTextureParameter("tf");
     304            _cutplaneShader->disableFPTextureParameter("volume");
     305            _cutplaneShader->unbind();
    302306        } //done cutplanes
    303307
    304         //Now do volume rendering
     308        // Now prepare proxy geometry slices
    305309
    306310        // Initialize view-aligned quads with eye space bounds of
    307311        // volume
    308         vert1 = (Vector4(eyeMinX, eyeMinY, -0.5, 1));
    309         vert2 = (Vector4(eyeMaxX, eyeMinY, -0.5, 1));
    310         vert3 = (Vector4(eyeMaxX, eyeMaxY, -0.5, 1));
    311         vert4 = (Vector4(eyeMinX, eyeMaxY, -0.5, 1));
     312        vert1 = Vector4(eyeMinX, eyeMinY, -0.5, 1);
     313        vert2 = Vector4(eyeMaxX, eyeMinY, -0.5, 1);
     314        vert3 = Vector4(eyeMaxX, eyeMaxY, -0.5, 1);
     315        vert4 = Vector4(eyeMinX, eyeMaxY, -0.5, 1);
    312316
    313317        size_t counter = 0;
    314318
    315         //transform slices and store them
     319        // Transform slices and store them
    316320        float slice_z;
    317321        for (size_t j = 0; j < n_actual_slices; j++) {
     
    337341
    338342            for (size_t k = 0; k < 6; k++) {
    339                 poly->clip(volume_planes[k], true);
     343                if (!poly->clip(volume_planes[k], true))
     344                    break;
    340345            }
    341346
    342             poly->transform(model_view_no_trans_inverse);
    343             poly->transform(model_view_trans);
    344 
    345             if (poly->vertices.size() >= 3)
     347            if (poly->vertices.size() >= 3) {
     348                poly->transform(model_view_no_trans_inverse);
     349                poly->transform(model_view_trans);
    346350                total_rendered_slices++;
     351            }
    347352        }
    348353    } //iterate all volumes
     
    379384        int volume_index = slices[i].volumeId;
    380385        int slice_index = slices[i].sliceId;
    381         ConvexPolygon *cur = polys[volume_index][slice_index];
     386        ConvexPolygon *currentSlice = polys[volume_index][slice_index];
    382387        float z_step = z_steps[volume_index];
    383388
     
    396401
    397402#ifdef notdef
    398         TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d\n",
    399                volPtr->name(), volPtr, slice_index, volume_index);
     403        TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d z_step=%g avgSD=%g\n",
     404              volPtr->name(), volPtr, slice_index, volume_index, z_step, avgSampleDistance);
    400405#endif
    401406        activateVolumeShader(volPtr, false, sampleRatio);
     
    403408
    404409        glBegin(GL_POLYGON);
    405         cur->emit(true);
     410        currentSlice->emit(true);
    406411        glEnd();
    407412
  • branches/nanovis2/packages/vizservers/nanovis/VolumeRenderer.h

    r3006 r3023  
    8181    VolumeInterpolator *_volumeInterpolator;
    8282
    83     /**
    84      * shader for rendering a single cubic volume
     83    /**
     84     * Shader for single slice cutplane render
     85     */
     86    NvShader *_cutplaneShader;
     87
     88    /**
     89     * Shader for rendering a single cubic volume
    8590     */
    8691    NvRegularVolumeShader *_regularVolumeShader;
  • branches/nanovis2/packages/vizservers/nanovis/shaders/one_volume.cg

    r3013 r3023  
    2828 *   y: isosurface flag (opacity scaling on/off)
    2929 *   z: opacity scale
     30 *   w: two-sided lighting
    3031 */
    3132PixelOut main(v2f IN,
     
    6364            //lighting computation
    6465#ifndef LIGHT_TWO_SIDE
    65             float normal_dot_light = max(dot(normal, light_vector), 0);
    66             float normal_dot_half = max(dot(normal, half_vector), 0);
     66            float normal_dot_light = dot(normal, light_vector);
     67            float normal_dot_half = dot(normal, half_vector);
     68            if (renderParams.w > 0.5) {
     69                normal_dot_light = abs(normal_dot_light);
     70                normal_dot_half = abs(normal_dot_half);
     71            } else {
     72                normal_dot_light = max(normal_dot_light, 0);
     73                normal_dot_half = max(normal_dot_half, 0);
     74            }
    6775#else
    6876            float normal_dot_light = abs(dot(normal, light_vector));
  • branches/nanovis2/packages/vizservers/nanovis/shaders/zincblende_volume.cg

    r3006 r3023  
    6060    */
    6161
    62     //sample transfor function texture
     62    //sample transfer function texture
    6363    float4 color = f4tex1D(tf, sample);
    6464
Note: See TracChangeset for help on using the changeset viewer.