Render to texture

Software: Away3D 4.x

mountainstorm, Newbie
Posted: 28 December 2013 10:52 AM   Total Posts: 4

I want to use Away3D to render (only) to a texture - which I’ll then composite in Starling.

So far I’ve read lots of posts which suggest things like:

view.renderer.swapBackBuffer = false;
view.render();
view.stage3DProxy.context3D.drawToBitmapData(mainBmp.bitmapData); 
view.renderer.swapBackBuffer = true;

which don’t work - as swapBackBuffers appears to have disappeared recently.

view.renderer.queueSnapshot(bitmapData);

which doesn’t appear to do anything, and

view.stage3DProxy.context3D.setRenderToTexture(_texture.base)

which I expected to work but doesn’t.

So how do I do it.  The closest I’ve got by just calling

view.render();
view.stage3DProxy.context3D.drawToBitmapData(mainBmp.bitmapData);

Which works, but still renders to the back buffer (I have to cover it with a vanity image) and halves my frame rate (although Flash is still only using 24% of my CPU).

Originally I was just trying to layer Starling and Away3D native renders ... and it works; except you can’t use blend modes between the libraries so my screen blend layer just made everything darker :(

Given that 90% of what I want to do is in Starling; I just want a single 3D character - I’d rather render to a texture, add that to my Starling and then keep everything else 2D.

Thoughts?

Rich

   

mountainstorm, Newbie
Posted: 30 December 2013 11:08 PM   Total Posts: 4   [ # 1 ]

For anyone listening and interested, and general google fodder; heres a partial solution I’ve got working - with a new set of problems.

First, make away3d render to a texture (not bitmap data).  I’ve found two ways to do this:
1. Go into View3D.as - render()
  1. add a TextureBase param to the function
  2. add a call to (if param is provided) _renderer.render(_entityCollector, param, _rttBufferManager.renderToTextureRect);

or:

2. call stage3DProxy.context3D.setRenderToTexture(_texture.base, true);

in both cases you get the image rendered to your texture, and you can composite it with Starling etc (as described here: http://away3d.com/tutorials/Away3D_and_Starling_Interoperation).  Best of all as you never access the bitmap data, and it all stays on the graphics card as a texture there is no performance hit; yay!

This gives me two new problems though. 

1. The background is black; I should be able to call ‘view.renderer.backgroundAlpha = 0.0’ - but that gives me this error
  ‘Attempted access of inaccessible property backgroundAlpha through a reference with static type away3d.core.render:RendererBase.’ - you can always mod the source in RenderBase.as

2. The scale of the rendered view is way off i.e. its too tall

Anyone able to help with these problems

   

mountainstorm, Newbie
Posted: 31 December 2013 12:10 PM   Total Posts: 4   [ # 2 ]

A bit more experimentation reveals a not insignificant problem. 

You need the starling and away3d both using the same stage3dproxy, otherwise the texture isn;t shared between them.

When you call stage3DProxy.context3D.setRenderToTexture everything for that proxy gets rendered to the texture ... thus so does your starling output.  you don’t notice until you try to do it every frame. :(

The ‘fix’ I’ve come up with is to do the following:
  1. stage3DProxy.context3D.setRenderToTexture
  2. stage3DProxy.clear() // clears texture
  3. view3d.render()
  4. stage3DProxy.present() // completes render and sets output to backbuffer
  5. stage3DProxy.clear() // clears back buffer
  6. starling.nextFrame()
  7. stage3DProxy.present() // displays just starling output

I’ve still got a scaling issue but I suspect its a result of differing view matrix’s.

I’m starting to question how much I need Starling, its lovely but it might be easier to render all in away3d and just implement 2d backdrops natively

   

drygu, Newbie
Posted: 03 January 2014 08:31 PM   Total Posts: 7   [ # 3 ]

Hi mountainstorm,

I’ve tried to achieve something similar. Isometric 2d game with 3d characters. I’ve made it with away3d but the performacne wasn’t too good:
http://test.taern.com/demo/map.html (it’s loading quite slow, wait patiently smile)

Then i’ve tried different approach. Background in starling + 3d characters on away3d layer. Starling was doing great but away even with small 3d cube was decreasing performacne a lot. Here are some performance tests:
1. http://www.test.taern.com/s/starling/indexbug.html (just starling)
2. http://www.test.taern.com/s/starling/awayMag.html (starling + simple 3d character model)
3. http://www.test.taern.com/s/starling/awayEmpty.html (starling + 3d cube)

Next step i wanted to try is your solution smile
What performance did you achieved this way? Do you think it can handle multiple animated models on 2d backgorund this way?


I’ve tried to ask some away member by email about best approach to this issue but didn’t get any answer.

   

mountainstorm, Newbie
Posted: 05 January 2014 12:19 PM   Total Posts: 4   [ # 4 ]

Your first link gives me about 52 fps; nice graphics by the way - it looks great.

Originally I tried doing as you suggest, a 2d starling background and foreground.  This gives me the problem of colour matching my 3d models to the pre-rendered environment but I’m beginning to think that might be the lesser of two evils (I think my planned method might run out of texture memory fast).

This does limit me to only ever having the true 3d sandwiched between two layers of 2d - I also might try full on 3d, but that seems likely to be more haste than its worth.

   

Pierce, Jr. Member
Posted: 30 August 2014 03:08 AM   Total Posts: 40   [ # 5 ]

@drygu,

So I know this was posted forever ago, but I was looking around for info on texture rendering (thanks @mountainstorm) and am/have also played with shared views and was wondering what ultimately happened with your project.

For the record, your initial character demo ran just fine for me (around a very solid 58-62 with 5 characters fullscreen) but the combined starling views were definitely slower, with the character at 52ish, and bizarrely all over the place with the cube. Obviously, just starling was whirring on at 60+, as it better well should for just putting textures on planes.

Something wonky definitely seems to be going on. Did you ever identify it? Also wonder about the efficiency of your character rigs. That will definitely cause a performance hit, especially if they bleed onto the cpu at all. Unless you made them yourself, sometimes models that seems really simple have absolutely crazy stuff going on under the hood due to whatever the needs were of the thing they were originally used for.

   

drygu, Newbie
Posted: 30 August 2014 05:06 PM   Total Posts: 7   [ # 6 ]

Hi,

The difference between starling vs away3d + starling was about BASELINE_CONSTRAINED vs BASELINE mode. In BASELINE_CONSTRAINED everyhting is working much faster but it lacks some more advanced options. It’s default mode for Starling.

About our project:
We postponed it for few months but now we are back on track. We’ve learned more about optimization by consulting away3d team. We have optimized our models and scene and it’s runing smooth even on mobile now. I’ll be able to show some playable demo in few weeks.

   

liquid, Newbie
Posted: 09 May 2015 06:20 AM   Total Posts: 8   [ # 7 ]

Thanks for this discussion! You pointed me to something I wouldn’t have think about.

I use setRenderToTexture() to render an Away3D-Scene (2048x1024) into a flash.display3D.textures.TextureBase, that I share with a Starling Image. The performance is pretty good and there’s no need to render into a BitmapData (CPU) and pass it to the GPU again, but:

While the 3D Scene has a great quality (AntiAliasing set to 32) the resulting representation within the StarlingImage looks very dirty.

Can it be related to this (maybe unsolved) adobe bug report (the AntiAliasing property gets ignored)?
https://bugbase.adobe.com/index.cfm?event=bug&id=3689914

I use
- the latest AGALMiniAssembler (2015),
- the Starling TextureSmoothing is set to TRILINEAR
- en- or disabling the MipMapping was not helpful.

I can’t believe it’s a problem within the Starling Layer. It must be the way the Context3D renders the Texture. Did you realize similar problems with the render quality?


By the way, your scaling issue with the rendered texture can be related to the vieports width and height. If the dimensions are not powers of two you have to “scale back”.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X