Show Posts
|
|
Pages: [1]
|
|
3
|
Java Game APIs & Engines / JOGL Development / 3D texture problem
|
on: 2007-02-08 16:49:15
|
|
I have a Nvidia GeForce 6800 GS graphics card with 256 MB. My 3D application uses the following code to set up 3D texture units and uniform variables for use in the Cg fragment shader. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // texture setup in the application gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glGenTextures(1, temp1, 0); TextureID = temp1[0]; gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// Generate normals gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glGenTextures(1, temp16, 0); normal_ID = temp16[0]; gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID); // gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// setup Cg parameters Texture_Param = CgGL.cgGetNamedParameter(fProgram, "Texture"); normal_Param = CgGL.cgGetNamedParameter(fProgram,"normals"); CgGL.cgGLSetTextureParameter(Texture_Param, TextureID); CgGL.cgGLSetTextureParameter(normal_Param, normal_ID); CgGL.cgGLEnableTextureParameter(Texture_Param); CgGL.cgGLEnableTextureParameter(normal_Param);
-------------------------------------------------------------------------------------------------------------------------------------------------------- // in Display() FloatBuffer volumeBuf = FloatBuffer.wrap(volumeBuffer); volumeBuf.rewind(); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glEnable(GL.GL_TEXTURE_3D); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR); gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID); gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGBA, iWidth, iHeight, iDepth, 0, GL.GL_RGBA, GL.GL_FLOAT, volumeBuf);
FloatBuffer normal_buf = FloatBuffer.wrap(normals); normal_buf.rewind(); gl.glActiveTexture(GL.GL_TEXTURE1); gl.glEnable(GL.GL_TEXTURE_3D); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR); gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID); gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGB, iWidth, iHeight, iDepth, 0, GL.GL_RGB, GL.GL_FLOAT, normal_buf);
-------------------------------------------------------------------------------------------------------------------------------------------------
void FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0, uniform sampler3D Texture, uniform sampler3D normals) {
//get normal float3 normal; normal.rgb = tex3Dproj(normals, inTex).rgb; // Color look up float4 result; result.rgba = tex3Dproj(USTexture, inTex).rgba; ..... ...... // calculate the lighting.
oColor = result * light;
}
If I switch the order of normal and texture calculation in fragment program, i.e.
oid FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0, uniform sampler3D Texture, uniform sampler3D normals) {
// Color look up float4 result; result.rgba = tex3Dproj(USTexture, inTex).rgba; //get normal float3 normal; normal.rgb = tex3Dproj(normals, inTex).rgb; ..... ...... // calculate th light.
oColor = result * light;
}
The final volume image color changed quite a lot. It turns to be an error. Does anyone have the slightest clue about what could be the reason for such behavior? Can Jogl correctly handle 3D texture sampler? Or this due to my card issue? Or my OpenGL code doesn't setup 3D texture appropriately?
Thanks.
|
|
|
|
|
8
|
Java Game APIs & Engines / JOGL Development / Re: Jogl demo compilation error
|
on: 2006-12-07 15:35:55
|
|
Ken,
I follow what you suggest specify the -Djava.libarary.path in side JBuilder. Remove the old Cg. Install Cg 1.5. I still get the same error. I use JSR-231 1.0.0 release.
Don't know what's happed.
thanks,
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\jogl\jogl-1_0_0-windows-i586\lib\jogl_cg.dll: The specified procedure could not be found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:151)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:148)
at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
at demos.cg.runtime_ogl_vertex_fragment.runtime_ogl_vertex_fragment.init(runtime_ogl_vertex_fragment.java:107)
at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:264)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "Thread-2" javax.media.opengl.GLException: java.lang.NoClassDefFoundError
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:271)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:256)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at com.sun.opengl.util.Animator.display(Animator.java:144)
at com.sun.opengl.util.Animator$MainLoop.run(Animator.java:181)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NoClassDefFoundError
at demos.cg.runtime_ogl_vertex_fragment.runtime_ogl_vertex_fragment.display(runtime_ogl_vertex_fragment.java:154)
at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:298)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
|
|
|
|
|
9
|
Java Game APIs & Engines / JOGL Development / Re: Jogl demo compilation error
|
on: 2006-12-06 22:12:55
|
|
Ken,
I use JBuilder. I include all the .jar files in the required library. Compile is fine. When I run, I get the following error, Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no jogl_cg in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:151)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:148)
at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
at demos.cg.runtime_ogl.cgGL_vertex_example.init(cgGL_vertex_example.java:191)
at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:264)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Then, I copy the jogl.dll, jogl_awt.dll, jogl_cg.dll to C:\jdk1.5.0_06\jre\bin. During the running, I receive the following error, Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\jdk1.5.0_06\jre\bin\jogl_cg.dll: The specified procedure could not be found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:151)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:148)
at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
at demos.cg.runtime_ogl.cgGL_vertex_example.init(cgGL_vertex_example.java:191)
at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:264)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Any suggestions? It seems that the JBuilder can't automatically grab the jogl.dll related files.
Thanks,
|
|
|
|
|
10
|
Java Game APIs & Engines / JOGL Development / Re: Jogl demo compilation error
|
on: 2006-12-06 16:33:29
|
|
Ken,
I follow exactly from the user guide. Add the CLASSPATH for jogl.jar and PATH for Cg. I use the Cg 1.5 and Jogl nightly build. I run into the same problems.
I doubt for the incompatibility issues between Cg 1.5 and new release Jogl.
Could you tell me exactly where you locate the .dll and window-586.jar files? If possible, clarify the classpath setup.
Thanks a lot,
|
|
|
|
|
12
|
Java Game APIs & Engines / JOGL Development / Re: Jogl demo compilation error
|
on: 2006-12-01 18:44:08
|
|
Actually, I get the following error.
// Create Cg Context Context = CgGL.cgCreateContext(); CheckCgError();
demos.cg.runtime_ogl.cgGL_vertex_example
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\jdk1.5.0_06\jre\bin\jogl_cg.dll: The specified procedure could not be found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:78)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:101)
at com.sun.opengl.impl.NativeLibLoader.access$100(NativeLibLoader.java:47)
at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:151)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCgImpl(NativeLibLoader.java:148)
at com.sun.opengl.cg.CgGL.<clinit>(CgGL.java:5412)
at demos.cg.runtime_ogl.cgGL_vertex_example.init(cgGL_vertex_example.java:191)
at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:264)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
|
|
|
|
|
13
|
Java Game APIs & Engines / JOGL Development / Jogl demo compilation error
|
on: 2006-12-01 18:13:22
|
|
I recently download the latest version of Jogl and demos. Most of the demos work fine. However, I found two demos are out dated.
demos.cg.runtime_ogl and demos.cg.runtime_ogl_vertex_fragment
It turn out that following no longer exist,
Context = CgGL.cgCreateContext(); CgGL.cgGLEnableProfile
Any suggestions?
Thanks,
|
|
|
|
|
18
|
Java Game APIs & Engines / JOGL Development / Jogl: fragment program is over native resource limits
|
on: 2006-06-28 23:01:20
|
|
I use jogl to read the two fragment programs. It seems the simple fragment program can pass the native resource limit test. However, the more complicated fragment program can not pass the native resource limits test. Can someone give me some suggestions on the error causation and work around? If I use C and OpenGL, both of the fragment programs work all right. What the "native resource limits" means in Jogl?
Hopefully, Ken can give me certain input on this.
Thanks.
I post my jogl testing code and the two fragment programs below,
/************** Jogl testing code ****************/ // profile = GL.GL_FRAGMENT_PROGRAM_ARB // FileUtils as given in the jogl.demo.util private int loadProgram(GL gl, int profile) throws IOException { String fileNm = "isosurface_sm3.fp"; FileInputStream in; fileNm = "VolumeRenderPyramidF.ocg"; in = new FileInputStream(fileNm); String programBuffer = FileUtils.loadStreamIntoString(in); int[] tmpInt = new int[1]; gl.glGenProgramsARB(1, tmpInt, 0); int res = tmpInt[0]; gl.glBindProgramARB(profile, res); gl.glProgramStringARB(profile, GL.GL_PROGRAM_FORMAT_ASCII_ARB, programBuffer.length(), programBuffer); int[] errPos = new int[1]; gl.glGetIntegerv(GL.GL_PROGRAM_ERROR_POSITION_ARB, errPos, 0); if (errPos[0] >= 0) { String kind = "Program"; if (profile == GL.GL_VERTEX_PROGRAM_ARB) { kind = "Vertex program"; } else if (profile == GL.GL_FRAGMENT_PROGRAM_ARB) { kind = "Fragment program"; } System.out.println(kind + " failed to load:"); String errMsg = gl.glGetString(GL.GL_PROGRAM_ERROR_STRING_ARB); if (errMsg == null) { System.out.println("[No error message available]"); } else { System.out.println("Error message: \"" + errMsg + "\""); } System.out.println("Error occurred at position " + errPos[0] + " in program:"); int endPos = errPos[0]; while (endPos < programBuffer.length() && programBuffer.charAt(endPos) != '\n') { ++endPos; } System.out.println(programBuffer.substring(errPos[0], endPos)); throw new GLException("Error loading " + kind); } else { if (profile == GL.GL_FRAGMENT_PROGRAM_ARB) { int[] isNative = new int[1]; gl.glGetProgramivARB(GL.GL_FRAGMENT_PROGRAM_ARB, GL.GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, isNative, 0); if (isNative[0] != 1) { /******************************* Native limit test *******************/ System.out.println( "WARNING: fragment program is over native resource limits"); Thread.dumpStack(); } } } return res; }
/***** simple fragment code: "VolumeRenderPyramidF.ocg" ****************************/ !!FP1.0 # NV_fragment_program generated by NVIDIA Cg compiler # cgc version 1.1.0003, build date Mar 4 2003 12:32:10 # command line args: -q -profile fp30 -entry FragmentProgram #vendor NVIDIA Corporation #version 1.0.02 #profile fp30 #program FragmentProgram #semantic FragmentProgram.USTexture #semantic FragmentProgram.ColorMap #var float4 inTex : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1 #var float4 sColor0 : $vout.COLOR0 : COLOR0 : 1 : 1 #var sampler3D USTexture : : texunit 0 : 2 : 1 #var sampler1D ColorMap : : texunit 1 : 3 : 1 MOVX H0, f[TEX0]; MULX H0.z, H0.z, H0.w; TXP R0, H0, TEX0, 3D; TEX o[COLR], R0.x, TEX1, 1D; # # If you get artifacts, try this instead: # # MOVR R0, f[TEX0]; # MULR R0.z, R0.z, R0.w; # TXP R0, R0, TEX0, 3D; # TEX o[COLR], R0.x, TEX1, 1D; # END # 4 instructions, 1 R-regs, 1 H-regs. # End of program
/*** complicated fragment program: isosurface_sm3.fp *************************/ !!ARBfp1.0 OPTION NV_fragment_program2;
# Filename: volume_sm3.fp
#! VOLUME = 0 #! TRANSFERFUNCTION = 1 #! BACKGROUND = 2
# r = step # g = gradient scale # b = gradient offset # a = z-value of background plane PARAM params = program.local[0];
# r = texture coordinate scale # g = number of iterations # b = isovalue of isosurface PARAM params2 = program.local[1]; PARAM center = program.local[2]; PARAM texMax = program.local[3];
PARAM scaleFactors = program.local[5];
TEMP geomDir; TEMP geomPos; TEMP texblen; TEMP diffVec; TEMP scalar; TEMP camera; TEMP normal; TEMP temp1; TEMP temp2; TEMP temp; TEMP pos; TEMP src; TEMP dst; TEMP dir; TEMP tex;
# Compute the ray's starting point MOV geomPos, fragment.texcoord[0]; MUL pos, geomPos, scaleFactors; MOV pos.a, 0.0;
# Compute the camera position by translating the origin to the center of the # volume MOV camera, state.matrix.modelview.invtrans.row[3];
# Compute the ray direction SUB geomDir, geomPos, camera;
# Normalize the direction (done manually instead of with NRM to improve # accuracy) DP3 geomDir.w, geomDir, geomDir; RSQ geomDir.w, geomDir.w; MUL geomDir, geomDir, geomDir.w; MOV geomDir.w, 0.0;
MUL dir, geomDir, scaleFactors;
# Initialize scalar value # RGB = gradient, alpha = scalar value TXL scalar, pos, texture[0], 3D; MOV scalar.g, scalar.a; MOV scalar.a, 0.0;
# Initialize destination color MOV dst, 0.0;
# Move one step forward MAD pos, dir, params.r, pos;
REP params2.g; REP params2.g;
# Lookup new scalar value TXL tex, pos, texture[0], 3D; MOV scalar.r, tex.a;
# Lookup color in pre-int texture TXL src, scalar, texture[1], 2D;
# TODO Early ray termination (no gain of speed so far) #SUBC texblen.r, 1.0, dst.a; #BRK (LE.x);
# Perform blending SUB texblen.r, 1.0, dst.a; MAD_SAT dst, src, texblen.r, dst;
# Move one step forward MAD pos, dir, params.r, pos;
# Terminate loop if outside volume SGE temp1, pos, 0.0; SLE temp2, pos, texMax; DP3 temp1.r, temp1, temp2; SEQC temp1.r, temp1.r, 3.0; BRK (EQ.x);
# Save current scalar value MOV scalar.g, scalar.r;
ENDREP;
BRK (LE.x);
ENDREP;
# Compute the normal of the background plane (this is just the negative view # direction which initially is (0, 0, -1)) MOV normal, state.matrix.modelview.row[2];
# Compute the plane constant (we want the plane to be located in the volume # center) DP3 temp1.r, normal, center;
# Move the plane behind the volume: d' = <n,(x - l n)> = <n, x> - l <n, n>; # l = 0.71 is chosen since it is greater than half the cube diagonal DP3 temp1.g, normal, normal; MAD temp1.r, temp1.g, -.71, temp1.r;
# Compute ray parameter DP3 temp1.g, normal, geomPos; SUB temp1.g, temp1.r, temp1.g; DP3 temp1.b, normal, geomDir; DIV temp.r, temp1.g, temp1.b;
# Compute ray/plane intersection MAD temp.rgb, temp.r, geomDir, geomPos;
# Compute the difference vector SUB diffVec, temp, center;
# Compute the texture coordinates DP3 temp.r, diffVec, state.matrix.modelview.row[0]; DP3 temp.g, diffVec, state.matrix.modelview.row[1]; MUL temp.rg, temp, params2.r;
# Center background image ADD temp.rg, temp, .5;
# Look up the texel value TEX temp.rgb, temp, texture[2], 2D; MOV temp.a, 1.0;
# Blend the background pixel SUB texblen, 1.0, dst.a; MAD dst, temp, texblen.x, dst;
# Write the output color MOV result.color, dst;
END
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|