예제 #1
0
void sc_forward_destroy(SC_SCREEN* screen)
{
	if(screen.views.main != NULL){
		if(is(screen.views.main,NOSHADOW))
		{
			set(screen.views.main, SHOW);
			if(is(screen.views.main, PROCESS_SCREEN)) reset(screen.views.main, PROCESS_SCREEN);
			if(is(screen.views.main, PROCESS_TARGET)) reset(screen.views.main, PROCESS_TARGET);
			reset(screen.views.main, NOSKY);
			reset(screen.views.main, CHILD);
			reset(screen.views.main,NOSHADOW);
			
			if(screen.views.main.bmap != NULL) bmap_purge(screen.views.main.bmap);
			screen.views.main.bmap = NULL;
			
			if(screen.views.preForward.bmap != NULL) bmap_purge(screen.views.preForward.bmap);
			screen.views.preForward.bmap = NULL;
			
			VIEW* view_last;
			view_last = screen.views.gBuffer;
			while(view_last.stage != screen.views.main && view_last.stage != NULL)
			{
				view_last = view_last.stage;
			}
				
			if(screen.views.main.stage != NULL) view_last.stage = screen.views.main.stage;
			else view_last.stage = NULL;
			screen.views.main.stage = NULL;
		}
	}
}
예제 #2
0
void sc_refract_destroy(SC_SCREEN* screen)
{
	if(screen.views.refract != NULL){
		if(is(screen.views.refract,NOSHADOW))
		{
			reset(screen.views.refract,NOSHADOW);
			if(screen.views.refract.bmap) bmap_purge(screen.views.refract.bmap);
			screen.views.refract.bmap = NULL;
			
			if(screen.views.preRefract.bmap) bmap_purge(screen.views.preRefract.bmap);
			screen.views.preRefract.bmap = NULL;
			
			
			//find view before
			VIEW* view_last;
			view_last = screen.views.gBuffer;
			while(view_last.stage != screen.views.refract && view_last.stage != NULL)
			{
				view_last = view_last.stage;
			}
			//remove view from view chain
			if(screen.views.refract.stage != NULL)	view_last.stage = screen.views.refract.stage;
			else view_last.stage = NULL;	
			screen.views.refract.stage = NULL;
	
		}
	}
}
예제 #3
0
void sc_lights_initSun(SC_SCREEN* screen)
{
	if(sun_color.red == 0 && sun_color.green == 0 && sun_color.blue == 0) return;
	
	//create materials
	screen.materials.sun = mtl_create();
	if(screen.settings.lights.sunShadows == 0) effect_load(screen.materials.sun, sc_lights_sMaterialSun);
	else effect_load(screen.materials.sun, sc_lights_sMaterialSunShadow);
	screen.materials.sun.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH]; //point to gBuffer: normals and depth
	//screen.materials.sun.skin2 = ObjData.light.projMap; //projection map
	//screen.materials.sun.skin3 = ObjData.light.shadowMap; //shadowmap
	screen.materials.sun.skin4 = screen.renderTargets.gBuffer[SC_GBUFFER_MATERIAL_DATA]; //point to gBuffer: brdf data
	screen.materials.sun.SC_SKILL = screen;
	set(screen.materials.sun, ENABLE_VIEW);
	screen.materials.sun.event = sc_lights_MaterialEventSun;
	
	//setup views
	screen.views.sun = view_create(-997);
	set(screen.views.sun, PROCESS_TARGET);
	set(screen.views.sun, UNTOUCHABLE);
	set(screen.views.sun, NOSHADOW);
	reset(screen.views.sun, AUDIBLE);
	set(screen.views.sun, NOPARTICLE);
	set(screen.views.sun, NOSKY);
	set(screen.views.sun, CHILD);
	set(screen.views.sun, NOFLAG1);
	screen.views.sun.size_x = screen.views.main.size_x;
	screen.views.sun.size_y = screen.views.main.size_y;
	screen.views.sun.material = screen.materials.sun;
	screen.views.sun.bmap = screen.renderTargets.full0;
	
	
	#ifndef SC_A7
		//PSSM SHADOWS
		if(screen.settings.lights.sunShadows == 1)
		{
			sun_angle.roll = 1.1*maxv(vec_length(level_ent->max_x),vec_length(level_ent->min_x));
			//screen.renderTargets.sunShadowDepth = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 12222);
			//screen.materials.sun.skin3 = screen.renderTargets.sunShadowDepth;
			
			int i = 0;
			for(i=0; i<screen.settings.lights.sunPssmSplits; i++)
			{	
				
				screen.views.sunShadowDepth[i] = view_create(-800);
				
				#ifndef SC_A7
					screen.views.sunShadowDepth[i].bg = pixel_for_vec(COLOR_WHITE,0,8888);
				#endif
				screen.views.sunShadowDepth[i].lod = shadow_lod;
				
				/*
				//set shadowview flags
				set(screen.views.sunShadowDepth[i], SHOW);
				reset(screen.views.sunShadowDepth[i], AUDIBLE);
				set(screen.views.sunShadowDepth[i], UNTOUCHABLE);
				set(screen.views.sunShadowDepth[i], NOSHADOW);
				set(screen.views.sunShadowDepth[i], SHADOW);
				set(screen.views.sunShadowDepth[i], NOPARTICLE);
				set(screen.views.sunShadowDepth[i], ISOMETRIC);
				//set(screen.views.sunShadowDepth[i], CULL_CW);
				#ifdef SC_USE_NOFLAG1
					set(screen.views.sunShadowDepth[i], NOFLAG1);
				#endif
				*/
				screen.views.sunShadowDepth[i]->flags |= SHOW|UNTOUCHABLE|NOSHADOW|NOPARTICLE|NOLOD|NOSKY|ISOMETRIC|SHADOW|NOFLAG1;
				
				
				//create rendertarget
				screen.renderTargets.sunShadowDepth[i] = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 14);
				
				/*
				//BLUR SHADOWMAP (ESM SHADOWS ONLY)
				if(i < screen.settings.lights.sunPssmBlurSplits)
				{
					//assign rendertarget
					//screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
					screen.views.sunShadowDepth[i].bmap = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 14);
					
					//blur light depthmap
					VIEW* blurView = view_create(-799);
					blurView.size_x = screen.settings.lights.sunShadowResolution;
					blurView.size_y = screen.settings.lights.sunShadowResolution;
					set(blurView, CHILD);
					set(blurView, PROCESS_TARGET);
					screen.views.sunShadowDepth[i].stage = blurView;
					blurView.bmap = screen.renderTargets.sunShadowDepth[i];
					blurView.material = mtl_create();
					effect_load(blurView.material, sc_lights_sMaterialShadowmapBlur);
					//blurView.material.skill1 = floatv((float)(2.25-i)/(float)screen.settings.lights.sunShadowResolution);
					if(i==0) blurView.material.skill1 = floatv((float)(1.5)/(float)screen.settings.lights.sunShadowResolution);
					if(i==1) blurView.material.skill1 = floatv((float)(0.75)/(float)screen.settings.lights.sunShadowResolution);
					if(i==2) blurView.material.skill1 = floatv((float)(0.25)/(float)screen.settings.lights.sunShadowResolution);
					if(i==3) blurView.material.skill1 = floatv((float)(0.125)/(float)screen.settings.lights.sunShadowResolution);
					//
				}
				else
				{
					screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
				}
				*/
				screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
				
				//create material
				screen.views.sunShadowDepth[i].material = mtl_create();
				
				switch(i){
					case 0:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit1);
					break;
					case 1:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit2);
					break;
					case 2:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit3);
					break;
					case 3:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit4);
					break;
					default:
					break;
				}
				
				//pass number of splits to sun shader
				screen.materials.sun.skill13 = floatv(screen.settings.lights.sunPssmSplits);
				
			}
			
			if(sc_materials_zbuffer!=NULL){ bmap_purge(sc_materials_zbuffer); ptr_remove(sc_materials_zbuffer); sc_materials_zbuffer=NULL; }
			sc_materials_zbuffer=bmap_createblack(maxv(screen_size.x,screen.settings.lights.sunShadowResolution),maxv(screen_size.y,screen.settings.lights.sunShadowResolution),32);
			bmap_zbuffer(sc_materials_zbuffer);
			
			
			
			
			
			
			//add shadow edge masking + expanding to accelerate pcf shadows
			//setup views
			screen.views.sunEdge = view_create(-997);
			set(screen.views.sunEdge, PROCESS_TARGET);
			set(screen.views.sunEdge, UNTOUCHABLE);
			set(screen.views.sunEdge, NOSHADOW);
			reset(screen.views.sunEdge, AUDIBLE);
			set(screen.views.sunEdge, NOPARTICLE);
			set(screen.views.sunEdge, NOSKY);
			set(screen.views.sunEdge, CHILD|NOFLAG1);
			screen.views.sunEdge.size_x = screen.views.main.size_x/4;
			screen.views.sunEdge.size_y = screen.views.main.size_y/4;
			screen.views.sunEdge.bmap = screen.renderTargets.quarter0;//bmap_createblack(screen.views.main.size_x/4, screen.views.main.size_y/4, 32);//screen.renderTargets.quarter0;
			screen.views.sunEdge.material = mtl_create();
			effect_load(screen.views.sunEdge.material, sc_lights_sMaterialSunShadowEdge);
			screen.views.sunEdge.material.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH];
			
			screen.views.sunEdge.material.skill8 = floatv(screen.views.main.clip_far);
			screen.views.sunEdge.material.skill13 = floatv(screen.settings.lights.sunPssmSplits);
			LPD3DXEFFECT fx = screen.views.sunEdge->material->d3deffect;
			if(fx) {
				fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				fx->SetFloat("shadowBias", (screen.settings.lights.sunShadowBias) );
			}
			set(screen.views.sunEdge.material, ENABLE_VIEW);
			screen.views.sunEdge.material.event = sc_lights_MaterialEventSun;
			
			
			//expander
			screen.views.sunExpand = view_create(-997);
			set(screen.views.sunExpand, PROCESS_TARGET);
			set(screen.views.sunExpand, UNTOUCHABLE);
			set(screen.views.sunExpand, NOSHADOW);
			reset(screen.views.sunExpand, AUDIBLE);
			set(screen.views.sunExpand, NOPARTICLE);
			set(screen.views.sunExpand, NOSKY);
			set(screen.views.sunExpand, CHILD|NOFLAG1);
			screen.views.sunExpand.size_x = screen.views.main.size_x/8;
			screen.views.sunExpand.size_y = screen.views.main.size_y/8;
			screen.views.sunExpand.bmap = screen.renderTargets.eighth0;//bmap_createblack(screen.views.main.size_x/8, screen.views.main.size_y/8, 32);//screen.renderTargets.quarter0;
			screen.views.sunExpand.material = mtl_create();
			effect_load(screen.views.sunExpand.material, sc_lights_sMaterialSunShadowExpand);
			screen.views.sunExpand.material.skin1 = screen.renderTargets.quarter0;
			set(screen.views.sunExpand.material, ENABLE_VIEW);
			screen.views.sunExpand.material.event = sc_lights_MaterialEventSun;
			
			//shadow
			screen.views.sunShadow = view_create(-997);
			set(screen.views.sunShadow, PROCESS_TARGET);
			set(screen.views.sunShadow, UNTOUCHABLE);
			set(screen.views.sunShadow, NOSHADOW);
			reset(screen.views.sunShadow, AUDIBLE);
			set(screen.views.sunShadow, NOPARTICLE);
			set(screen.views.sunShadow, NOSKY);
			set(screen.views.sunShadow, CHILD|NOFLAG1);
			screen.views.sunShadow.size_x = screen.views.main.size_x;
			screen.views.sunShadow.size_y = screen.views.main.size_y;
			screen.views.sunShadow.bmap = screen.renderTargets.full1;//bmap_createblack(screen.views.main.size_x/4, screen.views.main.size_y/4, 32);//screen.renderTargets.quarter0;
			screen.views.sunShadow.material = mtl_create();
			effect_load(screen.views.sunShadow.material, sc_lights_sMaterialSunShadowCreate);
			screen.views.sunShadow.material.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH];
			screen.views.sunShadow.material.skin2 = screen.renderTargets.eighth0;
			
			screen.views.sunShadow.material.skill4 = floatv(screen.views.sunShadowDepth[0].clip_far);
			screen.views.sunShadow.material.skill8 = floatv(screen.views.main.clip_far);
			screen.views.sunShadow.material.skill13 = floatv(screen.settings.lights.sunPssmSplits);
			LPD3DXEFFECT fx = screen.views.sunShadow->material->d3deffect;
			if(fx) {
				fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				fx->SetFloat("shadowBias", (screen.settings.lights.sunShadowBias) );
			}
			set(screen.views.sunShadow.material, ENABLE_VIEW);
			screen.views.sunShadow.material.event = sc_lights_MaterialEventSun;
			
			//set stages
			screen.views.sunEdge.stage = screen.views.sunExpand;
			screen.views.sunExpand.stage = screen.views.sunShadow;	
			screen.views.sunShadow.stage = screen.views.sun;
			
		}
	#endif
	//------------
	
	
	
	
	//apply sun to camera
	VIEW* view_last;
	view_last = screen.views.gBuffer;
	while(view_last.stage != NULL)
	{
		view_last = view_last.stage;
	}
	
	#ifndef SC_A7 //PSSM SHADOWS are supported
		if(screen.settings.lights.sunShadows == 1)
		{
			view_last.stage = screen.views.sunEdge;
		}
		else
		{
			view_last.stage = screen.views.sun;
		}
		#else
		view_last.stage = screen.views.sun;
	#endif
	
}