Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (427)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  MultiPassView - Can I add it as a package to xith.tk?  (Read 4303 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.0

MultiPassView.java
1  
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++) {
         
         // get render pass
        RenderPass pass = m_renderPasses.get(i);
         
         // set node
        pass.getNode().setRenderable(true);

         // set projection policy
        if (pass.getProjectionPolicy() == View.PARALLEL_PROJECTION) {
            setProjectionPolicy(View.PARALLEL_PROJECTION);
         } else {
            setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
         }
         
         // set clear buffer state
        if (i == 0) {
            m_peerImpl.setDisableClearBuffer(false);
         } else {
            m_peerImpl.setDisableClearBuffer(true);
         }
         
         // set force swap state
        if (i < m_renderPasses.size() - 1) {
            m_peerImpl.setForceNoSwap(true);
         } else {
            m_peerImpl.setForceNoSwap(false);
         }
         
         // render
        renderOnce();
         
         // unset node
        pass.getNode().setRenderable(false);
      }
   }
}


and

RenderPass.java
1  
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;

/**
 * @author Jaakko
 *
 */

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);
   }
   
   /**
    * @return Returns the zAlignment.
    */

   public int getZAlignment() {
      return m_zAlignment;
   }

   /**
    * @param alignment The zAlignment to set.
    */

   public void setZAlignment(int zAlignment) {
      m_zAlignment = zAlignment;
   }

   /**
    * @return Returns the farClip.
    */

   public float getFarClip() {
      return m_farClip;
   }
   
   /**
    * @param clip The farClip to set.
    */

   public void setFarClip(float clip) {
      m_farClip = clip;
   }
   
   /**
    * @return Returns the nearClip.
    */

   public float getNearClip() {
      return m_nearClip;
   }
   
   /**
    * @param clip The nearClip to set.
    */

   public void setNearClip(float clip) {
      m_nearClip = clip;
   }
   
   /**
    * @return Returns the node.
    */

   public Node getNode() {
      return m_node;
   }
   
   /**
    * @param m_node The node to set.
    */

   public void setNode(Node node) {
      m_node = node;
   }
   
   /**
    * @return Returns the projectionPolicy.
    */

   public int getProjectionPolicy() {
      return m_projectionPolicy;
   }
   
   /**
    * @param policy The projectionPolicy to set.
    */

   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.

Smiley
Offline 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)

:: JOODE :: Xith3d :: OdeJava ::
Offline 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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.

David Wallace Croft / www.CroftSoft.com / (214) 636-3790 m / Advanced Java Game Programming
Offline 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.
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #5 - Posted 2006-01-26 10:11:47 »

Java 6.0 will be released this Summer.  We should start thinking about permitting 5.0 contributions to Xith.

Now that Java 1.5 is fairly mature, I personally don't have a problem with moving to it.  I don't plan to distribute anything in the near future though, people who do may think differently (I don't know).    Perhaps the community should vote on this?

Until we officially switch (if we do), contributions should be 1.4 though.


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.0

MultiPassView.java

...

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.

Smiley

You are certainly welcome to add this as a tool to the Xith-TK project.  I wonder if they should be added to the core instead though, seems like something a lot of people may want and could become an integral part of Xith3D.


I'm thinking of ways this class can be expanded

Perhaps you could add a variable to the RenderPass class (and call SetRenderOptions on CanvasPeer prior to rendering) so it's even more customisable?

I wonder - would there be a way of integrating features like render to texture into this framework?  This has been a long standing request and there is an example implementation:  http://www.java-gaming.org/forums/index.php?topic=8361.0 (not sure those links still work - one very good example of why to use IssueZilla and not the forums for these things...)

More discussions on such issues:
http://www.java-gaming.org/forums/index.php?topic=8657.0
https://xith3d.dev.java.net/issues/show_bug.cgi?id=93
https://xith3d.dev.java.net/issues/show_bug.cgi?id=101

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.


Thanks for your contribution!

Cheers,

Will.

Offline 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.
Offline 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... Cheesy
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« 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... Cheesy

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.

Offline 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!
Legends of Yore - The Casual Retro Roguelike
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« 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"
Offline 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...
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« 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.

Offline jaakko777

Senior Newbie





« Reply #13 - Posted 2006-02-12 11:06:59 »

Ok, thanks. Ill try it tonight.
Offline 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.
Offline jaakko777

Senior Newbie





« Reply #15 - Posted 2006-02-12 22:41:13 »

Still cant add... Sad

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();
}
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #16 - Posted 2006-02-13 12:03:29 »

What is your error message?

Will.

Offline 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
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« 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.

Offline 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
Offline 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 Smiley ) 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.
Offline jaakko777

Senior Newbie





« Reply #21 - Posted 2006-02-28 00:28:13 »

Committed.

A test program will follow soon...
Offline 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
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #23 - Posted 2006-03-13 14:19:07 »

Thanks Smiley

Will.

Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #24 - Posted 2006-03-13 18:22:43 »

Good job Smiley

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« 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.
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« 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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (76 views)
2014-04-15 18:08:23

BurntPizza (69 views)
2014-04-15 03:46:01

UprightPath (81 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (211 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!