#include <meshvp_per_pixel_light.h>
Inheritance diagram for NL3D::CMeshVPPerPixelLight:
Coord Tex 0 : duplicate the tex Coord 0 set from the v.b. Coord Tex 1 : The light vector in tangent space. Coord Tex 2 : The half-angle vector in tangent space.
This is designed to work with material that got a 'PerPixelLighting' shader. Note that no bump is used with this shader.
It requires that the input mesh has its tangent space first column vector encoded in the 2nd texture coordinate. Other stages are not supported for now.
Note that this can be mixed with gouraud rendered light (the gouraud diffuse and specular component are still computed)
Nevrax France
Definition at line 58 of file meshvp_per_pixel_light.h.
Public Member Functions | |
CMeshVPPerPixelLight () | |
virtual std::string | getClassName ()=0 |
virtual float | getMaxVertexMove () |
const sint & | getRefCount () const |
IMeshVertexProgram implementation | |
virtual bool | begin (IDriver *drv, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat, const NLMISC::CVector &viewerPos) |
virtual void | end (IDriver *drv) |
virtual void | initInstance (CMeshBaseInstance *mbi) |
virtual bool | needTangentSpace () const |
NLMISC_DECLARE_CLASS (CMeshVPPerPixelLight) | |
virtual void | serial (NLMISC::IStream &f) throw (NLMISC::EStream) |
virtual void | setupForMaterial (const CMaterial &mat, IDriver *drv, CScene *scene, IVertexBufferHard *vb) |
virtual void | setupForMaterial (const CMaterial &mat, IDriver *drv, CScene *scene, CVertexBuffer *vb) |
MBR support. | |
Actually, it's targeted to work optimally with WindTree. Requirement are:
| |
virtual void | beginMBRInstance (IDriver *drv, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat) |
virtual void | beginMBRMesh (IDriver *drv, CScene *scene) |
virtual void | endMBRMesh (IDriver *drv) |
virtual bool | isMBRVpOk (IDriver *drv) const |
virtual bool | supportMeshBlockRendering () const |
MBR support. | |
Actually, it's targeted to work optimally with WindTree. Requirement are:
| |
virtual void | beginMBRInstance (IDriver *drv, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat) |
virtual void | beginMBRMesh (IDriver *drv, CScene *scene) |
virtual void | endMBRMesh (IDriver *drv) |
virtual bool | isMBRVpOk (IDriver *drv) const |
virtual bool | supportMeshBlockRendering () const |
Data Fields | |
sint | crefs |
CPtrInfo * | pinfo |
bool | SpecularLighting |
true if want Specular Lighting. | |
Static Public Attributes | |
CPtrInfo | NullPtrInfo |
Private Types | |
enum | { NumVp = 8 } |
Private Member Functions | |
void | enable (bool enabled, IDriver *drv) |
virtual bool | setupForMaterial (const CMaterial &mat, IDriver *drv, CScene *scene) |
Private Attributes | |
bool | _Enabled |
bool | _IsPointLight |
Static Private Attributes | |
std::auto_ptr< CVertexProgram > | _VertexProgram [NumVp] |
Friends | |
struct | CPtrInfo |
|
Definition at line 99 of file meshvp_per_pixel_light.h.
00099 { NumVp = 8}; |
|
Definition at line 64 of file meshvp_per_pixel_light.h. References _Enabled, and SpecularLighting.
00064 : SpecularLighting(true), _Enabled(false) {} |
|
Setup for gouraud lighting
Implements NL3D::IMeshVertexProgram. Definition at line 433 of file meshvp_per_pixel_light.cpp. References _IsPointLight, NL3D::CRenderTrav::beginVPLightSetup(), enable(), NL3D::CLight::getDirection(), NL3D::CRenderTrav::getDriverLight(), NL3D::CLight::getMode(), NL3D::CLight::getPosition(), NL3D::CScene::getRenderTrav(), NL3D::CRenderTrav::getStrongestLightIndex(), NL3D::IDriver::isVertexProgramEmulated(), NL3D::IDriver::isVertexProgramSupported(), NLMISC::CMatrix::mulVector(), NL3D::IDriver::setConstant(), NL3D::IDriver::setConstantMatrix(), sint, SpecularLighting, and NL3D::IDriver::supportPerPixelLighting().
00437 { 00438 // test if supported by driver 00439 if (! 00440 (drv->isVertexProgramSupported() 00441 && !drv->isVertexProgramEmulated() 00442 && drv->supportPerPixelLighting(SpecularLighting) 00443 ) 00444 ) 00445 { 00446 return false; 00447 } 00448 // 00449 CRenderTrav *renderTrav= &scene->getRenderTrav(); 00451 renderTrav->beginVPLightSetup(VPLightConstantStart, 00452 SpecularLighting, 00453 invertedModelMat); 00454 // 00455 sint strongestLightIndex = renderTrav->getStrongestLightIndex(); 00456 if (strongestLightIndex == -1) return false; // if no strongest light, disable this vertex program 00457 // setup the strongest light 00459 const CLight &strongestLight = renderTrav->getDriverLight(strongestLightIndex); 00460 00461 switch (strongestLight.getMode()) 00462 { 00463 case CLight::DirectionalLight: 00464 { 00465 // put light direction in object space 00466 NLMISC::CVector lPos = invertedModelMat.mulVector(strongestLight.getDirection()); 00467 drv->setConstant(4, lPos); 00468 _IsPointLight = false; 00469 } 00470 break; 00471 case CLight::PointLight: 00472 { 00473 // put light in object space 00474 NLMISC::CVector lPos = invertedModelMat * strongestLight.getPosition(); 00475 drv->setConstant(4, lPos); 00476 _IsPointLight = true; 00477 } 00478 break; 00479 default: 00480 return false; 00481 break; 00482 } 00483 00484 00485 if (SpecularLighting) 00486 { 00487 // viewer pos in object space 00488 NLMISC::CVector vPos = invertedModelMat * viewerPos; 00489 drv->setConstant(5, vPos); 00490 } 00491 00492 // c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix(); 00493 drv->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity); 00494 // 00495 enable(true, drv); // must enable the vertex program before the vb is activated 00496 // 00497 return true; 00498 } |
|
Reimplemented in NL3D::CMeshVPWindTree. Definition at line 123 of file mesh_vertex_program.h.
00123 {}; |
|
Reimplemented in NL3D::CMeshVPWindTree. Definition at line 122 of file mesh_vertex_program.h.
00122 {}; |
|
Definition at line 517 of file meshvp_per_pixel_light.cpp. References _Enabled, _IsPointLight, NL3D::IDriver::activeVertexProgram(), NL3D::IDriver::isForceNormalize(), nlassert, SpecularLighting, and uint. Referenced by begin(), end(), and setupForMaterial().
00518 { 00519 if (enabled != _Enabled) 00520 { 00521 nlassert(drv); 00522 if (enabled) 00523 { 00524 /* for (uint k = 0; k < NumVp; ++k) 00525 { 00526 nlinfo("test vp %d", k); 00527 drv->activeVertexProgram(_VertexProgram[k].get()); 00528 } */ 00529 uint idVP = (drv->isForceNormalize() ? 4 : 0) 00530 | (SpecularLighting ? 2 : 0) 00531 | (_IsPointLight ? 1 : 0); 00532 // 00533 drv->activeVertexProgram(_VertexProgram[idVP].get()); 00534 } 00535 else 00536 { 00537 drv->activeVertexProgram(NULL); 00538 } 00539 _Enabled = enabled; 00540 } 00541 } |
|
Setup for gouraud lighting
Implements NL3D::IMeshVertexProgram. Definition at line 502 of file meshvp_per_pixel_light.cpp. References enable().
00503 { 00504 enable(false, drv); 00505 } |
|
Reimplemented in NL3D::CMeshVPWindTree. Definition at line 124 of file mesh_vertex_program.h.
00124 {} |
|
Implemented in NLAIAGENT::CNumericIndex, NLAIC::IPointerGestion, NLAIC::CIdentType, and CAutomataDesc. Referenced by NLMISC::CClassRegistry::checkObject(), and NL3D::GetTextureSize(). |
|
This return the (over-evaluated) max delta the VertexProgram apply to vertex (in world basis) NB: This method call is relevant only after begin() or beginMBRInstance() Reimplemented in NL3D::CMeshVPWindTree. Definition at line 131 of file mesh_vertex_program.h.
00131 {return 0;}
|
|
Definition at line 70 of file smart_ptr.h. References NLMISC::CRefCount::crefs, and sint.
00071 { 00072 return crefs; 00073 } |
|
Setup for gouraud lighting
Implements NL3D::IMeshVertexProgram. Definition at line 371 of file meshvp_per_pixel_light.cpp. References nlassert, nlwarning, NumVp, CVPParser::parse(), NL3D::PPLightingDirectionnalNoSpecVPCodeBegin, NL3D::PPLightingDirectionnalNoSpecVPNormalizeCodeBegin, NL3D::PPLightingDirectionnalVPCodeBegin, NL3D::PPLightingDirectionnalVPNormalizeCodeBegin, NL3D::PPLightingNoSpecVPCodeBegin, NL3D::PPLightingVPCodeBegin, NL3D::PPLightingVPCodeEnd, NL3D::PPLightingVPNormalizeCodeBegin, NL3D::PPLightingVPNormalizeNoSpecCodeBegin, CVPParser::TProgram, and uint.
00372 { 00373 // init the vertexProgram code. 00374 static bool vpCreated= false; 00375 if(!vpCreated) 00376 { 00377 vpCreated= true; 00378 00379 // Gives each vp name 00380 // Bit 0 : 1 when it is a directionnal light 00381 // Bit 1 : 1 when specular is needed 00382 // Bit 2 : 1 when normalization of the tangent space is needed 00383 static const char *vpName[] = 00384 { 00385 // no spec 00386 PPLightingDirectionnalNoSpecVPCodeBegin, 00387 PPLightingNoSpecVPCodeBegin, 00388 // specular 00389 PPLightingDirectionnalVPCodeBegin, 00390 PPLightingVPCodeBegin, 00392 // no spec 00393 PPLightingDirectionnalNoSpecVPNormalizeCodeBegin, 00394 PPLightingVPNormalizeNoSpecCodeBegin, 00395 // spec 00396 PPLightingDirectionnalVPNormalizeCodeBegin, 00397 PPLightingVPNormalizeCodeBegin, 00398 }; 00399 00400 uint numvp = sizeof(vpName) / sizeof(const char *); 00401 nlassert(NumVp == numvp); // make sure that it is in sync with header..todo : compile time assert :) 00402 for (uint vp = 0; vp < NumVp; ++vp) 00403 { 00404 // \todo yoyo TODO_OPTIM Manage different number of pointLights 00405 // NB: never call getLightVPFragment() with normalize, because already done by PerPixel fragment before. 00406 std::string vpCode = std::string(vpName[vp]) 00407 + std::string("# ***************") // temp for debug 00408 + CRenderTrav::getLightVPFragment(CRenderTrav::MaxVPLight-1, VPLightConstantStart, (vp & 2) != 0, false) 00409 + std::string("# ***************") // temp for debug 00410 + std::string(PPLightingVPCodeEnd); 00411 #ifdef NL_DEBUG 00412 00417 CVPParser vpParser; 00418 CVPParser::TProgram result; 00419 std::string parseOutput; 00420 if (!vpParser.parse(vpCode.c_str(), result, parseOutput)) 00421 { 00422 nlwarning(parseOutput.c_str()); 00423 nlassert(0); 00424 } 00425 #endif 00426 _VertexProgram[vp]= std::auto_ptr<CVertexProgram>(new CVertexProgram(vpCode.c_str())); 00427 } 00428 00429 } 00430 } |
|
Reimplemented in NL3D::CMeshVPWindTree. Definition at line 121 of file mesh_vertex_program.h.
00121 {return false;} |
|
Setup for gouraud lighting
Reimplemented from NL3D::IMeshVertexProgram. Definition at line 84 of file meshvp_per_pixel_light.h.
00084 { return true; } |
|
Setup for gouraud lighting
|
|
Setup for gouraud lighting
Implements NLMISC::IStreamable. Definition at line 509 of file meshvp_per_pixel_light.cpp.
00510 { 00511 (void)f.serialVersion(0); 00512 f.serial(SpecularLighting); 00513 } |
|
Definition at line 544 of file meshvp_per_pixel_light.cpp. References _Enabled, NL3D::CRenderTrav::changeVPLightSetupMaterial(), enable(), NL3D::CScene::getRenderTrav(), NL3D::CMaterial::getShader(), NL3D::CMaterial::getShininess(), NL3D::CRenderTrav::getStrongestLightColors(), and NL3D::IDriver::setPerPixelLightingLight().
00548 { 00549 bool enabled = (mat.getShader() == CMaterial::PerPixelLighting || mat.getShader() == CMaterial::PerPixelLightingNoSpec); 00550 if (enabled) 00551 { 00552 CRenderTrav *renderTrav= &scene->getRenderTrav(); 00553 renderTrav->changeVPLightSetupMaterial(mat, true /* exclude strongest*/); 00554 00555 NLMISC::CRGBA pplDiffuse, pplSpecular; 00556 renderTrav->getStrongestLightColors(pplDiffuse, pplSpecular); 00557 drv->setPerPixelLightingLight(pplDiffuse, pplSpecular, mat.getShininess()); 00558 } 00559 bool change = (enabled != _Enabled); 00560 enable(enabled, drv); // enable disable the vertex program (for material that don't have the right shader) 00561 return change; 00562 } |
|
Setup for gouraud lighting
Implements NL3D::IMeshVertexProgram. Definition at line 577 of file meshvp_per_pixel_light.cpp. References NL3D::IDriver::activeVertexBufferHard(), and setupForMaterial().
00581 { 00582 00583 if (setupForMaterial(mat, drv, scene)) // a switch from v.p enabled / disabled force to reactivate the vertex buffer. 00584 { 00585 drv->activeVertexBufferHard(vb); 00586 } 00587 } |
|
Setup for gouraud lighting
Implements NL3D::IMeshVertexProgram. Definition at line 564 of file meshvp_per_pixel_light.cpp. References NL3D::IDriver::activeVertexBuffer(). Referenced by setupForMaterial().
00568 { 00569 00570 if (setupForMaterial(mat, drv, scene)) // a switch from v.p enabled / disabled force to reactivate the vertex buffer. 00571 { 00572 drv->activeVertexBuffer(*vb); 00573 } 00574 } |
|
Reimplemented in NL3D::CMeshVPWindTree. Definition at line 120 of file mesh_vertex_program.h.
00120 { return false; } |
|
Definition at line 67 of file smart_ptr.h. |
|
Definition at line 96 of file meshvp_per_pixel_light.h. Referenced by CMeshVPPerPixelLight(), enable(), and setupForMaterial(). |
|
Definition at line 97 of file meshvp_per_pixel_light.h. |
|
Definition at line 44 of file meshvp_per_pixel_light.cpp. |
|
Definition at line 79 of file smart_ptr.h. Referenced by NLMISC::CRefCount::CRefCount(), NLMISC::CRefCount::getRefCount(), and NLMISC::CRefCount::~CRefCount(). |
|
Referenced by NLMISC::CRefCount::CRefCount(). |
|
Definition at line 80 of file smart_ptr.h. Referenced by NLMISC::CRefCount::CRefCount(), and NLMISC::CRefCount::~CRefCount(). |
|
true if want Specular Lighting.
Definition at line 62 of file meshvp_per_pixel_light.h. Referenced by begin(), CMeshVPPerPixelLight(), and enable(). |