Yeah well it's that time of the year again: Me asking stupid questions laugh

Before i start with the questioning, little info on what i'm doing:
I created a deferred renderer with "full" BRDF support. Local lighting is done by rendering light volumes, directional lighting is applied in a fullscreen quad.
To speed up performance i re-use the zbuffer from the gBuffer generation phase for my light volumes.
Also, to be able to efficiently do the BRDF stuff i added support for volume textures. I pass a volume texture which contains brdf data to the light shader. By using a material ID from the gBuffer i then access the volume texture and pick the correct lighting model.

I have a few questions/problems now:

1.) ENABLE_VIEW vs all other material events:
To keep the ZBuffer from the gBuffer stage i use PROCESS_SCREEN/NO_SKY for my light view. Because of that i have to manually clear the view each frame. I do that in a view event like so:
Code:
void testMat2Event()
{
	if(sc_screen_default == NULL) return; //check if shade-c view is set
	
	switch(render_view)
	{
		case sc_screen_default.views.deferredLighting:
			
				IDirect3DDevice9* pd3dDevice = (IDirect3DDevice9*)(pd3ddev);
				pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 0.0, 0);
				//pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 0.0, 0);
				break;
			

		default:
			break;
	}
	
	
}

MATERIAL* testMat2 =
{
	flags = ENABLE_VIEW;
	event = testMat2Event;
	effect = "
		technique t1
		{
			pass p0
			{
			}
		}
	";
}


This works very well and i get a nice performance boost out of it. However when using ENABLE_VIEW, my gBuffer gets fucked up. Specifically the material skills for SOME (NOT ALL!) Entities aren't set anymore (like max depth, material ID, etc). It doesn't matter whats inside testMat2Event: As soon as i apply an (empty) event to testMat2, all my materials are buggy. It's always the same entities that are buggy, some only at specific camera angles/position. If i add some more entities to the scene, the buggy entities from before are mostly not buggy anymore but others are instead.
I know from my past experience with A6 and A7 that ENABLE_VIEW always caused me nothing but trouble and i always tried to not use it at all.
However in order to be able to use pd3dDevice->Clear(..) i have to use it.
Question is, what has to be fixed to get this right? Or are there alternative ways to clear the screen?
I would really like to understand how ENABLE_VIEW works though as after all these years of using Acknex i still have no idea what really happens when using ENABLE_VIEW and i might have to use it some more in the future to set things up for my deferred renderer.

2.) Using render_d3dxeffect AFTER assigning a different material in a view material event
This doesn't work, the volume texture isn't assigned to the shader:
Code:
var sc_deferredLighting_mtlRenderEvent()
{	
	if(my)
	{
		if(my.alpha < 100)
		{
			mtl = someOtherMaterial;
			
			LPD3DXEFFECT pEffect = (LPD3DXEFFECT)render_d3dxeffect;
			if(pEffect != NULL)
			{
				pEffect->SetTexture("texBRDFLut", sc_deferredLighting_texBRDFData); //assign volumetric brdf data
				pEffect->SetFloat("someVar", someVar); //assign some var to the shader
			}
		}
	}
	
	return 0;
}



This does work:
Code:
var sc_deferredLighting_mtlRenderEvent()
{	
	if(my)
	{
		if(my.alpha < 100)
		{
			
			
			LPD3DXEFFECT pEffect = (LPD3DXEFFECT)render_d3dxeffect;
			if(pEffect != NULL)
			{
				pEffect->SetTexture("texBRDFLut", sc_deferredLighting_texBRDFData); //assign volumetric brdf data
				pEffect->SetFloat("someVar", someVar); //assign some var to the shader
			}
		}
	}
	
	return 0;
}


How can i assign the texture/var to the shader AFTER changing the material?


3.) Re-Using RenderTargets
I've red numerous time now that it is common practice to re-use rendertargets between effects to lower video ram overhead.

E.g.: User has a general rendertarget with (screen_size.x/2, screen_size.y/2) resolution. The idea is to use the same rendertarget for blurring bloom and then for bluring dof.
There would be only temporal data in the rendertarget. The actual compositing wis be done in other rendertargets .
The way i would to it is again in a view event like so:
Code:
BMAP* genericRT;

.
.
.

var mtlChangeRTsEvent()
{
	if(render_view == bloomBlur)
	{
		bloomBlur.bmap = genericRT;
	}
	if(render_view == dofBlur)
	{
		dofBlur.bmap = genericRT;
	}
	
	return 0;
}

MATERIAL* mtlChangeRTs =
{
	flags = ENABLE_VIEW;
	event = mtlChangeRTsEvent;
	effect = "
		technique t1
		{
			pass p0
			{
			}
		}
	";
}


I haven't tested this yet (due to my problems with ENABLE_VIEW) but this is how i would do it. Is this the right way?



Ok that's all the questions i can think of now.
Really looking forward to the answers laugh


Shade-C EVO Lite-C Shader Framework