jaakko777
Senior Newbie 
|
 |
«
Posted
2006-01-25 01:25:01 » |
|
I made these two classes for the multipass rendering that got spawned from this thread: http://www.java-gaming.org/forums/index.php?topic=10611.0MultiPassView.java1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| import java.util.ArrayList;
import com.xith3d.render.jogl.*; import com.xith3d.scenegraph.*;
public class MultiPassView extends View { private CanvasPeerImpl m_peerImpl; private ArrayList<RenderPass> m_renderPasses; private BranchGroup m_sceneGraph; public MultiPassView(CanvasPeerImpl peerImpl, Locale locale) { super(); m_peerImpl = peerImpl; m_renderPasses = new ArrayList<RenderPass>(128); m_sceneGraph = new BranchGroup(); m_sceneGraph.setPickable(true); locale.addBranchGraph(m_sceneGraph); } public void addRenderPass(RenderPass pass) { if (m_renderPasses.size() == 0) { m_renderPasses.add(pass); } else { switch (pass.getZAlignment()) { default: case RenderPass.ALIGN_Z_FAR : m_renderPasses.add(0, pass); break; case RenderPass.ALIGN_Z_CLOSE : m_renderPasses.add(m_renderPasses.size() - 1, pass); break; case RenderPass.ALIGN_Z_CLOSEST : m_renderPasses.add(pass); break; } }
m_sceneGraph.addChild(pass.getNode()); } public void removeRenderPass(RenderPass pass) { int index = m_renderPasses.indexOf(pass); m_renderPasses.set(index, null); m_sceneGraph.removeChild(pass.getNode()); } public void renderAll() { for (int i = 0; i < m_renderPasses.size(); i++) { RenderPass pass = m_renderPasses.get(i); pass.getNode().setRenderable(true);
if (pass.getProjectionPolicy() == View.PARALLEL_PROJECTION) { setProjectionPolicy(View.PARALLEL_PROJECTION); } else { setProjectionPolicy(View.PERSPECTIVE_PROJECTION); } if (i == 0) { m_peerImpl.setDisableClearBuffer(false); } else { m_peerImpl.setDisableClearBuffer(true); } if (i < m_renderPasses.size() - 1) { m_peerImpl.setForceNoSwap(true); } else { m_peerImpl.setForceNoSwap(false); } renderOnce(); pass.getNode().setRenderable(false); } } } |
and RenderPass.java1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| import com.xith3d.scenegraph.Node;
public class RenderPass {
public static final int ALIGN_Z_FAR = 0; public static final int ALIGN_Z_CLOSE = 1; public static final int ALIGN_Z_CLOSEST = 2;
private int m_projectionPolicy; private float m_nearClip; private float m_farClip; private Node m_node; private int m_zAlignment; public RenderPass(int projectionPolicy, float nearClip, float farClip, Node node) { this(projectionPolicy, nearClip, farClip, node, ALIGN_Z_CLOSE); } public RenderPass(int projectionPolicy, float nearClip, float farClip, Node node, int zAlignment) { m_projectionPolicy = projectionPolicy; m_nearClip = nearClip; m_farClip = farClip; m_node = node; m_zAlignment = zAlignment; m_node.setRenderable(false); } public int getZAlignment() { return m_zAlignment; }
public void setZAlignment(int zAlignment) { m_zAlignment = zAlignment; }
public float getFarClip() { return m_farClip; } public void setFarClip(float clip) { m_farClip = clip; } public float getNearClip() { return m_nearClip; } public void setNearClip(float clip) { m_nearClip = clip; } public Node getNode() { return m_node; } public void setNode(Node node) { m_node = node; } public int getProjectionPolicy() { return m_projectionPolicy; } public void setProjectionPolicy(int policy) { m_projectionPolicy = policy; } } |
Now can I add them as a new package to the toolkit? I'll provide good javadoc comments and make a test program as required. 
|
|
|
|
|
arne
Senior Member   
money is the worst drug- we should not let it rule
|
 |
«
Reply #1 - Posted
2006-01-25 16:07:54 » |
|
Looks nice to me.
Only one thing:
I believe code should be 1.4 for compilant for the toolkit, you're using 1.5 (generics)
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #2 - Posted
2006-01-25 16:33:11 » |
|
Oh yeah you are right, I'll change that... Also I noticed that there is potentially a NullPointerExeption thrown in the render() method.
Well, ill fix those and then, who do I need to get the "green light" from for committing the new package?
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
croft
Junior Member  
Java, Java, Java
|
 |
«
Reply #3 - Posted
2006-01-25 16:46:22 » |
|
I believe code should be 1.4 for compilant for the toolkit, you're using 1.5 (generics)
Java 6.0 will be released this Summer. We should start thinking about permitting 5.0 contributions to Xith.
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #4 - Posted
2006-01-26 06:15:40 » |
|
Yeah, there are other nice things in 5.0. Like for example System.nanoTime() , a high resolution timer. Perfect for counting update times.
|
|
|
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #6 - Posted
2006-01-26 10:27:10 » |
|
Ok, well ill add it to the toolkit now so i get it out, then you decide weather it will end up in the core. I'll look into those subjects as i have done that.
|
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #7 - Posted
2006-01-26 10:40:15 » |
|
As Yuri mentions in Issue #101, one thing you lose when using a Scenegraph is more direct control over the rendering, etc.
Depending on how you use your new MultiPassView class, you could have much more control over the render order which is nice.
I have been thinking about that too, and i came up with an idea which im not sure if it would work, but here it is: Make a Node (I used extending from Group) that doesnt get drawn when its getting processed during render time. Instead it executes a code snippet provided by the programmer. I overided the getChildren() method so that it calls its own run() method -- containing the code you wanna execute in the middle of render time -- then it returns a empty ArrayList. I havent really tested this since im not so good at immediate mode rendering ( which i think this could be used to ). I guess it could be used for just about anything you usually would like to do in the midst of the rendering. Does this sound like a awful hack? If it does, i better shut my mouth and keep the wild ones to my self... 
|
|
|
|
|
William Denniss
|
 |
«
Reply #8 - Posted
2006-01-26 11:16:36 » |
|
Ok, well ill add it to the toolkit now so i get it out, then you decide weather it will end up in the core. I'll look into those subjects as i have done that.
Sounds good, put it into the toolkit, we can see how it goes (and think about other enhancements). What package name are you thinking of using? As Yuri mentions in Issue #101, one thing you lose when using a Scenegraph is more direct control over the rendering, etc.
Depending on how you use your new MultiPassView class, you could have much more control over the render order which is nice.
I have been thinking about that too, and i came up with an idea which im not sure if it would work, but here it is: Make a Node (I used extending from Group) that doesnt get drawn when its getting processed during render time. Instead it executes a code snippet provided by the programmer. I overided the getChildren() method so that it calls its own run() method -- containing the code you wanna execute in the middle of render time -- then it returns a empty ArrayList. I havent really tested this since im not so good at immediate mode rendering ( which i think this could be used to ). I guess it could be used for just about anything you usually would like to do in the midst of the rendering. Does this sound like a awful hack? If it does, i better shut my mouth and keep the wild ones to my self...  It does work, but the catch is, as Yuri comments in 101 (worth a read if you havn't), you mess with Xith3D's state management system and abstraction layer with LWJGL and JOGL. It might get the job done, but your code will probably break when Xith3D's updated. Most reasons for needing this I think probably could be added to Xith3d proper, and using the multiple render passes is probably a part of this. Will.
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #9 - Posted
2006-01-26 11:57:31 » |
|
How would org.xith3d.scenegraph.MultiPassView and org.xith3d.scenegraph.RenderPass be?
Or maybe just org.xith3d.multipass.*
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Amos Wenger
|
 |
«
Reply #10 - Posted
2006-01-26 18:44:49 » |
|
com.xith3d.scenegraph.MultiPassView and com.xith3d.scenegraph.RenderPass seems fine to me. Yes it needs to be in the core, and yes you should be able to have control on rendering order.
|
"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #11 - Posted
2006-02-10 01:36:01 » |
|
I tried to add the package to the toolkit but i dont have 'Add' rights to the project. Id like to have a folder named org.xith3d.multipass.
I tested that the tookit builds fine with the ant build and javadoced the sources. I still have to write the package level javadoc description and a test program.
Anyway here is the whole package...
|
|
|
|
|
William Denniss
|
 |
«
Reply #12 - Posted
2006-02-12 02:09:38 » |
|
Did you re-checkout your xith-tk with your user name (as opposed to anonymous which is possibly what you used when you firsed checked it out)? I think you should have 'add' permissions. I have added the folder as requested anyway.
Will.
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #13 - Posted
2006-02-12 11:06:59 » |
|
Ok, thanks. Ill try it tonight.
|
|
|
|
|
hawkwind
Junior Member  
Java games rock!
|
 |
«
Reply #14 - Posted
2006-02-12 17:45:52 » |
|
I would ber interested in seeing a small example of how to use these.
|
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #15 - Posted
2006-02-12 22:41:13 » |
|
Still cant add...  I'll make a complete example when i can commit properly, unitll that here is a quick incomplete example:
// create the render peer renderPeer = new RenderPeerImpl(); canvasPeerImpl = (CanvasPeerImpl) renderPeer.makeCanvas(frame, frame.getWidth(), frame.getHeight(), graphicsMode.getBitDepth(), graphicsDevice.getFullScreenWindow() != null); canvas3d = new Canvas3D(); canvas3d.set3DPeer(canvasPeer);
// create the virtual universe virtualUniverse = new VirtualUniverse();
// create a locale for the universe locale = new Locale(); virtualUniverse.addLocale(locale);
// create a view for the universe view = new MultiPassView(canvasPeer, locale);
virtualUniverse.addView(view);
// This far all looks pretty normal, but now comes the multiview setup
RenderPass background = new RenderPass(View.PERSPECTIVE_PROJECTION, 0.1f, 10.0f, new Background(new Color3f(0,0,0))); view.addRenderPass(background);
RenderPass scene = new RenderPass(View.PERSPECTIVE_PROJECTION, 0.1f, 3000.0f, new BranchGroup(), RenderPass.ALIGN_Z_CLOSEST); view.addRenderPass(scene);
RenderPass hud = new RenderPass(View.PARALLEL_PROJECTION, 0.1f, 100.0f, new Foreground(new BranchGroup(), View.VIEW_FIXED), RenderPass.ALIGN_Z_CLOSEST); view.addRenderPass("gui", hud); // <-- Note that we add a name for this pass so that we can refer to it easily later
// add the canvas to the view view.addCanvas3D(canvas3d);
// the render loop while(true) { // Any scenegraphg updates ... // for example: // Node gui = view.getRenderPass("gui").getNode(); // do something with the gui, update for example a FPS counter ... // render in multi pass view.renderAll(); }
|
|
|
|
|
William Denniss
|
 |
«
Reply #16 - Posted
2006-02-13 12:03:29 » |
|
What is your error message?
Will.
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #17 - Posted
2006-02-13 22:24:22 » |
|
The server reported an error while performing the "cvs add" command. xith-tk: User jaakko777 doesn't have <VersionControl - Add> access to project xith-tk
|
|
|
|
|
William Denniss
|
 |
«
Reply #18 - Posted
2006-02-18 23:03:01 » |
|
Odd, your name didn't appear in the xith-tk list which explains the error. Normally how it works is that a user can request a role, I get an email and approve it.
I've added your username as a developer - so try it again now.
Cheers, Will.
|
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #19 - Posted
2006-02-22 16:39:11 » |
|
Hi,
As a quick and simple implementation of multipass rendering it is 100% correct (I did nearly the same when was playing with pseudo-stereo (stereoglypgh) rendering with Xith3D).
Time ago I was reviewing several different engines how do they implement multipass, but still found no concept that will cover most of the needs: - Fullscreen Multipass (similar to one presented here) - Per-object multipass - Mixed on-screen+off-screen multipass - Stereo multipass - Multicanvas multipass - ...and some others very specific to my applications...
The best idea that I have up to now is to ... use the same concept as OrderedGroup is using, or even use the same ordered group mechanism, and add a bit more of sub-graph sharing features and extra rendering control nodes. ...but I still did not finalize the concept for such a change, so treat it just as an idea.
Yuri
|
Yuri Vl. Gushchin JProof Group
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #20 - Posted
2006-02-23 00:49:06 » |
|
Ok, i tought i was at developer status but well then.. Thanks for adding me! Sorry for my recent absence but i relocated to San Francisco last week for a six weeks assignment by my company ( to learn J2ME to BREW porting  ) and im getting over the jetlag slowly. I will commit the package as soon as possible - when im fully recovered and not falling asleep at once when entering my hotel room.
|
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #21 - Posted
2006-02-28 00:28:13 » |
|
Committed.
A test program will follow soon...
|
|
|
|
|
jaakko777
Senior Newbie 
|
 |
«
Reply #22 - Posted
2006-03-12 08:09:02 » |
|
I just committed a test program to this. Basically it just mixes parallel and perspective by rendering a cube in each mode. The cubes are rotating so that the difference can be seen.
I'll continue maintaining this so feel free to suggest improvements, other requests and of course notify bugs.
For now im leaving this as it is and head back to finalize the GUI system im working on...
Jaakko
|
|
|
|
|
|
|
Amos Wenger
|
 |
«
Reply #24 - Posted
2006-03-13 18:22:43 » |
|
Good job 
|
"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
|
|
|
Marvin Fröhlich
|
 |
«
Reply #25 - Posted
2006-06-17 17:24:17 » |
|
hi I took this great work and changed it slightly. But I have problems with it. My changes: - transscripted to Java 1.5
- added multi-canvas support
- eliminated the need for this Impl class
- renamed these renderPass methods to renderOnce so that they better fit into the familiar View class usage
My problem is the "canvasPeerImpl.setDisableClearBuffer(forceClearBuffer);" call. (Strange! I didn't modify this line.) If I leave this line, rendering flickers with more than one RenderPass. If I use it, rendering seems to stand still. But actually it seems to be some other problem. Could someone please look at the code and help me. Just use it with the slightly changed MultipassTest class. so long, Qudus By the way. Can someone with writerights to xith core please activate the getAllCanvas3Ds() method on the View class. I think one has to switch from ArrayList To Vector or something like that for the list containing the Canvas3Ds.
|
|
|
|
|
Marvin Fröhlich
|
 |
«
Reply #26 - Posted
2006-06-17 21:25:08 » |
|
OK. Once again it was only a matter of the right keywords to search the forum.
I will commit the changes to CVS, when I've solved other problems. Hope that's ok.
|
|
|
|
|
|