Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGFatBorderChunk.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                           OpenSG NURBS Library                            *
00003  *                                                                           *
00004  *                                                                           *
00005  * Copyright (C) 2001-2004 by the University of Bonn, Computer Graphics Group*
00006  *                                                                           *
00007  *                         http://cg.cs.uni-bonn.de/                         *
00008  *                                                                           *
00009  * contact: edhellon@cs.uni-bonn.de, guthe@cs.uni-bonn.de, rk@cs.uni-bonn.de *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #define OSG_COMPILEMYEXTENSIONLIB
00047 
00048 #include <OSGConfig.h>
00049 
00050 #include "OSGFatBorderChunk.h"
00051 
00052 // vertex programs
00053 const char* vertexProgStandard =
00054     "!!ARBvp1.0\n"
00055 
00056     "PARAM  mvp[]   = { state.matrix.mvp };\n"
00057     "PARAM  mv[]    = { state.matrix.modelview[0] };\n"
00058     "PARAM  m_one   = { -1.0, -1.0, -1.0, 0.0 };\n"
00059     "PARAM  small   = { 0.00001, 0.00001, 0.00001, 0.0 };\n"
00060     "TEMP   temp, temp2, temp3;\n"
00061 
00062 //  ###########################################################
00063 //  # preserve texture coordinates
00064 //  ###########################################################
00065 
00066     "MOV        result.texcoord[0], vertex.texcoord[1];\n"
00067 //  # just for debugging    
00068 //  "MOV        result.color, vertex.texcoord[1];\n"
00069 
00070 //  ###########################################################
00071 //  # compute per vertex lighting (only one lightsource)
00072 //  # if normal maps are used, this could be switched off
00073 //  ###########################################################
00074 
00075     "DP3        temp2.x, mv[0], vertex.normal;\n"
00076     "DP3        temp2.y, mv[1], vertex.normal;\n"
00077     "DP3        temp2.z, mv[2], vertex.normal;\n"
00078     "DP3        temp, temp2, temp2;\n"
00079     "RSQ        temp, temp.x;\n"
00080     "MUL        temp2, temp, temp2;\n"
00081 
00082     "DP3        temp.x, state.light[0].position, temp2;\n"
00083     "DP3        temp.y, state.light[0].half, temp2;\n"
00084     "MOV        temp.w, state.material.shininess.x;\n"
00085     "LIT        temp, temp;\n"
00086     "MAD        temp3, temp.y, state.lightprod[0].front.diffuse, state.lightprod[0].front.ambient;\n"
00087     "ADD        temp3, temp3, state.material.emission;\n"
00088     "MAD        temp3, temp.z, state.lightprod[0].front.specular, temp3;\n"
00089 
00090 //  # double sided lighting
00091     "MUL        temp2, temp2, m_one;\n"
00092     "DP3        temp.x, state.light[0].position, temp2;\n"
00093     "DP3        temp.y, state.light[0].half, temp2;\n"
00094     "MOV        temp.w, state.material.shininess.x;\n"
00095     "LIT        temp, temp;\n"
00096     "MAD        temp3, temp.y, state.lightprod[0].back.diffuse, temp3;\n"
00097     "MAD        result.color, temp.z, state.lightprod[0].back.specular, temp3;\n"
00098 
00099 //  ###########################################################
00100 //  # compute view direction
00101 //  ###########################################################
00102 
00103     "MUL        temp2, m_one, mv[2];\n"
00104     "DP3        temp, temp2, temp2;\n"
00105     "RSQ        temp, temp.x;\n"
00106     "MUL        temp2, temp, temp2;\n"
00107 
00108 //  ###########################################################
00109 //  # compute movement based on texture coordinate 1
00110 //  # squared length of texcoord should be half width of fat border
00111 //  ###########################################################
00112 
00113 //  # calculate direction in sceen plane
00114     "XPD        temp, temp2, vertex.texcoord[0];\n"
00115     "DP3        temp3, temp, temp;\n"
00116     "ADD        temp3, temp3, small;\n"
00117     "RSQ        temp3, temp3.x;\n"
00118     "MUL        temp, temp3, temp;\n"
00119 //  # calculate factor from texture coordinate squarelength
00120     "DP3        temp3, vertex.texcoord[0], vertex.texcoord[0];\n"
00121     "MUL        temp3, {1,1,1,0}, temp3.x;\n"
00122 //  # apply movement
00123     "MAD        temp, temp, temp3, vertex.position;\n"
00124     "MAD        temp, temp2, temp3, temp;\n"
00125 
00126 
00127 //  ###########################################################
00128 //  # transform and project vertex
00129 //  ###########################################################
00130 
00131     "DP4        result.position.x, mvp[0], temp;\n"
00132     "DP4        result.position.y, mvp[1], temp;\n"
00133     "DP4        result.position.z, mvp[2], temp;\n"
00134     "DP4        result.position.w, mvp[3], temp;\n"
00135 
00136     "END\n";
00137 
00138 const char* vertexProgFBasedLight =
00139     "!!ARBvp1.0\n"
00140 
00141     "PARAM  mvp[]   = { state.matrix.mvp };\n"
00142     "PARAM  mv[]    = { state.matrix.modelview[0] };\n"
00143     "PARAM  m_one   = { -1.0, -1.0, -1.0, 0.0 };\n"
00144     "PARAM  small   = { 0.00001, 0.00001, 0.00001, 0.0 };\n"
00145     "TEMP   temp, temp2, temp3;\n"
00146 
00147 //  ###########################################################
00148 //  # preserve texture coordinates and store normal for fragment program
00149 //  ###########################################################
00150 
00151     "MOV        result.texcoord[1], vertex.texcoord[1];\n"
00152     "MOV        result.texcoord[0], vertex.normal;\n"
00153 
00154 //  ###########################################################
00155 //  # compute view direction
00156 //  ###########################################################
00157 
00158     "MUL        temp2, m_one, mv[2];\n"
00159     "DP3        temp, temp2, temp2;\n"
00160     "RSQ        temp, temp.x;\n"
00161     "MUL        temp2, temp, temp2;\n"
00162 
00163 //  ###########################################################
00164 //  # compute movement based on texture coordinate 1
00165 //  # squared length of texcoord should be half width of fat border
00166 //  ###########################################################
00167 
00168 //  # calculate direction in sceen plane
00169     "XPD        temp, temp2, vertex.texcoord[0];\n"
00170     "DP3        temp3, temp, temp;\n"
00171     "ADD        temp3, temp3, small;\n"
00172     "RSQ        temp3, temp3.x;\n"
00173     "MUL        temp, temp3, temp;\n"
00174 //  # calculate factor from texture coordinate squarelength
00175     "DP3        temp3, vertex.texcoord[0], vertex.texcoord[0];\n"
00176     "MUL        temp3, {1,1,1,0}, temp3.x;\n"
00177 //  # apply movement
00178     "MAD        temp, temp, temp3, vertex.position;\n"
00179     "MAD        temp, temp2, temp3, temp;\n"
00180 
00181 
00182 //  ###########################################################
00183 //  # transform and project vertex
00184 //  ###########################################################
00185 
00186     "DP4        result.position.x, mvp[0], temp;\n"
00187     "DP4        result.position.y, mvp[1], temp;\n"
00188     "DP4        result.position.z, mvp[2], temp;\n"
00189     "DP4        result.position.w, mvp[3], temp;\n"
00190 
00191 //  # Just for testing the fragment shader's presence
00192 //  "MOV        result.color, {1,0,0,0};\n"
00193 
00194     "END\n";
00195 
00196 OSG_USING_NAMESPACE
00197 
00202 /***************************************************************************\
00203  *                           Class variables                               *
00204 \***************************************************************************/
00205 
00206 /***************************************************************************\
00207  *                           Class methods                                 *
00208 \***************************************************************************/
00209 
00210 void FatBorderChunk::initMethod (void)
00211 {
00212 }
00213 
00214 
00215 /***************************************************************************\
00216  *                           Instance methods                              *
00217 \***************************************************************************/
00218 
00219 /*-------------------------------------------------------------------------*\
00220  -  private                                                                 -
00221 \*-------------------------------------------------------------------------*/
00222 
00223 /*----------------------- constructors & destructors ----------------------*/
00224 
00225 FatBorderChunk::FatBorderChunk(void) :
00226     Inherited()
00227 {
00228 // Don't do that in the constructor
00229 //  activateWithStandardLighting( );
00230 }
00231 
00232 FatBorderChunk::FatBorderChunk(const FatBorderChunk &source) :
00233     Inherited(source)
00234 {
00235 }
00236 
00237 
00238 void FatBorderChunk::onCreate(const FatBorderChunk *)
00239 {
00240     if(GlobalSystemState == Startup)
00241         return;
00242 
00243     Inherited::onCreate(NULL);
00244     activateWithStandardLighting();
00245 }
00246 
00247 FatBorderChunk::~FatBorderChunk(void)
00248 {
00249 }
00250 
00251 /*----------------------------- class specific ----------------------------*/
00252 
00253 void FatBorderChunk::changed(BitVector whichField, UInt32 origin)
00254 {
00255     Inherited::changed(whichField, origin);
00256 }
00257 
00258 void FatBorderChunk::dump(      UInt32    , 
00259                          const BitVector ) const
00260 {
00261     SLOG << "Dump FatBorderChunk NI" << std::endl;
00262 }
00263 
00264 void FatBorderChunk::activateWithStandardLighting( )
00265 {
00266     beginEditCP( FatBorderChunkPtr( this ), ProgramFieldMask );
00267     {
00268         setProgram( vertexProgStandard );
00269 //      setProgram( "" );
00270     }
00271     endEditCP( FatBorderChunkPtr( this ), ProgramFieldMask );
00272 }
00273 
00274 void FatBorderChunk::activateWithFragmentBasedLighting( )
00275 {
00276     beginEditCP( FatBorderChunkPtr( this ), ProgramFieldMask );
00277     {
00278         setProgram( vertexProgFBasedLight );
00279 //      setProgram( "" );
00280     }
00281     endEditCP( FatBorderChunkPtr( this ), ProgramFieldMask );
00282 }
00283 
00284 /*------------------------------------------------------------------------*/
00285 /*                              cvs id's                                  */
00286 
00287 #ifdef OSG_SGI_CC
00288 #pragma set woff 1174
00289 #endif
00290 
00291 #ifdef OSG_LINUX_ICC
00292 #pragma warning( disable : 177 )
00293 #endif
00294 
00295 namespace
00296 {
00297     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00298     static Char8 cvsid_hpp       [] = OSGFATBORDERCHUNKBASE_HEADER_CVSID;
00299     static Char8 cvsid_inl       [] = OSGFATBORDERCHUNKBASE_INLINE_CVSID;
00300 
00301     static Char8 cvsid_fields_hpp[] = OSGFATBORDERCHUNKFIELDS_HEADER_CVSID;
00302 }
00303 
00304 #ifdef __sgi
00305 #pragma reset woff 1174
00306 #endif
00307 

Generated on Thu Aug 25 04:04:38 2005 for OpenSG by  doxygen 1.4.3