#include <patchdlm_context.h>
Nevrax France
Definition at line 55 of file patchdlm_context.h.
Public Member Functions | |
| void | compile (const CPointLight &pl, NLMISC::CRGBA landDiffMat, float maxAttEnd=30.f) |
Data Fields | |
| float | AttMax |
| float | AttMin |
| float | B |
| NLMISC::CAABBox | BBox |
| NLMISC::CBSphere | BSphere |
| float | CosMax |
| float | CosMin |
| CVector | Dir |
| float | G |
| bool | IsSpot |
| float | OOAttDelta |
| float | OOCosDelta |
| CVector | Pos |
| float | R |
|
||||||||||||||||
|
Definition at line 52 of file patchdlm_context.cpp. References AttMax, AttMin, NLMISC::CRGBA::B, NLMISC::CBSphere::Center, CosMax, CosMin, Dir, NLMISC::CRGBA::G, G, NL3D::CPointLight::getAttenuationBegin(), NL3D::CPointLight::getAttenuationEnd(), NL3D::CPointLight::getDiffuse(), NL3D::CPointLight::getPosition(), NL3D::CPointLight::getSpotAngleBegin(), NL3D::CPointLight::getSpotAngleEnd(), NL3D::CPointLight::getSpotDirection(), NL3D::CPointLight::getType(), IsSpot, min, nlassert, OOAttDelta, OOCosDelta, NLMISC::CRGBA::R, R, NLMISC::CBSphere::Radius, NLMISC::CAABBox::setCenter(), NLMISC::CAABBox::setHalfSize(), and NLMISC::sqr().
00053 {
00054 nlassert(maxAttEnd>0);
00055
00056 // copy color
00057 R= (float) (( pl.getDiffuse().R*(landDiffMat.R+1) ) >>8);
00058 G= (float) (( pl.getDiffuse().G*(landDiffMat.G+1) ) >>8);
00059 B= (float) (( pl.getDiffuse().B*(landDiffMat.B+1) ) >>8);
00060 // Copy Spot/Pos/Dir.
00061 IsSpot= pl.getType() == CPointLight::SpotLight;
00062 Pos= pl.getPosition();
00063 Dir= pl.getSpotDirection();
00064
00065 // compute spot params
00066 if(IsSpot)
00067 {
00068 CosMax= cosf(pl.getSpotAngleBegin());
00069 CosMin= cosf(pl.getSpotAngleEnd());
00070 }
00071 else
00072 {
00073 // with tesse Values, we have always (cosSpot-CosMin) * OOCosDelta > 1.0f
00074 CosMax= -1;
00075 CosMin= -2;
00076 }
00077 OOCosDelta= 1.f / (CosMax-CosMin);
00078
00079 // compute att params
00080 AttMax= pl.getAttenuationEnd();
00081 AttMin= pl.getAttenuationBegin();
00082 // infinite pointLight?
00083 if(AttMax==0)
00084 {
00085 AttMax= maxAttEnd;
00086 AttMin= maxAttEnd*0.99f;
00087 }
00088 // To big pointLigt?
00089 else if(AttMax>maxAttEnd)
00090 {
00091 AttMax= maxAttEnd;
00092 AttMin= min(AttMin, maxAttEnd*0.99f);
00093 }
00094 // compile distance
00095 OOAttDelta= 1.f / (AttMin-AttMax);
00096
00097
00098 // Compute bounding sphere.
00099 // If not a spot or if angleMin>Pi/2
00100 if(!IsSpot || CosMin<0)
00101 {
00102 // Take sphere of pointlight sphere
00103 BSphere.Center= Pos;
00104 BSphere.Radius= AttMax;
00105 // The bbox englobe the sphere.
00106 BBox.setCenter(Pos);
00107 BBox.setHalfSize(CVector(AttMax, AttMax, AttMax));
00108 }
00109 else
00110 {
00111 // Compute BSphere.
00112 //==============
00113
00114 // compute sinus of AngleMin
00115 float sinMin= sqrtf(1-sqr(CosMin));
00116
00117 // Test 2 centers: Center of radius along Dir: Pos+Dir*AttMax/2, and intersection of end cone with line (Pos,Dir)
00118 // Don't know why but I think they are sufficiently good :)
00119 // See below for computing of those centers.
00120
00121 /* compute radius of each sphere by taking max of 3 distances: distance to spotLight center, distance
00122 to spotLight forward extremity, and distance to spotLight circle interstion Cone/Sphere. (named DCCS)
00123 NB: Do the compute with radius=1 at first, then multiply later.
00124 */
00125 float radius1= 0.5f; // =max(0.5, 0.5); max distance to spot center and extremity center :)
00126 // for distance DCCS, this is the hypothenuse of (cosMin-0.5) + sinMin.
00127 float dccs= sqrtf( sqr(CosMin-0.5f) + sqr(sinMin));
00128 // take the bigger.
00129 radius1= max(radius1, dccs );
00130
00131 // Same reasoning for center2.
00132 float radius2= max(CosMin, 1-CosMin); // max distance to spot center and extremity center :)
00133 // for distance DCCS, it is simply sinMin!!
00134 dccs= sinMin;
00135 // take the bigger.
00136 radius2= max(radius2, dccs );
00137
00138
00139 // Then take the center which gives the smaller sphere
00140 if(radius1<radius2)
00141 {
00142 BSphere.Center= Pos + (Dir*0.5f*AttMax);
00143 // radius1 E [0,1], must take real size.
00144 BSphere.Radius= radius1 * AttMax;
00145 }
00146 else
00147 {
00148 BSphere.Center= Pos + (Dir*CosMin*AttMax);
00149 // radius2 E [0,1], must take real size.
00150 BSphere.Radius= radius2 * AttMax;
00151 }
00152
00153
00154 // Compute BBox.
00155 //==============
00156
00157 // just take bbox of the sphere, even if not optimal.
00158 BBox.setCenter(BSphere.Center);
00159 float rad= BSphere.Radius;
00160 BBox.setHalfSize( CVector(rad, rad, rad) );
00161 }
00162 }
|
|
|
Definition at line 73 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 75 of file patchdlm_context.h. Referenced by compile(). |
|
|
Definition at line 59 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(). |
|
|
Definition at line 84 of file patchdlm_context.h. Referenced by NL3D::CLandscape::computeDynamicLighting(). |
|
|
Definition at line 81 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and NL3D::CLandscape::computeDynamicLighting(). |
|
|
Definition at line 67 of file patchdlm_context.h. Referenced by compile(). |
|
|
Definition at line 69 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 65 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 59 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 61 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 77 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 71 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
|
|
Definition at line 63 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(). |
|
|
Definition at line 59 of file patchdlm_context.h. Referenced by NL3D::CPatchDLMContext::addPointLightInfluence(), and compile(). |
1.3.6