Exemple #1
0
void GGLAssembler::build_fog(
                        component_t& temp,      // incomming fragment / output
                        int component,
                        Scratch& regs)
{
   if (mInfo[component].fog) {
        Scratch scratches(registerFile());
        comment("fog");

        integer_t fragment(temp.reg, temp.h, temp.flags);
        if (!(temp.flags & CORRUPTIBLE)) {
            temp.reg = regs.obtain();
            temp.flags |= CORRUPTIBLE;
        }

        integer_t fogColor(scratches.obtain(), 8, CORRUPTIBLE); 
        LDRB(AL, fogColor.reg, mBuilderContext.Rctx,
                immed12_pre(GGL_OFFSETOF(state.fog.color[component])));

        integer_t factor(scratches.obtain(), 16, CORRUPTIBLE);
        CONTEXT_LOAD(factor.reg, generated_vars.f);

        // clamp fog factor (TODO: see if there is a way to guarantee
        // we won't overflow, when setting the iterators)
        BIC(AL, 0, factor.reg, factor.reg, reg_imm(factor.reg, ASR, 31));
        CMP(AL, factor.reg, imm( 0x10000 ));
        MOV(HS, 0, factor.reg, imm( 0x10000 ));

        build_blendFOneMinusF(temp, factor, fragment, fogColor);
    }
}
void SceneTerrain::Reload()
{
	vec3 fogColor(0.7f, 0.7f, 0.9f);
	m_pShaderTerrain->Activate();
	m_pShaderTerrain->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
	m_pShaderTerrain->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
	m_pShaderTerrain->Uniform("fog_color", fogColor);
	m_pShaderTerrain->Deactivate();

	m_pShaderWater->Activate();
	m_pShaderWater->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
	m_pShaderWater->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
	m_pShaderWater->Uniform("fog_color", fogColor);
	m_pShaderWater->Deactivate();
}
Exemple #3
0
void SkyBox::_initRender()
{
   GFXVertexPNTT *tmpVerts = NULL;

   U32 vertCount = 36;

   if ( !mDrawBottom )
      vertCount = 30;

   mPrimCount = vertCount / 3;

   // Create temp vertex pointer
   // so we can read from it
   // for generating the normals below.
   tmpVerts = new GFXVertexPNTT[vertCount];

   // We don't bother sharing
   // vertices here, in order to
   // avoid using a primitive buffer.
   tmpVerts[0].point.set( -1, -1, 1 );
   tmpVerts[1].point.set( 1, -1, 1 );
   tmpVerts[2].point.set( 1, -1, -1 );

   tmpVerts[0].texCoord.set( 0, 0 );
   tmpVerts[1].texCoord.set( 1.0f, 0 );
   tmpVerts[2].texCoord.set( 1.0f, 1.0f );

   tmpVerts[3].point.set( -1, -1, 1 );
   tmpVerts[4].point.set( 1, -1, -1 );
   tmpVerts[5].point.set( -1, -1, -1 );

   tmpVerts[3].texCoord.set( 0, 0 );
   tmpVerts[4].texCoord.set( 1.0f, 1.0f );
   tmpVerts[5].texCoord.set( 0, 1.0f );

   tmpVerts[6].point.set( 1, -1, 1 );
   tmpVerts[7].point.set( 1, 1, 1 );
   tmpVerts[8].point.set( 1, 1, -1 );

   tmpVerts[6].texCoord.set( 0, 0 );
   tmpVerts[7].texCoord.set( 1.0f, 0 );
   tmpVerts[8].texCoord.set( 1.0f, 1.0f );

   tmpVerts[9].point.set( 1, -1, 1 );
   tmpVerts[10].point.set( 1, 1, -1 );
   tmpVerts[11].point.set( 1, -1, -1 );

   tmpVerts[9].texCoord.set( 0, 0 );
   tmpVerts[10].texCoord.set( 1.0f, 1.0f );
   tmpVerts[11].texCoord.set( 0, 1.0f );

   tmpVerts[12].point.set( -1, 1, 1 );
   tmpVerts[13].point.set( -1, -1, 1 );
   tmpVerts[14].point.set( -1, -1, -1 );

   tmpVerts[12].texCoord.set( 0, 0 );
   tmpVerts[13].texCoord.set( 1.0f, 0 );
   tmpVerts[14].texCoord.set( 1.0f, 1.0f );

   tmpVerts[15].point.set( -1, 1, 1 );
   tmpVerts[16].point.set( -1, -1, -1 ); 
   tmpVerts[17].point.set( -1, 1, -1 );

   tmpVerts[15].texCoord.set( 0, 0 );
   tmpVerts[16].texCoord.set( 1.0f, 1.0f ); 
   tmpVerts[17].texCoord.set( 1.0f, 0 );

   tmpVerts[18].point.set( 1, 1, 1 );
   tmpVerts[19].point.set( -1, 1, 1 );
   tmpVerts[20].point.set( -1, 1, -1 );

   tmpVerts[18].texCoord.set( 0, 0 );
   tmpVerts[19].texCoord.set( 1.0f, 0 );
   tmpVerts[20].texCoord.set( 1.0f, 1.0f );

   tmpVerts[21].point.set( 1, 1, 1 );
   tmpVerts[22].point.set( -1, 1, -1 );
   tmpVerts[23].point.set( 1, 1, -1 );

   tmpVerts[21].texCoord.set( 0, 0 );
   tmpVerts[22].texCoord.set( 1.0f, 1.0f );
   tmpVerts[23].texCoord.set( 0, 1.0f );

   tmpVerts[24].point.set( -1, -1, 1 );
   tmpVerts[25].point.set( -1, 1, 1 );
   tmpVerts[26].point.set( 1, 1, 1 );

   tmpVerts[24].texCoord.set( 0, 0 );
   tmpVerts[25].texCoord.set( 1.0f, 0 );
   tmpVerts[26].texCoord.set( 1.0f, 1.0f );

   tmpVerts[27].point.set( -1, -1, 1 );
   tmpVerts[28].point.set( 1, 1, 1 );
   tmpVerts[29].point.set( 1, -1, 1 );

   tmpVerts[27].texCoord.set( 0, 0 );
   tmpVerts[28].texCoord.set( 1.0f, 1.0f );
   tmpVerts[29].texCoord.set( 0, 1.0f );

   // Only set up these
   // vertices if the SkyBox
   // is set to render the bottom face.
   if ( mDrawBottom )
   {
      tmpVerts[30].point.set( 1, 1, -1 ); 
      tmpVerts[31].point.set( -1, 1, -1 );
      tmpVerts[32].point.set( -1, -1, -1 );

      tmpVerts[30].texCoord.set( 1.0f, 1.0f ); 
      tmpVerts[31].texCoord.set( 1.0f, 0 );
      tmpVerts[32].texCoord.set( 0, 0 );

      tmpVerts[33].point.set( 1, -1, -1 ); 
      tmpVerts[34].point.set( 1, 1, -1 );
      tmpVerts[35].point.set( -1, -1, -1 );

      tmpVerts[33].texCoord.set( 0, 1.0f ); 
      tmpVerts[34].texCoord.set( 1.0f, 1.0f );
      tmpVerts[35].texCoord.set( 0, 0 );
   }

   VectorF tmp( 0, 0, 0 );

   for ( U32 i = 0; i < vertCount; i++ )
   {
      //tmp = tmpVerts[i].point;
      //tmp.normalize();
      //tmpVerts[i].normal.set( tmp );

      // Note: SkyBox renders with a regular material, which uses the "Reflect Cube"
      // feature. 
      //
      // This feature is really designed a cubemap representing a reflection
      // on an objects surface and therefore looks up into the cubemap with the 
      // cubemap-space view vector reflected by the vert normal. 
      //
      // Since we are actually viewing the skybox from "inside" not from 
      // "outside" this reflection ends up making the cubemap appear upsidown. 
      // Therefore we set the vert-normals to "zero" so that the reflection 
      // operation returns the input, unreflected, vector.

      tmpVerts[i].normal.set( Point3F::Zero );
   }

   if ( mVB.isNull() || mIsVBDirty )
   {
      mVB.set( GFX, vertCount, GFXBufferTypeStatic );
      mIsVBDirty = false;
   }

   GFXVertexPNTT *vertPtr = mVB.lock();
   if (!vertPtr)
   {
      delete[] tmpVerts;
      return;
   }

   dMemcpy( vertPtr, tmpVerts, sizeof ( GFXVertexPNTT ) * vertCount );

   mVB.unlock();

   // Clean up temp verts.
   delete [] tmpVerts;

   if ( mFogBandVB.isNull() )
      mFogBandVB.set( GFX, 48, GFXBufferTypeStatic );

   GFXVertexPC *bandVertPtr = mFogBandVB.lock();
   if(!bandVertPtr) return;

   // Grab the fog color.
   ColorI fogColor( mLastFogColor.red * 255, mLastFogColor.green * 255, mLastFogColor.blue * 255 );
   ColorI fogColorAlpha( mLastFogColor.red * 255, mLastFogColor.green * 255, mLastFogColor.blue * 255, 0 );

   // Upper portion of band geometry.
   {
      bandVertPtr[0].point.set( -1, -1, mFogBandHeight );
      bandVertPtr[1].point.set( 1, -1, mFogBandHeight );
      bandVertPtr[2].point.set( 1, -1, 0 );

      bandVertPtr[0].color.set( fogColorAlpha );
      bandVertPtr[1].color.set( fogColorAlpha );
      bandVertPtr[2].color.set( fogColor );

      bandVertPtr[3].point.set( -1, -1, mFogBandHeight );
      bandVertPtr[4].point.set( 1, -1, 0 );
      bandVertPtr[5].point.set( -1, -1, 0 );

      bandVertPtr[3].color.set( fogColorAlpha );
      bandVertPtr[4].color.set( fogColor );
      bandVertPtr[5].color.set( fogColor );

      bandVertPtr[6].point.set( 1, -1, mFogBandHeight );
      bandVertPtr[7].point.set( 1, 1, mFogBandHeight );
      bandVertPtr[8].point.set( 1, 1, 0 );

      bandVertPtr[6].color.set( fogColorAlpha );
      bandVertPtr[7].color.set( fogColorAlpha );
      bandVertPtr[8].color.set( fogColor );

      bandVertPtr[9].point.set( 1, -1, mFogBandHeight );
      bandVertPtr[10].point.set( 1, 1, 0 );
      bandVertPtr[11].point.set( 1, -1, 0 );

      bandVertPtr[9].color.set( fogColorAlpha );
      bandVertPtr[10].color.set( fogColor );
      bandVertPtr[11].color.set( fogColor );

      bandVertPtr[12].point.set( -1, 1, mFogBandHeight );
      bandVertPtr[13].point.set( -1, -1, mFogBandHeight );
      bandVertPtr[14].point.set( -1, -1, 0 );

      bandVertPtr[12].color.set( fogColorAlpha );
      bandVertPtr[13].color.set( fogColorAlpha );
      bandVertPtr[14].color.set( fogColor );

      bandVertPtr[15].point.set( -1, 1, mFogBandHeight );
      bandVertPtr[16].point.set( -1, -1, 0 ); 
      bandVertPtr[17].point.set( -1, 1, 0 );

      bandVertPtr[15].color.set( fogColorAlpha );
      bandVertPtr[16].color.set( fogColor );
      bandVertPtr[17].color.set( fogColor );

      bandVertPtr[18].point.set( 1, 1, mFogBandHeight );
      bandVertPtr[19].point.set( -1, 1, mFogBandHeight );
      bandVertPtr[20].point.set( -1, 1, 0 );

      bandVertPtr[18].color.set( fogColorAlpha );
      bandVertPtr[19].color.set( fogColorAlpha );
      bandVertPtr[20].color.set( fogColor );

      bandVertPtr[21].point.set( 1, 1, mFogBandHeight );
      bandVertPtr[22].point.set( -1, 1, 0 );
      bandVertPtr[23].point.set( 1, 1, 0 );

      bandVertPtr[21].color.set( fogColorAlpha );
      bandVertPtr[22].color.set( fogColor );
      bandVertPtr[23].color.set( fogColor );
   }

   // Lower portion of band geometry.
   {
      bandVertPtr[24].point.set( -1, -1, 0 );
      bandVertPtr[25].point.set( 1, -1, 0 );
      bandVertPtr[26].point.set( 1, -1, -1 );

      bandVertPtr[24].color.set( fogColor );
      bandVertPtr[25].color.set( fogColor );
      bandVertPtr[26].color.set( fogColor );

      bandVertPtr[27].point.set( -1, -1, 0 );
      bandVertPtr[28].point.set( 1, -1, -1 );
      bandVertPtr[29].point.set( -1, -1, -1 );

      bandVertPtr[27].color.set( fogColor );
      bandVertPtr[28].color.set( fogColor );
      bandVertPtr[29].color.set( fogColor );

      bandVertPtr[30].point.set( 1, -1, 0 );
      bandVertPtr[31].point.set( 1, 1, 0 );
      bandVertPtr[32].point.set( 1, 1, -1 );

      bandVertPtr[30].color.set( fogColor );
      bandVertPtr[31].color.set( fogColor );
      bandVertPtr[32].color.set( fogColor );

      bandVertPtr[33].point.set( 1, -1, 0 );
      bandVertPtr[34].point.set( 1, 1, -1 );
      bandVertPtr[35].point.set( 1, -1, -1 );

      bandVertPtr[33].color.set( fogColor );
      bandVertPtr[34].color.set( fogColor );
      bandVertPtr[35].color.set( fogColor );

      bandVertPtr[36].point.set( -1, 1, 0 );
      bandVertPtr[37].point.set( -1, -1, 0 );
      bandVertPtr[38].point.set( -1, -1, -1 );

      bandVertPtr[36].color.set( fogColor );
      bandVertPtr[37].color.set( fogColor );
      bandVertPtr[38].color.set( fogColor );

      bandVertPtr[39].point.set( -1, 1, 0 );
      bandVertPtr[40].point.set( -1, -1, -1 ); 
      bandVertPtr[41].point.set( -1, 1, -1 );

      bandVertPtr[39].color.set( fogColor );
      bandVertPtr[40].color.set( fogColor );
      bandVertPtr[41].color.set( fogColor );

      bandVertPtr[42].point.set( 1, 1, 0 );
      bandVertPtr[43].point.set( -1, 1, 0 );
      bandVertPtr[44].point.set( -1, 1, -1 );

      bandVertPtr[42].color.set( fogColor );
      bandVertPtr[43].color.set( fogColor );
      bandVertPtr[44].color.set( fogColor );

      bandVertPtr[45].point.set( 1, 1, 0 );
      bandVertPtr[46].point.set( -1, 1, -1 );
      bandVertPtr[47].point.set( 1, 1, -1 );

      bandVertPtr[45].color.set( fogColor );
      bandVertPtr[46].color.set( fogColor );
      bandVertPtr[47].color.set( fogColor );
   }

   mFogBandVB.unlock();

   SAFE_DELETE( mFogBandMatInst );
   if ( mFogBandMat )
   {
      mFogBandMat->deleteObject();
      mFogBandMat = NULL;
   }

   // Setup the material for this imposter.
   mFogBandMat = MATMGR->allocateAndRegister( String::EmptyString );
   mFogBandMat->mAutoGenerated = true;   
   mFogBandMat->mTranslucent = true;   
   mFogBandMat->mVertColor[0] = true;
   mFogBandMat->mDoubleSided = true;
   mFogBandMat->mEmissive[0] = true;

   mFogBandMatInst = mFogBandMat->createMatInstance();
   mFogBandMatInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<GFXVertexPC>() );
}
		void GLSpriteRenderer::Render() {
			SPADES_MARK_FUNCTION();
			lastImage = NULL;
			program->Use();
			
			projectionViewMatrix(program);
			rightVector(program);
			upVector(program);
			texture(program);
			viewMatrix(program);
			fogDistance(program);
			fogColor(program);
			
			positionAttribute(program);
			spritePosAttribute(program);
			colorAttribute(program);
			
			projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
			viewMatrix.SetValue(renderer->GetViewMatrix());
			
			fogDistance.SetValue(renderer->GetFogDistance());
			
			Vector3 fogCol = renderer->GetFogColor();
			fogColor.SetValue(fogCol.x,fogCol.y,fogCol.z);
			
			const client::SceneDefinition& def = renderer->GetSceneDef();
			rightVector.SetValue(def.viewAxis[0].x,
								 def.viewAxis[0].y,
								 def.viewAxis[0].z);
			upVector.SetValue(def.viewAxis[1].x,
							  def.viewAxis[1].y,
							  def.viewAxis[1].z);
			texture.SetValue(0);
			
			device->ActiveTexture(0);
			
			device->EnableVertexAttribArray(positionAttribute(), true);
			device->EnableVertexAttribArray(spritePosAttribute(), true);
			device->EnableVertexAttribArray(colorAttribute(), true);
			
			
			for(size_t i = 0; i < sprites.size(); i++){
				Sprite& spr = sprites[i];
				if(spr.image != lastImage){
					Flush();
					lastImage = spr.image;
					SPAssert(vertices.empty());
				}
				
				Vertex v;
				v.x = spr.center.x;
				v.y = spr.center.y;
				v.z = spr.center.z;
				v.radius = spr.radius;
				v.angle = spr.angle;
				v.r = spr.color.x;
				v.g = spr.color.y;
				v.b = spr.color.z;
				v.a = spr.color.w;
				
				uint32_t idx = (uint32_t)vertices.size();
				v.sx = -1; v.sy = -1;
				vertices.push_back(v);
				v.sx = 1; v.sy = -1;
				vertices.push_back(v);
				v.sx = -1; v.sy = 1;
				vertices.push_back(v);
				v.sx = 1; v.sy = 1;
				vertices.push_back(v);
				
				indices.push_back(idx);
				indices.push_back(idx + 1);
				indices.push_back(idx + 2);
				indices.push_back(idx + 1);
				indices.push_back(idx + 3);
				indices.push_back(idx + 2);
			}
		
			Flush();
			
			device->EnableVertexAttribArray(positionAttribute(), false);
			device->EnableVertexAttribArray(spritePosAttribute(), false);
			device->EnableVertexAttribArray(colorAttribute(), false);
		}
		void GLSoftSpriteRenderer::Render() {
			SPADES_MARK_FUNCTION();
			lastImage = NULL;
			program->Use();

			device->Enable(IGLDevice::Blend, true);
			device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);

			projectionViewMatrix(program);
			rightVector(program);
			frontVector(program);
			viewOriginVector(program);
			upVector(program);
			texture(program);
			depthTexture(program);
			viewMatrix(program);
			fogDistance(program);
			fogColor(program);
			zNearFar(program);

			positionAttribute(program);
			spritePosAttribute(program);
			colorAttribute(program);

			projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
			viewMatrix.SetValue(renderer->GetViewMatrix());

			fogDistance.SetValue(renderer->GetFogDistance());

			Vector3 fogCol = renderer->GetFogColor();
			fogCol *= fogCol; // linearize
			fogColor.SetValue(fogCol.x, fogCol.y, fogCol.z);

			const client::SceneDefinition &def = renderer->GetSceneDef();
			rightVector.SetValue(def.viewAxis[0].x, def.viewAxis[0].y, def.viewAxis[0].z);
			upVector.SetValue(def.viewAxis[1].x, def.viewAxis[1].y, def.viewAxis[1].z);
			frontVector.SetValue(def.viewAxis[2].x, def.viewAxis[2].y, def.viewAxis[2].z);

			viewOriginVector.SetValue(def.viewOrigin.x, def.viewOrigin.y, def.viewOrigin.z);
			texture.SetValue(0);
			depthTexture.SetValue(1);
			zNearFar.SetValue(def.zNear, def.zFar);

			device->ActiveTexture(1);
			device->BindTexture(IGLDevice::Texture2D,
			                    renderer->GetFramebufferManager()->GetDepthTexture());
			device->ActiveTexture(0);

			device->EnableVertexAttribArray(positionAttribute(), true);
			device->EnableVertexAttribArray(spritePosAttribute(), true);
			device->EnableVertexAttribArray(colorAttribute(), true);

			thresLow = tanf(def.fovX * .5f) * tanf(def.fovY * .5f) * 1.8f;
			thresRange = thresLow * .5f;

			// full-resolution sprites
			{
				GLProfiler::Context measure(renderer->GetGLProfiler(), "Full Resolution");
				for (size_t i = 0; i < sprites.size(); i++) {
					Sprite &spr = sprites[i];
					float layer = LayerForSprite(spr);
					if (layer == 1.f)
						continue;
					if (spr.image != lastImage) {
						Flush();
						lastImage = spr.image;
						SPAssert(vertices.empty());
					}

					Vertex v;
					v.x = spr.center.x;
					v.y = spr.center.y;
					v.z = spr.center.z;
					v.radius = spr.radius;
					v.angle = spr.angle;
					v.r = spr.color.x;
					v.g = spr.color.y;
					v.b = spr.color.z;
					v.a = spr.color.w;

					float fade = 1.f - layer;
					v.r *= fade;
					v.g *= fade;
					v.b *= fade;
					v.a *= fade;

					uint32_t idx = (uint32_t)vertices.size();
					v.sx = -1;
					v.sy = -1;
					vertices.push_back(v);
					v.sx = 1;
					v.sy = -1;
					vertices.push_back(v);
					v.sx = -1;
					v.sy = 1;
					vertices.push_back(v);
					v.sx = 1;
					v.sy = 1;
					vertices.push_back(v);

					indices.push_back(idx);
					indices.push_back(idx + 1);
					indices.push_back(idx + 2);
					indices.push_back(idx + 1);
					indices.push_back(idx + 3);
					indices.push_back(idx + 2);
				}

				Flush();
			}

			// low-res sprites
			IGLDevice::UInteger lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
			int sW = device->ScreenWidth(), sH = device->ScreenHeight();
			int lW = (sW + 3) / 4, lH = (sH + 3) / 4;
			int numLowResSprites = 0;
			GLColorBuffer buf = renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
			device->BindFramebuffer(IGLDevice::Framebuffer, buf.GetFramebuffer());
			device->ClearColor(0.f, 0.f, 0.f, 0.f);
			device->Clear(IGLDevice::ColorBufferBit);
			device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
			device->Viewport(0, 0, lW, lH);
			{
				GLProfiler::Context measure(renderer->GetGLProfiler(), "Low Resolution");
				for (size_t i = 0; i < sprites.size(); i++) {
					Sprite &spr = sprites[i];
					float layer = LayerForSprite(spr);
					if (layer == 0.f)
						continue;
					if (spr.image != lastImage) {
						Flush();
						lastImage = spr.image;
						SPAssert(vertices.empty());
					}

					numLowResSprites++;

					Vertex v;
					v.x = spr.center.x;
					v.y = spr.center.y;
					v.z = spr.center.z;
					v.radius = spr.radius;
					v.angle = spr.angle;
					v.r = spr.color.x;
					v.g = spr.color.y;
					v.b = spr.color.z;
					v.a = spr.color.w;

					float fade = layer;
					v.r *= fade;
					v.g *= fade;
					v.b *= fade;
					v.a *= fade;

					uint32_t idx = (uint32_t)vertices.size();
					v.sx = -1;
					v.sy = -1;
					vertices.push_back(v);
					v.sx = 1;
					v.sy = -1;
					vertices.push_back(v);
					v.sx = -1;
					v.sy = 1;
					vertices.push_back(v);
					v.sx = 1;
					v.sy = 1;
					vertices.push_back(v);

					indices.push_back(idx);
					indices.push_back(idx + 1);
					indices.push_back(idx + 2);
					indices.push_back(idx + 1);
					indices.push_back(idx + 3);
					indices.push_back(idx + 2);
				}
				Flush();
			}

			// finalize

			device->ActiveTexture(1);
			device->BindTexture(IGLDevice::Texture2D, 0);
			device->ActiveTexture(0);
			device->BindTexture(IGLDevice::Texture2D, 0);
			device->EnableVertexAttribArray(positionAttribute(), false);
			device->EnableVertexAttribArray(spritePosAttribute(), false);
			device->EnableVertexAttribArray(colorAttribute(), false);

			// composite downsampled sprite
			device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
			if (numLowResSprites > 0) {
				GLProfiler::Context measure(renderer->GetGLProfiler(), "Finalize");
				GLQuadRenderer qr(device);

				// do gaussian blur
				GLProgram *program =
				  renderer->RegisterProgram("Shaders/PostFilters/Gauss1D.program");
				static GLProgramAttribute blur_positionAttribute("positionAttribute");
				static GLProgramUniform blur_textureUniform("mainTexture");
				static GLProgramUniform blur_unitShift("unitShift");
				program->Use();
				blur_positionAttribute(program);
				blur_textureUniform(program);
				blur_unitShift(program);
				blur_textureUniform.SetValue(0);
				device->ActiveTexture(0);
				qr.SetCoordAttributeIndex(blur_positionAttribute());
				device->Enable(IGLDevice::Blend, false);

				// x-direction
				GLColorBuffer buf2 =
				  renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
				device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
				device->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
				blur_unitShift.SetValue(1.f / lW, 0.f);
				qr.Draw();
				buf.Release();

				// x-direction
				GLColorBuffer buf3 =
				  renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
				device->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
				device->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
				blur_unitShift.SetValue(0.f, 1.f / lH);
				qr.Draw();
				buf2.Release();

				buf = buf3;

				device->Enable(IGLDevice::Blend, true);

				// composite
				program = renderer->RegisterProgram("Shaders/PostFilters/PassThrough.program");
				static GLProgramAttribute positionAttribute("positionAttribute");
				static GLProgramUniform colorUniform("colorUniform");
				static GLProgramUniform textureUniform("mainTexture");
				static GLProgramUniform texCoordRange("texCoordRange");

				positionAttribute(program);
				textureUniform(program);
				texCoordRange(program);
				colorUniform(program);

				program->Use();

				textureUniform.SetValue(0);
				texCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
				colorUniform.SetValue(1.f, 1.f, 1.f, 1.f);

				qr.SetCoordAttributeIndex(positionAttribute());
				device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
				device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
				device->Viewport(0, 0, sW, sH);
				qr.Draw();
				device->BindTexture(IGLDevice::Texture2D, 0);

			} else {
				device->Viewport(0, 0, sW, sH);

				device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
			}

			buf.Release();
		}
void SceneTerrain::Init()
{
	SINGLETON_GET( ResourceManager, res )
	SINGLETON_GET( VarManager, var )

	m_vSunAngle = vec2(0.0f, RADIANS(45.0f));

	m_pSkybox   = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "xposD.jpg xnegD.jpg yposD.jpg ynegD.jpg zposD.jpg znegD.jpg");
	m_pNightbox = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "xposN.jpg xnegN.jpg yposN.jpg ynegN.jpg zposN.jpg znegN.jpg");


	m_pShaderLighting	= (Shader*)res.LoadResource(ResourceManager::SHADER, "lighting");
	m_pShaderTerrain	= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_ground");
	m_pShaderWater		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_water");
	m_pShaderGrass		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_grass");
	m_pShaderTree		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_tree");

	res.LoadResource(ResourceManager::MESH, "terrain_house.3d");

	res.LoadResource(ResourceManager::TEXTURE2D, "wall_diffuse.jpg");
	res.LoadResource(ResourceManager::TEXTURE2D, "wall_NM_height.tga");

	// These are textures used to render the final terrain
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_detail_NM.tga") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_sand_512.jpg") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_rocky_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_grass_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_water_caustics.jpg") );	
	
	
	res.LoadResource(ResourceManager::TEXTURE2D, "grass_billboards.tga");
	res.LoadResource(ResourceManager::TEXTURE2D, "palm_texture.tga");

	m_pTexWaterNoiseNM = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_NM.jpg");
	m_pTerrainDiffuseMap = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "heightmap_1024_diffusemap.jpg");

	m_pTerrain = new Terrain();
	assert(m_pTerrain != NULL);
	BoundingBox bbox( vec3(.0f, .0f, .0f), vec3(1025.0f, 255.0f, 1025.0f) );	// TODO : Calculate this so can be modified in game.
	m_pTerrain->Load("heightmap_1024.jpg", bbox, 32);	// 16

	ImageTools::ImageData img;
	ImageTools::OpenImage("heightmap_1024.jpg", img);
	std::cout << "   HeightMap D: " << img.d << " Size: " << img.w << "x" << img.h << std::endl;
	m_pTerrain->GenerateGrass(img, 200);				// 200000 GRASS AMOUNT
	m_pTerrain->GenerateVegetation(img, 25);
	m_pTerrain->ComputeBoundingBox();
	img.Destroy();

	vec3 fogColor(0.7f, 0.7f, 0.9f);
	m_pShaderTerrain->Activate();
		m_pShaderTerrain->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
		m_pShaderTerrain->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
		m_pShaderTerrain->Uniform("fog_color", fogColor);
	m_pShaderTerrain->Deactivate();

	m_pShaderWater->Activate();
		m_pShaderWater->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
		m_pShaderWater->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
		m_pShaderWater->Uniform("fog_color", fogColor);
	m_pShaderWater->Deactivate();


	m_fboWaterReflection.Create(FrameBufferObject::FBO_2D_COLOR, 512, 512);
	m_fboDepthMapFromLight[0].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);
	m_fboDepthMapFromLight[1].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);

	Camera::GetSingleton().setEye( ( m_pTerrain->getBoundingBox().min + (m_pTerrain->getBoundingBox().max * 0.5) ) );
	//Camera::GetSingleton().setAngle( 45.0f, 45.0f );

	// Player set up. TODO : Need to add multiple players and networking.
	Mark.m_szName = "Mark";
	Mark.m_pointer.MoveTo( ( m_pTerrain->getBoundingBox().min + (m_pTerrain->getBoundingBox().max * 0.5) ));
	res.LoadResource(ResourceManager::MESH, "pointy.3d");
	m_pGui = new GUI();
	m_pGui->init();
}
void SceneBase::Init()
{
	srand(time(NULL));
	// Black background
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	// Enable depth test
	glEnable(GL_DEPTH_TEST);
	// Accept fragment if it closer to the camera than the former one
	glDepthFunc(GL_LESS);

	glEnable(GL_CULL_FACE);

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	m_programID = LoadShaders("Shader//fog.vertexshader", "Shader//fog.fragmentshader");

	// Get a handle for our uniform
	m_parameters[U_MVP] = glGetUniformLocation(m_programID, "MVP");
	//m_parameters[U_MODEL] = glGetUniformLocation(m_programID, "M");
	//m_parameters[U_VIEW] = glGetUniformLocation(m_programID, "V");
	m_parameters[U_MODELVIEW] = glGetUniformLocation(m_programID, "MV");
	m_parameters[U_MODELVIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_programID, "MV_inverse_transpose");
	m_parameters[U_MATERIAL_AMBIENT] = glGetUniformLocation(m_programID, "material.kAmbient");
	m_parameters[U_MATERIAL_DIFFUSE] = glGetUniformLocation(m_programID, "material.kDiffuse");
	m_parameters[U_MATERIAL_SPECULAR] = glGetUniformLocation(m_programID, "material.kSpecular");
	m_parameters[U_MATERIAL_SHININESS] = glGetUniformLocation(m_programID, "material.kShininess");
	m_parameters[U_LIGHTENABLED] = glGetUniformLocation(m_programID, "lightEnabled");
	m_parameters[U_NUMLIGHTS] = glGetUniformLocation(m_programID, "numLights");
	m_parameters[U_LIGHT0_TYPE] = glGetUniformLocation(m_programID, "lights[0].type");
	m_parameters[U_LIGHT0_POSITION] = glGetUniformLocation(m_programID, "lights[0].position_cameraspace");
	m_parameters[U_LIGHT0_COLOR] = glGetUniformLocation(m_programID, "lights[0].color");
	m_parameters[U_LIGHT0_POWER] = glGetUniformLocation(m_programID, "lights[0].power");
	m_parameters[U_LIGHT0_KC] = glGetUniformLocation(m_programID, "lights[0].kC");
	m_parameters[U_LIGHT0_KL] = glGetUniformLocation(m_programID, "lights[0].kL");
	m_parameters[U_LIGHT0_KQ] = glGetUniformLocation(m_programID, "lights[0].kQ");
	m_parameters[U_LIGHT0_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[0].spotDirection");
	m_parameters[U_LIGHT0_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[0].cosCutoff");
	m_parameters[U_LIGHT0_COSINNER] = glGetUniformLocation(m_programID, "lights[0].cosInner");
	m_parameters[U_LIGHT0_EXPONENT] = glGetUniformLocation(m_programID, "lights[0].exponent");
	m_parameters[U_LIGHT1_TYPE] = glGetUniformLocation(m_programID, "lights[1].type");
	m_parameters[U_LIGHT1_POSITION] = glGetUniformLocation(m_programID, "lights[1].position_cameraspace");
	m_parameters[U_LIGHT1_COLOR] = glGetUniformLocation(m_programID, "lights[1].color");
	m_parameters[U_LIGHT1_POWER] = glGetUniformLocation(m_programID, "lights[1].power");
	m_parameters[U_LIGHT1_KC] = glGetUniformLocation(m_programID, "lights[1].kC");
	m_parameters[U_LIGHT1_KL] = glGetUniformLocation(m_programID, "lights[1].kL");
	m_parameters[U_LIGHT1_KQ] = glGetUniformLocation(m_programID, "lights[1].kQ");
	m_parameters[U_LIGHT1_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[1].spotDirection");
	m_parameters[U_LIGHT1_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[1].cosCutoff");
	m_parameters[U_LIGHT1_COSINNER] = glGetUniformLocation(m_programID, "lights[1].cosInner");
	m_parameters[U_LIGHT1_EXPONENT] = glGetUniformLocation(m_programID, "lights[1].exponent");
	// Get a handle for our "colorTexture" uniform
	m_parameters[U_COLOR_TEXTURE_ENABLED] = glGetUniformLocation(m_programID, "colorTextureEnabled[0]");
	m_parameters[U_COLOR_TEXTURE] = glGetUniformLocation(m_programID, "colorTexture[0]");
	m_parameters[U_COLOR_TEXTURE_ENABLED1] = glGetUniformLocation(m_programID, "colorTextureEnabled[1]");
	m_parameters[U_COLOR_TEXTURE1] = glGetUniformLocation(m_programID, "colorTexture[1]");
	// Get a handle for our "textColor" uniform
	m_parameters[U_TEXT_ENABLED] = glGetUniformLocation(m_programID, "textEnabled");
	m_parameters[U_TEXT_COLOR] = glGetUniformLocation(m_programID, "textColor");

	// Fog
	m_parameters[U_FOG_COLOR] = glGetUniformLocation(m_programID, "fog.color");
	m_parameters[U_FOG_START] = glGetUniformLocation(m_programID, "fog.start");
	m_parameters[U_FOG_END] = glGetUniformLocation(m_programID, "fog.end");
	m_parameters[U_FOG_DENSITY] = glGetUniformLocation(m_programID, "fog.density");
	m_parameters[U_FOG_TYPE] = glGetUniformLocation(m_programID, "fog.type");
	m_parameters[U_FOG_ENABLE] = glGetUniformLocation(m_programID, "fog.enabled");

	// Use our shader
	glUseProgram(m_programID);

	lights[0].type = Light::LIGHT_DIRECTIONAL;
	lights[0].position.Set(0, 20, 0);
	lights[0].color.Set(1, 1, 1);
	lights[0].power = 1;
	lights[0].kC = 1.f;
	lights[0].kL = 0.01f;
	lights[0].kQ = 0.001f;
	lights[0].cosCutoff = cos(Math::DegreeToRadian(45));
	lights[0].cosInner = cos(Math::DegreeToRadian(30));
	lights[0].exponent = 3.f;
	lights[0].spotDirection.Set(0.f, 1.f, 0.f);

	lights[1].type = Light::LIGHT_DIRECTIONAL;
	lights[1].position.Set(1, 1, 0);
	lights[1].color.Set(1, 1, 0.5f);
	lights[1].power = 0.4f;
	//lights[1].kC = 1.f;
	//lights[1].kL = 0.01f;
	//lights[1].kQ = 0.001f;
	//lights[1].cosCutoff = cos(Math::DegreeToRadian(45));
	//lights[1].cosInner = cos(Math::DegreeToRadian(30));
	//lights[1].exponent = 3.f;
	//lights[1].spotDirection.Set(0.f, 1.f, 0.f);

	glUniform1i(m_parameters[U_NUMLIGHTS], 1);
	glUniform1i(m_parameters[U_TEXT_ENABLED], 0);

	glUniform1i(m_parameters[U_LIGHT0_TYPE], lights[0].type);
	glUniform3fv(m_parameters[U_LIGHT0_COLOR], 1, &lights[0].color.r);
	glUniform1f(m_parameters[U_LIGHT0_POWER], lights[0].power);
	glUniform1f(m_parameters[U_LIGHT0_KC], lights[0].kC);
	glUniform1f(m_parameters[U_LIGHT0_KL], lights[0].kL);
	glUniform1f(m_parameters[U_LIGHT0_KQ], lights[0].kQ);
	glUniform1f(m_parameters[U_LIGHT0_COSCUTOFF], lights[0].cosCutoff);
	glUniform1f(m_parameters[U_LIGHT0_COSINNER], lights[0].cosInner);
	glUniform1f(m_parameters[U_LIGHT0_EXPONENT], lights[0].exponent);

	glUniform1i(m_parameters[U_LIGHT1_TYPE], lights[1].type);
	glUniform3fv(m_parameters[U_LIGHT1_COLOR], 1, &lights[1].color.r);
	glUniform1f(m_parameters[U_LIGHT1_POWER], lights[1].power);
	glUniform1f(m_parameters[U_LIGHT1_KC], lights[1].kC);
	glUniform1f(m_parameters[U_LIGHT1_KL], lights[1].kL);
	glUniform1f(m_parameters[U_LIGHT1_KQ], lights[1].kQ);
	glUniform1f(m_parameters[U_LIGHT1_COSCUTOFF], lights[1].cosCutoff);
	glUniform1f(m_parameters[U_LIGHT1_COSINNER], lights[1].cosInner);
	glUniform1f(m_parameters[U_LIGHT1_EXPONENT], lights[1].exponent);

	// Fog
	fogEnabled = false;
	Color fogColor(0.5f, 0.5f, 0.5f);
	glUniform3fv(m_parameters[U_FOG_COLOR], 1, &fogColor.r);
	glUniform1f(m_parameters[U_FOG_START], 10);
	glUniform1f(m_parameters[U_FOG_END], 1000);
	glUniform1f(m_parameters[U_FOG_DENSITY], 0.005f);
	glUniform1f(m_parameters[U_FOG_TYPE], 0);
	glUniform1f(m_parameters[U_FOG_ENABLE], fogEnabled);

	m_fov = 45.f;

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 1000 units
	Mtx44 perspective;
	perspective.SetToPerspective(m_fov, 4.0f / 3.0f, 0.1f, 10000.0f);
	//perspective.SetToOrtho(-80, 80, -60, 60, -1000, 1000);
	projectionStack.LoadMatrix(perspective);

	// TODO: Delete temp camera when actual camera is made
	//m_camera = new Camera3();
	//m_camera->Init(Vector3(0, 0, 10), Vector3::ZERO_VECTOR, Vector3(0, 1, 0));

	m_lightEnabled = false;
}
Exemple #8
0
void SceneShadow::Init()
{
	Application::setWindowSize(1184, 666);

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	m_gPassShaderID = LoadShaders( "Shader//GPass.vertexshader", "Shader//GPass.fragmentshader" );
	m_parameters[U_LIGHT_DEPTH_VIEW_GPASS] = glGetUniformLocation(m_gPassShaderID, "lV");
	m_parameters[U_LIGHT_DEPTH_PROJECTION_GPASS] = glGetUniformLocation(m_gPassShaderID, "lP");

	m_programID = LoadShaders( "Shader//Shadow.vertexshader", "Shader//Shadow.fragmentshader" );
	m_parameters[U_MODELVIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_programID, "MV_inverse_transpose");
	m_parameters[U_VIEW] = glGetUniformLocation(m_programID, "V");
	m_parameters[U_PROJECTION] = glGetUniformLocation(m_programID, "P");
	m_parameters[U_MATERIAL_AMBIENT] = glGetUniformLocation(m_programID, "material.kAmbient");
	m_parameters[U_MATERIAL_DIFFUSE] = glGetUniformLocation(m_programID, "material.kDiffuse");
	m_parameters[U_MATERIAL_SPECULAR] = glGetUniformLocation(m_programID, "material.kSpecular");
	m_parameters[U_MATERIAL_SHININESS] = glGetUniformLocation(m_programID, "material.kShininess");
	m_parameters[U_LIGHTENABLED] = glGetUniformLocation(m_programID, "lightEnabled");

	m_parameters[U_LIGHT0_POSITION] = glGetUniformLocation(m_programID, "lights[0].position_cameraspace");
	m_parameters[U_LIGHT0_COLOR] = glGetUniformLocation(m_programID, "lights[0].color");
	m_parameters[U_LIGHT0_POWER] = glGetUniformLocation(m_programID, "lights[0].power");
	m_parameters[U_LIGHT0_KC] = glGetUniformLocation(m_programID, "lights[0].kC");
	m_parameters[U_LIGHT0_KL] = glGetUniformLocation(m_programID, "lights[0].kL");
	m_parameters[U_LIGHT0_KQ] = glGetUniformLocation(m_programID, "lights[0].kQ");
	m_parameters[U_LIGHT0_TYPE] = glGetUniformLocation(m_programID, "lights[0].type");
	m_parameters[U_LIGHT0_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[0].spotDirection");
	m_parameters[U_LIGHT0_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[0].cosCutoff");
	m_parameters[U_LIGHT0_COSINNER] = glGetUniformLocation(m_programID, "lights[0].cosInner");
	m_parameters[U_LIGHT0_EXPONENT] = glGetUniformLocation(m_programID, "lights[0].exponent");
	
	m_parameters[U_LIGHT1_POSITION] = glGetUniformLocation(m_programID, "lights[1].position_cameraspace");
	m_parameters[U_LIGHT1_COLOR] = glGetUniformLocation(m_programID, "lights[1].color");
	m_parameters[U_LIGHT1_POWER] = glGetUniformLocation(m_programID, "lights[1].power");
	m_parameters[U_LIGHT1_KC] = glGetUniformLocation(m_programID, "lights[1].kC");
	m_parameters[U_LIGHT1_KL] = glGetUniformLocation(m_programID, "lights[1].kL");
	m_parameters[U_LIGHT1_KQ] = glGetUniformLocation(m_programID, "lights[1].kQ");
	m_parameters[U_LIGHT1_TYPE] = glGetUniformLocation(m_programID, "lights[1].type");
	m_parameters[U_LIGHT1_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[1].spotDirection");
	m_parameters[U_LIGHT1_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[1].cosCutoff");
	m_parameters[U_LIGHT1_COSINNER] = glGetUniformLocation(m_programID, "lights[1].cosInner");
	m_parameters[U_LIGHT1_EXPONENT] = glGetUniformLocation(m_programID, "lights[1].exponent");
	
	m_parameters[U_LIGHT2_POSITION] = glGetUniformLocation(m_programID, "lights[2].position_cameraspace");
	m_parameters[U_LIGHT2_COLOR] = glGetUniformLocation(m_programID, "lights[2].color");
	m_parameters[U_LIGHT2_POWER] = glGetUniformLocation(m_programID, "lights[2].power");
	m_parameters[U_LIGHT2_KC] = glGetUniformLocation(m_programID, "lights[2].kC");
	m_parameters[U_LIGHT2_KL] = glGetUniformLocation(m_programID, "lights[2].kL");
	m_parameters[U_LIGHT2_KQ] = glGetUniformLocation(m_programID, "lights[2].kQ");
	m_parameters[U_LIGHT2_TYPE] = glGetUniformLocation(m_programID, "lights[2].type");
	m_parameters[U_LIGHT2_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[2].spotDirection");
	m_parameters[U_LIGHT2_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[2].cosCutoff");
	m_parameters[U_LIGHT2_COSINNER] = glGetUniformLocation(m_programID, "lights[2].cosInner");
	m_parameters[U_LIGHT2_EXPONENT] = glGetUniformLocation(m_programID, "lights[2].exponent");

	m_parameters[U_LIGHT3_POSITION] = glGetUniformLocation(m_programID, "lights[3].position_cameraspace");
	m_parameters[U_LIGHT3_COLOR] = glGetUniformLocation(m_programID, "lights[3].color");
	m_parameters[U_LIGHT3_POWER] = glGetUniformLocation(m_programID, "lights[3].power");
	m_parameters[U_LIGHT3_KC] = glGetUniformLocation(m_programID, "lights[3].kC");
	m_parameters[U_LIGHT3_KL] = glGetUniformLocation(m_programID, "lights[3].kL");
	m_parameters[U_LIGHT3_KQ] = glGetUniformLocation(m_programID, "lights[3].kQ");
	m_parameters[U_LIGHT3_TYPE] = glGetUniformLocation(m_programID, "lights[3].type");
	m_parameters[U_LIGHT3_SPOTDIRECTION] = glGetUniformLocation(m_programID, "lights[3].spotDirection");
	m_parameters[U_LIGHT3_COSCUTOFF] = glGetUniformLocation(m_programID, "lights[3].cosCutoff");
	m_parameters[U_LIGHT3_COSINNER] = glGetUniformLocation(m_programID, "lights[3].cosInner");
	m_parameters[U_LIGHT3_EXPONENT] = glGetUniformLocation(m_programID, "lights[3].exponent");

	m_parameters[U_NUMLIGHTS] = glGetUniformLocation(m_programID, "numLights");

	m_parameters[U_ALPHA] = glGetUniformLocation(m_programID, "fragmentAlpha");
	m_parameters[U_TEXTURE_ROWS] = glGetUniformLocation(m_programID, "texRows");
	m_parameters[U_PARTICLE_TEXTURE] = glGetUniformLocation(m_programID, "particleTex");
	m_parameters[U_COLOR_TEXTURE_ENABLED] = glGetUniformLocation(m_programID, "colorTextureEnabled");
	m_parameters[U_COLOR_TEXTURE] = glGetUniformLocation(m_programID, "colorTexture");
	m_parameters[U_COLOR_SCALE_ENABLED] = glGetUniformLocation(m_programID, "colorScaleEnabled");
	m_parameters[U_COLOR_SCALE] = glGetUniformLocation(m_programID, "colorScale");
	m_parameters[U_TEXT_ENABLED] = glGetUniformLocation(m_programID, "textEnabled");
	m_parameters[U_TEXT_COLOR] = glGetUniformLocation(m_programID, "textColor");

	m_parameters[U_FOG_COLOR] = glGetUniformLocation(m_programID, "fogParam.color");
	m_parameters[U_FOG_START] = glGetUniformLocation(m_programID, "fogParam.start");
	m_parameters[U_FOG_END] = glGetUniformLocation(m_programID, "fogParam.end");
	m_parameters[U_FOG_DENSITY] = glGetUniformLocation(m_programID, "fogParam.density");
	m_parameters[U_FOG_TYPE] = glGetUniformLocation(m_programID, "fogParam.type");
	m_parameters[U_FOG_ENABLED] = glGetUniformLocation(m_programID, "fogParam.enabled");

	m_parameters[U_LIGHT_DEPTH_VIEW] = glGetUniformLocation(m_programID, "lightView");
	m_parameters[U_LIGHT_DEPTH_PROJECTION] = glGetUniformLocation(m_programID, "lightProj");
	m_parameters[U_SHADOW_MAP] = glGetUniformLocation(m_programID, "shadowMap");
		
	glUseProgram(m_programID);	

	glUniform1f(m_parameters[U_ALPHA], 1);
	glUniform1i(m_parameters[U_NUMLIGHTS], 1);
	glUniform1i(m_parameters[U_TEXT_ENABLED], 0);
	glUniform1i(m_parameters[U_PARTICLE_TEXTURE], 0);

	Color fogColor(86.f / 255.f, 117.f / 255.f, 130.f / 255.f);
	glUniform3fv(m_parameters[U_FOG_COLOR], 1, &fogColor.r);
	glUniform1f(m_parameters[U_FOG_START], 10);
	glUniform1f(m_parameters[U_FOG_END], 1000);
	glUniform1f(m_parameters[U_FOG_DENSITY], 0.04f);
	glUniform1i(m_parameters[U_FOG_TYPE], 2);
	glUniform1i(m_parameters[U_FOG_ENABLED], 1);

	lights[0].type = Light::LIGHT_DIRECTIONAL;
	lights[0].position.Set(0, 5, 5);
	lights[1].power = 0.f;
	lights[2].power = 0.f;
	lights[3].power = 0.f;

	UpdateLight();

	m_lightDepthFBO.Init(2048, 2048);
	InitMesh();
}