Extending jReality Shaders
-
- Posts: 5
- Joined: Fri 22. Jan 2010, 12:41
Extending jReality Shaders
How can one define an external shader and specify it for the appearance of a node?
Re: Extending jReality Shaders
Here's a short overview of what's required to add a new polygon shader. For an introduction to shading in general see this tutorial section or this section.
If you are working with the svn repository, look at the package de.jreality.shader in src-core. There are a series of shader interfaces which are "backend-neutral". For example, there are three different polygon shaders: default, twoSided, and implode. Each backend writer is then encouraged to implement these shaders in his backend. Currently, for example, in the JOGL backend, this list of shaders is hard-wired into the class de.jreality.jogl.shader.DefaultGeometryShader in the method
Similar (but not identical) code exists in the software backend. The argument to this method can be thought of as a set of get/set methods for the parameters to the shader; the return value is a shader which implements the algorithm of this shader using these parameters for the given backend, in this case, the JOGL backend.
So, if you want to add a new polygon shader and your first backend implementation is the JOGL backend, you'll need to create an interface shader in the package de.jreality.shader, and then write a JOGL implementation of this shader with the same name in the package de.jreality.jogl.shader. Here you can use the existing JOGL polygon shaders as a guide to writing the latter shader, in the absence of better documentation. Finally, add a line in the above method corresponding to your new pair of classes. If your shader is named "MyPolygonShader", then you can create instances of your shader with calls like
A better documented alternative is to write your extended shaders using the OpenGL shading language. This alternative is illustrated in three tutorial examples in de.jreality.tutorial.app. Then you won't have the chance of seeing your extended shader in other backends besides the JOGL one, but depending on your purposes that may be acceptable, or even necessary depending on what you want your shader to do!
If you are working with the svn repository, look at the package de.jreality.shader in src-core. There are a series of shader interfaces which are "backend-neutral". For example, there are three different polygon shaders: default, twoSided, and implode. Each backend writer is then encouraged to implement these shaders in his backend. Currently, for example, in the JOGL backend, this list of shaders is hard-wired into the class de.jreality.jogl.shader.DefaultGeometryShader in the method
Code: Select all
public static de.jreality.jogl.shader.PolygonShader createFrom(de.jreality.shader.PolygonShader ps) {
So, if you want to add a new polygon shader and your first backend implementation is the JOGL backend, you'll need to create an interface shader in the package de.jreality.shader, and then write a JOGL implementation of this shader with the same name in the package de.jreality.jogl.shader. Here you can use the existing JOGL polygon shaders as a guide to writing the latter shader, in the absence of better documentation. Finally, add a line in the above method corresponding to your new pair of classes. If your shader is named "MyPolygonShader", then you can create instances of your shader with calls like
Code: Select all
DefaultGeometryShader dgs =
ShaderUtility.createDefaultGeometryShader(ap, true);
MyPolygonShader mps = (MyPolygonShader) dgs.createPolygonShader("my");
mps.setFoo(8.0); // set your shader parameters
....
jReality core developer
-
- Posts: 5
- Joined: Fri 22. Jan 2010, 12:41
Re: Extending jReality Shaders
Thank you for the prompt reply!
What we are actually trying to do is port our OpenCL and GLSL (initially CG) volume rendering algorithms to jReality. I browsed though the GLSL shader code today and I noticed that it does not force you to render to a texture. So (correct me if I am wrong) we can use this shader for the GLSL algorithms that need to render directly to the frame buffer. In the case of the OpenCL algorithms we will need to create a custom shader.
We also considered intercepting the rendering process by sub-classing JOGLPeerComponent, but although it might work it's more of a hack than a "proper" implementation.
Thank you,
Kostas
P.S. We will share with you our results and a demo!
What we are actually trying to do is port our OpenCL and GLSL (initially CG) volume rendering algorithms to jReality. I browsed though the GLSL shader code today and I noticed that it does not force you to render to a texture. So (correct me if I am wrong) we can use this shader for the GLSL algorithms that need to render directly to the frame buffer. In the case of the OpenCL algorithms we will need to create a custom shader.
We also considered intercepting the rendering process by sub-classing JOGLPeerComponent, but although it might work it's more of a hack than a "proper" implementation.
Thank you,
Kostas
P.S. We will share with you our results and a demo!
Re: Extending jReality Shaders
If you have problems with the jReality GLSL shader interface (after looking at the three tutorial examples mentioned in my previous post) please don't hesitate to post them -- there may be simple solutions/answers that the documentation doesn't mention.
jReality core developer
Re: Extending jReality Shaders
I just noticed that you posted this question in two different categories of the jReality forum. To avoid duplicated responses, I recommend that you first post it in the category which you think is the most relevant. If it receives no replies after two or three days, then perhaps post it in another category, but generally if you chose the wrong category the other users should correct you and you can then move the question to the more appropriate category. Thanks for your understanding.
jReality core developer