Device.SetRenderTarget(0,null);
Texture2D tex = RT.GetTexture();
Eff.SetValue("...",tex);
Device.SetRenderTarget(0,RT);
.....
CComPtr m_Texture; // Member variable
...
// لاحقاً
...
D3DDevice->CreateTexture(256,256,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&m_Texture,0);
clear(LightBuffer)
for(light l in lights)
{
sceneLighted = ApplyLight(l)
LightBuffer += sceneLighted
}
Game.SetRenderTarget(0, RT4);
Game.SetRenderTarget(1, RT5);
eff.SetTexture("RT4", rt4);//set render target to use it again (add other light to it)
eff.SetTexture("RT5", rt5);
eff.Begin();
eff.BeginPass(3);//apply light to scene
//draw...
//inside shader :
//output1 = DiffuseLight + RT4 //(additive blend)
//output2 = SpecularLight + RT5 //(additive blend)
eff.EndPass();
eff.End();
public void SetRenderTarget(int id, Texture s)
{
if (s == null && id == 0)
{
var bb = GraphicsDevice.GetBackBuffer(0, 0);
GraphicsDevice.SetRenderTarget(0, bb);
bb.Dispose();
}
else
{
Surface ss;
if (s != null)
ss = s.GetSurfaceLevel(0);
else ss = null;
GraphicsDevice.SetRenderTarget(id, ss);
if (ss != null)
ss.Dispose();
}
}