|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Shaders in Java 3DHi all,
Anyone using shaders in J3D? I'm trying to get a feel for how good the support is at this point - is this pretty stable/functional? Any reason to choose Cg vs GLSL? I'm also looking for good background material on developing shaders, esp as it pertains to Java 3D. I've noticed the javadoc is still missing things (ShaderAppearance has a bunch of XXXXX for attributes). I know there are some examples in the distribution to start with. Thanks! Bill [Message sent by forum member 'weiland' (weiland@...)] http://forums.java.net/jive/thread.jspa?messageID=369531 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: Shaders in Java 3Dhi,
I'm using shaders, no problems with it at all. I'd choose GLSL over Cg, because Cg is Nvidia specific. I started with the examples, they are pretty nice and i tried to figure it out to build a bump-map-"shader". best chris [Message sent by forum member 'optimusprime1982' (c.krenn@...)] http://forums.java.net/jive/thread.jspa?messageID=369562 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: Shaders in Java 3DBill, the following text isn't an academical elaboration of Java 3D and GLSL. It is only a collection of experiences that might encourage the use of shaders in Java 3D. Not all statements were tested! Corrections and more details are appreciated. August
[b]A. OpenGL / GLSL Versions[/b] [code] Year OpenGL GLSL Remarks 2004 2.0 1.10 Introduction of the programmable rendering pipeline 2006 2.1 1.20 2008 3.0 1.30 Deprecation Model: deprecated features 2009 3.1 1.40 2009 3.2 1.50 Profiles: Core, Compability [/code] [b]GLSL <= 1.20 :[/b] "Any OpenGL state used by the shader is automatically tracked and made available to shaders. This automatic state tracking mechanism allows the application to use existing OpenGL state commands for state management and have the current values of such state automatically available for use in a shader." [b]Break ![/b] [b]GLSL >= 1.30 :[/b] "Most OpenGL state is not tracked or made available to shaders. Typically, user-defined variables will be used for communicating between different stages of the OpenGL pipeline. However, a small amount of state is still tracked and automatically made available to shaders, and there are a few built-in variables for interfaces between different stages of the OpenGL pipeline." NVIDIA declared its commitment to backwards compability of its drivers : http://developer.nvidia.com/object/opengl_3_driver.html. I assume that AMD/ATI will behave similarly. Java 3D 1.4 introduced shaders in 2006. The Java 3D 1.5.2 engine still uses the legacy/2.x OpenGL-context creation API. This creates a compatible context version which could be above 2.1 (e.g. 3.2 on my system GTS250/191.07) depending on the installed graphics device and driver. Compatible context means that all deprecated features are still supported and OpenGL states are still available to shaders as in versions <= 1.20! The GLSL preprocessor directive '#version [i]number[/i]' allows to specify the desired compiler version (number = 110, 120, 130, 140, or 150; if avaialble). I successfully ran '#version 150'. I replaced the deprecated 'varying' storage qualifier by 'out/in' (1.30) and I had access to the fragment shader built-in variable 'gl_PrimitiveID' (1.50, #extension GL_EXT_gpu_shader4 : enable). The new geometry shader can't be used because it would require enhancements in the Java 3D API. [b]B. Attribute/State/Variable Binding: Java 3D -> OpenGL -> GLSL [/b] Java 3D implicitly binds node and node component attributes to shader built-in variables via OpenGL states. Unfortunately, this isn't really well described. In the first step one should get familiar with GLSL's built-in variables, see - GLSL specifications, chapter 7 Build-In Variables / 7.5 Built-In Uniform State - Orange Book, chapter 4 The OpenGL Programmable Pipeline / 4.3 Built-in Uniform Variables 1. ShaderAppearance 1.1 ColoringAttributes, Material, and TransparencyAttributes The Java 3D node components ColoringAttributes, Material, and TransparencyAttributes determine the vertex shader built-in variable 'gl_FrontMaterial'. [code] // Java 3D - ShaderAppearance Material material = new Material(); material.setDiffuseColor(0.8f, 0.2f, 0.0f); TransparencyAttributes trans = new TransparencyAttributes(); trans.setTransparencyMode(TransparencyAttributes.NICEST); trans.setTransparency(0.66f); // GLSL - Vertex Shader gl_FrontColor = gl_FrontMaterial.diffuse; // = (0.8, 0.2, 0.0, 0.34) RGBA [/code] 1.2 Texture, TextureAttributes, TexCoordGeneration A Java 3D texture image is represented within a shader by a user-defined uniform sampler variable: - Texture2D -> sampler2D - Texture3D -> sampler3D - TextureCubeMap -> samplerCube All (?) attributes of the Texture object like filtering and wrapping will be applied to the image. Corresponding built-in functions perform texture access within a shader: - Texture2D -> texture2D(sampler2D sampler, vec2 texCoord) - Texture3D -> texture3D(sampler3D sampler, vec3 texCoord) - TextureCubeMap -> textureCube(samplerCube sampler, vec3 texCoord) Automatically generated texture coordinates from a Java 3D TexCoordGeneration object can be accessed either within a vertex shader via the built-in variable 'gl_MultiTexCoordn' or within a fragment shader via the built-in variable 'gl_TexCoord[n]'. If both shaders exist the texture coordinates have to be directed from the vertex shader to the fragment shader, e.g. 'gl_TexCoord[n] = gl_MultiTexCoordn'. The plane equation coefficients used to generate the coordinates in the OBJECT_LINEAR and EYE_LINEAR generation modes are available as built-in variables: gl_ObjectPlaneS/T/R/Q[n] and gl_EyePlaneS/T/R/Q[n]. Neither the blending functions nor the texture transformation (?) of the Java 3D TextureAttributes will be applied if a fragment shader exists. Blending and texture transformation (built-in variable 'gl_TextureMatrix[n]') have to be implemented in the shader. [code] // Java 3D - TextureUnitState[0], TextureUnitState[1] ShaderAttributeValue attributeCloud = new ShaderAttributeValue("cloudTex", new Integer(0)); ShaderAttributeValue attributeEarth = new ShaderAttributeValue("earthTex", new Integer(1)); // GLSL - Fragment Shader uniform sampler2D earthTex; uniform sampler2D cloudTex; void main (void) { // Texture coordinates: generated or from GeometryArray vec2 tc0 = gl_TexCoord[0].xy; vec2 tc1 = gl_TexCoord[1].xy; // Texture access vec3 color0 = vec3(texture2D(cloudTex, tc0)); vec3 color1 = vec3(texture2D(earthTex, tc1)); // Final fragment color vec3 finalColor = color0*0.6 + color1; gl_FragColor = vec4(finalColor, 1.0); } [/code] 1.3 Other The Line-, Point-, Polygon-, and RenderingAttributes still effect the appearance of a Shape3D. They aren't bound to shader built-in variables because their attributes are related to the remaining fixed-function pipeline. The point size attribute requires more investigations. 2. GeometryArray 2.1 The standard vertex attributes coordinates, normals, colors, and texture coordinates are readable in a vertex shader via the built-in variables - gl_Vertex (COORDINATES) - gl_Normal (NORMALS) - gl_Color (COLOR_3 / _4) - gl_MultiTexCoordn (TEXTURE_COORDINATE_2 / _3 / _4) 2.2 The generic vertex attributes (VERTEX_ATTRIBUTES) are readable in a vertex shader via user-defined attribute variables. Array element 0 specifies the name of GeometryArray vertex attribute 0, array element 1 specifies the name of GeometryArray vertex attribute 1, and so forth. [code] // Java 3D String[] vaNames = { "weight", "temperature" }; GLSLShaderProgram.setVertexAttrNames(vaNames); // GLSL - Vertex Shader attribute float weight; attribute vec3 temperature; [/code] 3. Light Java 3D Light node attributes are readable in a vertex shader via the built-in variables 'gl_LightSource[n]'. 4. Fog Java 3D Fog node attributes are readable in a vertex shader via the built-in variable 'gl_Fog'. 5. ModelClip Java 3D ModelClip node attributes are readable in a vertex shader via the built-in variables 'gl_ClipPane[n]'. 6. Transformations The transformations of the Shape3D and the ViewPlatform as well as the transformation of the chosen projection mode are available in the vertex shader as built-in combined matrices of the model, view, and projection transformations: 'gl_xyzMatrix'. 7. Individual variables Subclasses of ShaderAttributeObject allow to encapsulate arbitrary attributes in the Java 3D code which then are readable via user-defined uniform variables within vertex and fragment shaders. [code] // Java 3D ShaderAttributeValue attributeValue = new ShaderAttributeValue("mixRatio", new Float(0.35f)); ShaderAttributeArray attributeArray = new ShaderAttributeArray("clamp", new Integer[]{-1, 1}); // GLSL - Vertex/Fragment Shader uniform float mixRatio; uniform int clamp[2]; [/code] [b]C. Resources[/b] 1. OpenGL and GLSL current and older [b]specifications[/b] : http://www.opengl.org/registry/ The GLSL specifications are generally understandable and worthy to read. 2. OpenGL Shading Language Book - [b]Orange Book[/b], 2nd (2.0 / 1.10) or 3rd (3.1 / 1.40) edition : http://www.3dshaders.com/home/ See the 'Shader Examples' page for shader examples and tools download : - Orange Book Shaders : "This zip file contains the source for all of the complete shader examples that are contained in the second edition of the OpenGL Shading Language book." - GLSL Demo : "GLSLdemo is a program that illustrates the use of many of the shaders published in the Orange Book." - ShaderGen : "ShaderGen is a program that can automatically produce shaders that mimic the results of a set of fixed function state." - deLight : "This more complex application includes shaders adapted from Chapters 12-14 of the book." [Message sent by forum member 'interactivemesh' (A.Lammersdorf@...)] http://forums.java.net/jive/thread.jspa?messageID=370212 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: Shaders in Java 3DThanks, August! The attribute binding info is especially useful. I've got the Orange Book; I'll try experimenting with some of their sample shaders.
Bill [Message sent by forum member 'weiland' (weiland@...)] http://forums.java.net/jive/thread.jspa?messageID=370501 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
| Free embeddable forum powered by Nabble | Forum Help |