The Stage3DPunk Thread!


(Red Ligot) #22

Wow this is incredible! Where the performance used to lag when it came to rotation or alpha, I’m suddenly able to run at 60 fps.


(Ultima2876) #23

IMPORTANT UPDATE (23RD MAY 2014): Please be aware that Stage3DPunk is a separate library to FlashPunk. The FlashPunk community forums are for support with FlashPunk ONLY - if you are using Stage3DPunk in your project, please ONLY ask for help within this topic or by contacting KickBack Games through their site or myself by PM. If you do have issues that seem like they may be FlashPunk issues, try dropping FlashPunk back into your project before asking for help from the FlashPunk community!

Please please make sure you stick to this guys. It was never my intention to cause confusion within the community and reporting FlashPunk issues when you’re using Stage3DPunk just makes life difficult for the helpful people here :smile:


(azrafe7) #24

Out of curiosity I’ve looked into the Lit library to see what would get in the way of using it with Stage3DPunk: would it be possible to make it just work?

Well… the short answer is: no, it’s not!

The main problem is that Stage3D itself doesn’t support BlendMode.SUBTRACT, which is essential to get that lighting effect. Playing more with the Lit code I managed to get something looking almost like it… but not quite.

Stage3DPunk-LitTest.swf (847.4 KB) - be sure to run it on desktop and that the console log reports “Stage3D mode”

I’ve resorted to use BlendMode.MULTIPLY and took advantage of setStage3DOverlay() to get that. The drawbacks are that the performance might not be on par and that - being an overlay - it applies to all things drawn below it (f.e. see the text in the upper left corner).

I’ve not uploaded the code (messy and requires some little tweaks in Stage3DPunk), but I’d be glad to supply it if you need it. :wink:

@Ultima2876: a few questions/annotations

  • is there a way to get a capture of the screen in Stage3D mode (in BitmapData or Sprite form)?
  • I’d guess the swc is compiled in debug mode, is there some way to also get a release ver (or is it handled internally in some way - compiler flags, etc.)?
  • while in Stage3D mode if you call image.render(someBitmapData, ...) you’ll not get color transforms and alpha (will take a different codepath that skips them)

(Ultima2876) #25

Pretty awesome :smile:

Questions:

  • You can get this with FP.getStage3DBitmapData, but be aware that it’s slow. Here’s the function documentation:

This replaces FP.buffer in Stage3D mode. It is SLOW and requires that Engine.enableRenderTargets is true, and will render the scene into a bitmap data up to the layer you specify (leave layer blank if you want to draw everything). Note that certain things are ignored, like screen scaling and rotation; you’ll have to apply these to the bitmap yourself

This is not really usable on mobile unless you’re just getting a single buffer capture e.g for a menu background. On desktop it should be okay as it essentially does a single-frame software render using regular FlashPunk mode, but if you do it once per frame or more then it’ll defeat the point of using Stage3D mode pretty much.

  • That’s a good question. I use a command line to compile the swc and I’m unaware of any options to compile in release mode; I’ll have a look into this (or if anyone knows how it can be done using the Air ADT packager, let me know). Currently it’s compiled in whatever mode the default is for swc.

  • Thanks for the bug report, I’ll get this fixed for the next version. Is it worth putting a github up for the public part of the code so that these kinds of fixes could be added by the community?

For BlendMode.SUBTRACT, I can actually add that if I can figure out what blending factors to use. Currently I have:

switch(_blendMode)
{
	case BlendMode.ADD: _context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ONE); break;

	case BlendMode.MULTIPLY: _context3D.setBlendFactors(Context3DBlendFactor.DESTINATION_COLOR, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA); break;

	case BlendMode.SCREEN: _context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ONE_MINUS_SOURCE_COLOR); break;

	case "none": _context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ZERO); break;

	default: _context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);
}

If it can’t be done with regular blending factors as above, there is also the option to write a specific AGAL shader for it.


(azrafe7) #26

Here’s with the list, hehe:

  1. FP.getStage3DBitmapData() eh? Nice… I missed that.

(Ultima2876) #27

:smile:

  • Compile line for building the swc: %FLEX_SDK%/bin/compc -framework=%FLEX_SDK%/frameworks -target-player=11.9 -compiler.debug=false -source-path=src -library-path=lib/dggameapi_as3.swc,lib/KBGamesAPI.swc -include-sources=src -output=tmp/tmp.swc – looks like it has debug set to false indeed! I completely forgot about this.

  • Cool, I’ll do that when I have some time then!

  • Thanks for the resource. I’ve added this to the todo and will look into it!

  • I don’t have one to hand but I can whip something up and put it in a gist this weekend (possibly this evening). Will post here when I can!

  • Yup. I’ll look into this.


(josepho) #28

I think you should also add a licensing fee that allows the devs to have all the publishing rights, I didnt test this yet, but I would definetly pay a nice amount for having what this promisses will full rights

For example: 300$ for having all the licensing rights and an updated lib and customer support will be perfect


(Ultima2876) #29

We tend to prefer publishing games directly as it gives us more impetus to help get great games out there (and we love to see what the engine is being used for!). We do have an option to do that though, we just don’t advertise it very much due to our preference of publishing games directly.


(josepho) #30


(Ultima2876) #31

Haha, I sent you a PM :smile: Give the engine a go!


(Mike Evmm) #32

That’s some really neat stuff. I’d like to use shaders with S3P too, but taking into account my little experience (both generally and with Stage3D) I don’t think I can pull it off. Regarding setPostProcessShader(), have you read this?


(azrafe7) #33

Yeah, I’ve already read that article, thanks. My question was more specific on how to do it with Stage3DPunk exposed API, how to work with shader costants, etc…

So the little example in the next posts might help clarify things a bit (right @Ultima2876? :stuck_out_tongue_winking_eye:).


(Mike Evmm) #34

Haha, nice hint :smile:


(Ultima2876) #35

Here’s an example gist for creating a post-process shader in Stage3DPunk. This one does some pretty weird stuff (it’s for a ‘drunk on whisky’ effect in a game I am [slowly] making with a friend); have a play around with it :wink:


(Red Ligot) #36

I noticed what seems to be a bug for colors with my player’s spritemap in which the colors only get changed if the colors were changed upon being added without it being the default color. It does change color in FlashPunk mode though. Am I just missing something though?


(Mike Evmm) #37

Hey, that actually looks rather easy to implement, thanks! :smiley:
Quick question:[quote=“Ultima2876, post:25, topic:1360”] You can get this with FP.getStage3DBitmapData, [/quote] I see that the following code is used to capture the stage, instread:

m_MotionBlurBitmap.copyPixels(FP.buffer, FP.buffer.rect, POINT_ZERO);

Soes this differ from FP.getStage3DBitmapData?


P.S.: lunaticapandora is a great name.


(Ultima2876) #38

Remember, that code is for regular FlashPunk mode (the gist has code paths for both FlashPunk mode and Stage3D mode; otherwise the game would not look right if a sponsor’s site doesn’t support wmode=direct). That code won’t work in Stage3D mode, and using FP.getStage3DBitmapData will be slow (as I mentioned elsewhere in the thread, if you do that once per frame or more you’re basically using regular FlashPunk mode and won’t get any performance advantage from Stage3D. It’s only really for taking a screen capture occasionally to use as a menu background or something).

The real meat of the code is this bit:

FP.screen.setPostProcessShader(m_PixelShader);
FP.screen.setPostProcessShaderConstants(m_PixelConstants);

I could’ve documented that code a lot better! Sorry about that :slight_smile:


(Ultima2876) #39

That does indeed sound like a bug! Could you post a code snippet of how you get this bug to happen?

One thing to try if you get any oddities like this is to add the following under your super() call in Main.as:

enableLazyVertexUpdates = false;

Basically, this is an optimisation which avoids writing to the GPU if a particular sprite’s properties have not changed at all in a frame. However, there are still a few bugs with this as it was added shortly before release. What I am suspecting is happening is that the color update isn’t telling the spritemap that it has been ‘changed’, thus the lazy vertices are blocking it from uploading the color change to the GPU. Just my initial guess though!

Please let me know your results with that though as it’s definitely something I want to fix!


(Mike Evmm) #40

(I couldn’t resist quickly implementing that in Visualize. It looks awesome.) One remark though: if you’re going for a drunk effect, having one of the doubled images rotate around the other probably would look good (imo, of course).


(Red Ligot) #41

Hi, I tried setting it to false, but the problem still persists. Here is the code snippet that handles the changing of the color.

if (currCoin != null)
{
 gameGraphic.color = 0x800080;
currCoin.die();
 FP.console.log("heyd"); Main.score++;
FP.console.log(Main.score.toString());
}