示例#1
0
void sc_lights_frmSun(SC_SCREEN* screen)
{
	if(screen.views.sun != NULL)
	{
		if(
		screen.settings.lights.sunPos.x == 0
		&& screen.settings.lights.sunPos.y == 0
		&& screen.settings.lights.sunPos.z == 0
		) //global sun
		{
			VECTOR distantSunPos;
			vec_for_angle(distantSunPos, sun_angle);
			vec_scale(distantSunPos, 9999999);
			screen.materials.sun.skill1 = floatv(distantSunPos.x);
			screen.materials.sun.skill2 = floatv(distantSunPos.y);
			screen.materials.sun.skill3 = floatv(distantSunPos.z);
		}
		else //local sun
		{
			screen.materials.sun.skill1 = floatv(screen.settings.lights.sunPos.x);
			screen.materials.sun.skill2 = floatv(screen.settings.lights.sunPos.y);
			screen.materials.sun.skill3 = floatv(screen.settings.lights.sunPos.z);
		}
		
		screen.materials.sun.skill4 = floatv(0); //local sun lightrange (not used)
		
		//sun color
		screen.materials.sun.skill5 = floatv(sun_color.red/255);
		screen.materials.sun.skill6 = floatv(sun_color.green/255);
		screen.materials.sun.skill7 = floatv(sun_color.blue/255);
		screen.materials.sun.skill8 = floatv(screen.views.main.clip_far);
		
		
		
		
		
		
		#ifndef SC_A7
			// PSSM main loop
			if(screen.settings.lights.sunPssmSplits>0 && screen.settings.lights.sunShadows == 1)
			{
				// update the views _after_ the camera was updated!
				//	proc_mode = PROC_LATE;
				
				// set up the split distances and the shadow view
				sc_lights_pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight, screen.settings.lights.sunShadowRange);
				//pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight);
				//pssm_viewcpy(screen.views.main, screen.views.sun);
				
				// set up the split view transformation matrices
				D3DXMATRIX matSplit[4];
				int i=0;
				for(i=0; i<screen.settings.lights.sunPssmSplits; i++) 
				{
					// look from the sun onto the scene			
					screen.views.sunShadowDepth[i]->pan = 180 + sun_angle.pan;
					screen.views.sunShadowDepth[i]->tilt = -sun_angle.tilt;
					vec_set(screen.views.sunShadowDepth[i]->x,sun_pos);
					
					// calculate the split view clipping borders and transformation matrix			
					view_to_split(screen.views.main, pssm_splitdist[i],pssm_splitdist[i+1], screen.views.sunShadowDepth[i], &matSplit[i]);
					LPD3DXEFFECT fx = screen.views.sunShadowDepth[i]->material->d3deffect;
					if(fx) fx->SetMatrix("matSplitViewProj",&matSplit[i]);
					
					// create a texture matrix from the split view proj matrix			
					D3DXMatrixMultiply(&matSplit[i],&matSplit[i],pssm_texscale(screen.settings.lights.sunShadowResolution));
					
					#ifdef DEBUG_PSSM		
						DEBUG_BMAP(screen.views.sunShadowDepth[i]->bmap,300 + i*220,0.2);
						var pssm_fps = 16/time_frame;
						DEBUG_VAR(pssm_fps,200);
						DEBUG_VAR(pssm_splitdist[i+1],220 + i*20);
					#endif
					//set depthmapshader maxDepth	
					screen.views.sunShadowDepth[i].material.skill4 = floatv(screen.views.sunShadowDepth[i].clip_far);
				}
				
				//put matrices to world space
				//mat_multiply(matSplit[0], matViewInv);
				// use a DX function to copy the 4 texture matrices to the shadow shader
				LPD3DXEFFECT fx = screen.views.sun->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				//same for shadowEdge acceleration
				LPD3DXEFFECT fx = screen.views.sunEdge->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				//and for the actual shadow view
				LPD3DXEFFECT fx = screen.views.sunShadow->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				screen.views.sun.material.skill4 = floatv(screen.views.sunShadowDepth[0].clip_far);
				
				#ifdef DEBUG_PSSM		
					DEBUG_BMAP(screen.views.sun->bmap,20,0.2);
				#endif
			}
		#endif
		
		
	}
}