xml3d / xml3d.js

The WebGL/JS implementation of XML3D
Other
75 stars 25 forks source link

XML3D.BaseRenderTree undefined #153

Closed Arsakes closed 8 years ago

Arsakes commented 8 years ago

It seems that both master & develop branch have XML3D.webgl.BaseRenderTree undefined (checked for DEVELOPMENT SNAPSHOT (21.10.2015 09:16:23 GMT+0200) and version 5.0.0.

csvurt commented 8 years ago

Woops! Thanks for the report, I'll get this fixed and push it out to both branches.

csvurt commented 8 years ago

Should be working now on the master branch. In case it helps here's the RenderTree I used to test the interface this morning, it just draws all objects normally and then draws their bounding boxes in a second pass.

bounding-box-rendertree.js | uploaded via ZenHub

Arsakes commented 8 years ago

Btw do you implemented ssao already? In https://github.com/xml3d/xml3d.js/wiki/Custom-RenderTrees-and-the-RenderInterface you have following function createSceneRenderPass(enableSSAO, target) that suggests it.

EDIT:Ok' I've tried calling createSceneRenderPass(true, sceneTarget) and it produces bugs. So i guess there is no ssao.

Arsakes commented 8 years ago

Regarding example you've provided. What if I would like only render the scene rendered in pass before using only data provided by former pass? No extra mesh data.

I've looked through example on wiki and the renderInterface.createFullscreenQuad(); doesn't work it draws some small quad tha transformed along everything else in scene.

csvurt commented 8 years ago

Sorry, there is SSAO but it's part of the ForwardRenderTree, not the Pass, this was wrong in the wiki. As long as you're using the standard renderer you can enable it in any scene with XML3D.options.setValue("renderer-ssao", true) but as of right now there's no easy way to use it in a custom RenderTree. You would have to copy the entire ForwardRenderTree code and work off that, adding your own passes to it.

If I understand you right you want to render the scene into a RenderTarget and then use that as an input texture for the next render pass. You can do this easily by changing the render target of the SceneRenderPass:

var backbuffer = ri.createRenderTarget(opt);
var scenePass = ri.createSceneRenderPass(backbuffer); //Render to our RenderTarget instead of to the screen
var yourPass = YourRenderPass(
    ri, 
    ri.context.canvasTarget, 
    { inputs : { "sceneTexture" : backbuffer } }
); //This pass would use the RenderTarget as input and draw to the screen

yourPass.addPrePass(scenePass);

Now inside your render pass you will have access to the backbuffer through this.inputs.sceneTexture. From there you can set it as an input texture for your shader and draw that to the fullscreen quad:

uniforms["sceneTexture"] = [this.inputs.sceneTexture.colorTarget.handle];

//In your shader:
uniform sampler2D sceneTexture;

In the simplest case your shader would do nothing more than a single texture read:

gl_FragColor = texture2D(sceneTexture, texcoords);

Which basically just copies the data from the RenderTarget to the screen.

Have a look in the code for the built in ssaoPass. It uses two RenderTargets as inputs and draws an SSAO effect to a full screen quad. You can also have a look at the ssao shader that the pass uses.

This is all pretty low level WebGL stuff which is why we haven't really made the RenderInterface an official feature yet. It still needs a lot of work to make it easier to work with, but hopefully with the example code it's not too confusing.

Arsakes commented 8 years ago

Thanks, regarding RenderInterface it is a little bit confusing since one have to use both your interface and webGl native functions, sometimes is hard to say what actually is done by XML3D and what must be done by user. Regarding SSAO: It seems your implementations have some problems when changing camera it gets broken in next frame ( you can see some random bands randomly placed on model). I'll take a look into it maybe there is some obvious bug. Also it seems that gl viewport dimmensions are set uncorrectly - when i swap renderTree i see viewport changing dimmension.