C++ & DirectX Plugin API problem

Started by Calin Leafshade, Sat 07/08/2010 00:57:45

Previous topic - Next topic

Pumaman

Quote from: Calin Leafshade on Sun 08/08/2010 06:53:46
The plugin API doesn't expose the texture that the engine is drawing to (although I imagine it draws straight to the backbuffer) So I'm finding it difficult to redraw whatever is on the screen.

Correct, it does not. But it sounds like what you really want is to hook into the AGS rendering process where it selects which pixel shader to use for each sprite, and replace it with your own.

If that's the case, is that something you would use?

Calin Leafshade

That is not really useful for the effects I am trying to achieve.

Certain pixel shaders (specifically things like blur and bloom and  other post-process fx) need to be applied to the whole screen after rendering. Applying these shaders to each individual sprite as it is drawn will not work since they are an effect on the world rather than the elements within the world, if that makes sense.

Pumaman

Well, the AGS rendering loop basically looks like:

d3ddevice9->BeginScene();

For each sprite:
  direct3ddevice->SetPixelShader(...);
  direct3ddevice->SetTransform(...);
  direct3ddevice->SetTexture(...);
  direct3ddevice->DrawPrimitive(...);

direct3ddevice->EndScene();
direct3ddevice->Present(...);

The AGSE_PREGUIDRAW event is drawn in the middle of the rendering loop after all the non-GUI stuff has been drawn. So I'm not sure if it's possible at that point to get what has already been drawn and re-draw it, I can't remember enough about how D3D's back buffer works. In AGS the D3D backbuffer is not lockable so it can't be directly accessed.

Calin Leafshade

#23
well just set the render target to something other than the back buffer.

create a texture
get the surface of that texture
set the current render target to that surface
draw the sprites to the surface

then allow the api a handle to that texture.
I can manipulate that texture in whatever way i like

draw the guis to the surface
set the render target to the back buffer again
draw the fully rendered texture to the back buffer.
done

This is generally how any engine with post processing shaders does it since you need the final result as a texture in order to perform them.

Does this sound possible?


Calin Leafshade

#25
yup if the scaling was done to the entire texture afterwards it would make all the scaling look much prettier.

Edit: obviously also scaling the characters before they are drawn. Not *all* the scaling can be done at the end. but this means the scalings is done on a 1:1 pixel basis with the background

Calin Leafshade

sorry for the double post but:

Does the AGS API have a feature whereby I can create DX textures of existing sprites in the sprite cache?

That way it would fairly trivial to rebuild the scene from scratch just by getting the current sprites of all the objects and drawing them in the right place.

It's a ballache and a fairly messy work around since AGS does all that anyway but at least it would work.

Pumaman

Quote from: Calin Leafshade on Tue 10/08/2010 18:05:00
well just set the render target to something other than the back buffer.
QuoteIt would nicely tie in with this:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=40132.msg533721#msg533721

Thanks, yep that fits together nicely. So if that was done, your request would become quite easily possible.

QuoteDoes the AGS API have a feature whereby I can create DX textures of existing sprites in the sprite cache?

There are no D3D-specific AGS API functions at the moment.

Calin Leafshade

Quote from: Pumaman on Sun 15/08/2010 23:37:10
Thanks, yep that fits together nicely. So if that was done, your request would become quite easily possible.

Yup the code is already done, just need the access to that texture and I can release full (post process) shader support for AGS :D:D:D


Quote from: Pumaman on Sun 15/08/2010 23:37:10

There are no D3D-specific AGS API functions at the moment.


I thought that might be the case, thanks for replying though.

subspark

QuoteYup the code is already done, just need the access to that texture and I can release full (post process) shader support for AGS :D:D
HOLY Shinoouwza!!! :o This could mean the end of our game resolution woes AND the potential for working new arbitrary aspect ratios in!

Nice going Calin! We salute you. 8)

Sparky.

Calin Leafshade

Hmm my particular project would have no effect on the resolution of the engine. It just redraws the screen with a shader effect applied.

I also wouldnt recommend using an unsupported plugin in a commercial project.

subspark

Fair enough of course however I was under the belief that CJ would implement this particular plugin into AGS as 'out of the box'. Don't ask me why :P.

Nice work though. I hope with this plugin in combination with better resolution support, we wont actually need to change the 'monitor' resolution when playing a game anymore. We just stretch the graphics across two tris.

When we're talking about the resolution of the texture (the game resolution) I was excited because this may mean that low res games under DirectX 9 can be scaled up directly/filtered/not filtered and still maintain the exact relative pixel grid.

So I still salute your efforts! ;D

Sparky.

Calin Leafshade

#32
I've just had a thought. (that happens to me sometimes)

CJ, Where abouts in the render cycle does the engine set the render target?

Could I create a texture and set the render target to that texture myself? Or would the engine just set it back to the backbuffer before it renders stuff?

If I could set the render target myself then I could get the texture very easily since i was the one who created it.

EDIT: Yup, that works.

subspark

#33
QuoteI've just had a thought. (that happens to me sometimes)
That happens to you ALOT Cal, don't be modest! ;)

Sparkz

EDIT: I had an idea too! Make a Calin Leafshade plugin so that everybody can have their own personal wonderbrain. ^^

Calin Leafshade

Ha, wonderbrain is a little much.

Incidentally this plugin works now.

Now I just need to finish some shaders for a demo.

Dualnames

Quote from: Calin Leafshade on Thu 02/09/2010 16:41:56
Ha, wonderbrain is a little much.

Incidentally this plugin works now.

Now I just need to finish some shaders for a demo.

Are we referring the BLOOM? Cause if we are, I officially propose to marry you! ;)
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Calin Leafshade

More generally a Post Processing shader allows you you skip through each pixel and apply some kind of mathematical formula to it.

Here are a couple of videos showing what they do.

http://www.youtube.com/watch?v=d4S__Nyi3t0
http://www.youtube.com/watch?v=6tp9Simhq2w
http://www.youtube.com/watch?v=e2gFynRah7g

Basically anything that affects the screen as a whole.

SMF spam blocked by CleanTalk