The Stage3DPunk Thread!


(John Andersson) #15

I honestly can’t find that line, not with the search tools at least O.o Where is that line located?


(Mike Evmm) #16

Well, nowhere. If you’re sharing the swf using, for example, Dropbox, it’ll default to FP mode. To force S3D mode, you’ll have to embed the swf in an html file (like this!):

<object width="100%" height="100%">
    <param name="movie" value="SWF_NAME_HERE">
	<PARAM NAME="SCALE" VALUE="default">
    <embed src="SWF_URL_HERE.swf" width="100%" height="100%" wmode="direct" scale="default"> 
    </embed>
</object>

EDIT:Shoot, missed a return (AKA: “body is too similar”).


(Justin Wolf) #17

If you upload to Newgrounds Dump, I believe it auto-detects whether or not your SWF file requires wmode and sets it accordingly.


(John Andersson) #18

Okay, thanks for the great info. But the problem still remains :stuck_out_tongue: The lit lighting engine doesn’t work with this!


(Justin Wolf) #19

Stage3DPunk likely has a missing feature here and there. I imagine maybe it has to do with BlendModes and how they work with Stage3D. @Ultima2876 will be able to let you know exactly why it’s not working.


(Ultima2876) #20

Hey there, sorry for the late response on this (and thanks @justinwolf and @miguelmurca for sorting out the wmode=direct thing).

It’s true, Stage3D needs wmode=direct to work. Some sites support this, others don’t, so rather than letting the game fail to run entirely like most Stage3D games do, Stage3DPunk reverts back to FlashPunk mode on sites (or computers!) that don’t support Stage3D. You can detect this using if(FP.stage3D) – this can be used to optimise your game for both cases so you can take advantage of Stage3D without cutting out some of your playerbase.

As for the Lit lighting engine, Stage3DPunk only provides support for the main FlashPunk library (as well as some limited support for Punk UI); it uses completely different rendering methods under the hood so any libraries for FlashPunk that rely directly on FlashPunk’s original rendering method will probably not work very well, if at all. I’m not familiar with the specifics of Lit but generally speaking if any class overrides the ‘render’ method it won’t work ‘out of the box’. That means most graphical libraries will be broken. If they do work, they may not work as intended or may not perform very well.

All that can be done about this is for someone (or yourself) to make a compatible version of that library (I recommend using if(FP.stage3D) and keeping the original FlashPunk-compatible code in as well!). The Stage3D part of the library isn’t documented but if someone wants to have a go they can feel free to PM me for help doing this :slight_smile:

Unfortunately I’m pretty busy at the moment so don’t have time to look into it myself!


Lit: a light engine
(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: