Sign in to follow this  
Shuryou

Transitions

Recommended Posts

Hello. For my game I need to have transitions in between scenes. Currently I only have crossfades, but that is pretty boring. I looked into some other programs to see how they did transitions. I like RPG Maker's way of doing transitions which is using a 256 colour image, each frame then goes through values 0 - 255 and if a pixel of the transition image is that colour then a pixel from the new scene is drawn in that position. Can anyone please explain how I can do this with DirectX, preferably with C#, but I'll be ok with C++ too.

Share this post


Link to post
Share on other sites
One way

Render your scene to a render target, then set the screen aligned quads' texture to the render target. Change the diffuse color, using time. Then something like this in the pixel shader

struct PS_INPUT
{
float4 Diffuse: COLOR0;
float2 Txr0: TEXCOORD0;
};


float4 ps_main(PS_INPUT In) : COLOR0
{
float4 o = In.Diffuse;
float4 d = tex2D(texture,In.Txr0);
if(o < d)
o = d;
return o;
}




Share this post


Link to post
Share on other sites
Thank you for your help, but I am confused on how I am supposed to do this. First off, here is my pixel shader:


sampler2D Trans;

struct PS_INPUT
{
float Diffuse: COLOR0;
float2 Txr0: TEXCOORD0;
};


float4 Diffuse(PS_INPUT In) : COLOR0
{
float o;
float4 d;

o = In.Diffuse;
d = tex2D(Trans, In.Txr0);

if( o < (d.r+d.b+d.g)/3.0f )
o = d;

return o;
}

technique DiffuseTransition
{
pass P0
{
VertexShader = NULL;
PixelShader = compile ps_2_0 Diffuse();
}
}



And this is my drawing code:


device.Clear(ClearFlags.Target, EngineState.BackgroundColour, 1.0f, 0);
device.BeginScene();

if (trans_running)
{
device.SetRenderTarget(0, tex_render_target.GetSurfaceLevel(0));
secondary.Draw();

device.SetRenderTarget(1, null);

scene_trans.SetValue("Trans", tex_render_target);

trans_sprite.Begin(SpriteFlags.None);
int passes = scene_trans.Begin(EffectFlags.None);

for (int i = 0; i < passes; i++)
{
scene_trans.BeginPass(i);
trans_sprite.Draw(TextureManager.GetTexture(trans_tex), null, Vector3.Empty, Vector3.Empty, GDI.Color.White);
scene_trans.EndPass();
}

scene_trans.End();
trans_sprite.End();

trans_step++;

if (trans_step >= 255)
{
trans_running = false;
TextureManager.FreeTexture(trans_tex);
secondary.Close();
}
}
else
{
primary.Draw();
}

device.EndScene();
device.Present();



What am I doing wrong?

Thanks in advance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this