void UnderWaterGodRay::_updateRays() { Camera * cam = World::Instance()->MainCamera(); const Vec3 * corner = cam->GetCorner(); float FarWidth = (corner[4] - corner[5]).Length(); float RaysLength = cam->GetFarClip(); VertexBufferPtr vb = mRender.vxStream.GetStream(0); Vec3 * vert = (Vec3*)vb->Lock(0, 0, LOCK_DISCARD); Vec2 Pos; float Dis, RayLength; for(int k = 0; k < mNumberOfRays; k++) { Pos = _calculateRayPosition(k); Dis = mRaysSize * RaysLength; RayLength = RaysLength * (0.3f + Pos.Length()); Pos *= FarWidth/2; // 4 Planes, 3 vertices each plane, 12 vertices per ray // ----> 1/4 // 0 *vert++ = Vec3(0, 0, 0); // A *vert++ = Vec3(Pos.x, Pos.y, -RayLength); // B *vert++ = Vec3(Pos.x+Dis, Pos.y, -RayLength); // ----> 2/4 // 0 *vert++ = Vec3(0, 0, 0); // D *vert++ = Vec3(Pos.x+Dis, Pos.y+Dis, -RayLength); // B *vert++ = Vec3(Pos.x+Dis, Pos.y, -RayLength); // ----> 3/4 // 0 *vert++ = Vec3(0, 0, 0); // C *vert++ = Vec3(Pos.x, Pos.y+Dis, -RayLength); // D *vert++ = Vec3(Pos.x+Dis, Pos.y+Dis, -RayLength); // ----> 4/4 // 0 *vert++ = Vec3(0, 0, 0); // C *vert++ = Vec3(Pos.x, Pos.y+Dis, -RayLength); // A *vert++ = Vec3(Pos.x, Pos.y, -RayLength); } vb->Unlock(); }
void GodRaysManager::_updateRays() { // Get frustum corners to calculate far plane dimensions const Ogre::Vector3 *FrustumCorners = mProjectorCamera->getWorldSpaceCorners(); // Calcule far plane dimensions float FarWidth = (FrustumCorners[4] - FrustumCorners[5]).length(); Ogre::Real RaysLength = mProjectorCamera->getFarClipDistance(); mManualGodRays->beginUpdate(0); Ogre::Vector2 Pos; Ogre::Real Dis, RayLength; // Rays are modeled as piramids, 12 vertex each ray // // // 0\\ // /| | | // || | | // || | | (0,0) (1,0) // || | | A B // || | | // |A----|-|B (0,1) (1,1) // |/ |/ C D // C------D for(int k = 0; k < mNumberOfRays; k++) { Pos = _calculateRayPosition(k); Dis = mRaysSize*RaysLength; RayLength = RaysLength*(0.95+Pos.length()); Pos *= FarWidth/2; // 4 Planes, 3 vertices each plane, 12 vertices per ray // ----> 1/4 // 0 mManualGodRays->position(0, 0, 0); // A mManualGodRays->position(Pos.x, Pos.y, -RayLength); // B mManualGodRays->position(Pos.x+Dis, Pos.y, -RayLength); // ----> 2/4 // 0 mManualGodRays->position(0, 0, 0); // D mManualGodRays->position(Pos.x+Dis, Pos.y+Dis, -RayLength); // B mManualGodRays->position(Pos.x+Dis, Pos.y, -RayLength); // ----> 3/4 // 0 mManualGodRays->position(0, 0, 0); // C mManualGodRays->position(Pos.x, Pos.y+Dis, -RayLength); // D mManualGodRays->position(Pos.x+Dis, Pos.y+Dis, -RayLength); // ----> 4/4 // 0 mManualGodRays->position(0, 0, 0); // C mManualGodRays->position(Pos.x, Pos.y+Dis, -RayLength); // A mManualGodRays->position(Pos.x, Pos.y, -RayLength); } mManualGodRays->end(); }