sampler3d / texture3d support?


how can i get an 3dtexture as sampler3d into the fragment shader? i can’t get the right type in jme. i’ve found the image class which can get a set of 2d images. but i can’t figure out how to bind it to the gpu/fragment shader. via the texture class?

please help me - this drives me crazy.

Did you read this:

yes, i did. but i don’t get the right way. there is no “setSampler3D()”-function (it’s mentioned in the doc that there is for every uniform a setXXX-function).

can someone give me a short code example, how to do it right?

i’ve got an 3D-float-array an need it as sampler3D on the gpu for my gpu-volume-raycaster.

thank you

You have to prefix the variable with “m_” if its a variable from a material, are you aware of that?

i understand, that i have to use the m_ prefix at the shader. but how do i have to declare the 3dtexture inside the material file an how should i assign my values inside the java-file? (which classes do i have to use?)

Material in the case of a material.

We don’t support 3D Textures for now.

Someone posted a patch once though on the forum.

I don’t think it will be enough to fully use them in a shader.

Any idea when 3d textures will be supported?

the patch is working fine!

I took a quick look at the patch, and it seems simple enough to not introduce any bugs.

We should probably add a test for it to make sure it won’t break in future revisions however.


earpnet said:
the patch is working fine!

Would you mind posting a quick example of how you used it? I'm using the patch, but having trouble setting up a 3d texture. I'm probably doing something silly, and it would really help to see something that is known to work.

yes, i will try it tomorrow if i’ve got a little more time. i had some problems to fill the byte-array used by the image-class, but now it’s working fine. i still don’t understand, why the image-class needs an arraylist of bytebuffers … my data for the 3dtexture is in a single bytebuffer. i thought that each “slice” has to be in a seperate bytebuffer, but that was not working. however, tomorrow i will post some code.

good night, folks

ok, here we go:

material-file (volcast.j3md):

[java]MaterialDef vcColor {

MaterialParameters {

Texture3D Volume


Technique {

VertexShader GLSL120: shader/vp.glsl

FragmentShader GLSL120: shader/fp.glsl

WorldParameters {





Technique FixedFunc {



main-method to load the data:


Box box= new Box(Vector3f.ZERO, 0.5f,0.5f,0.5f);

box_geo= new Geometry("box", box);

Material mat = new Material(assetManager,"shader/volcast.j3md");


Node pivot = new Node("pivot");



ArrayList<ByteBuffer> al=new ArrayList<ByteBuffer>();

byte[] b = DataLoader.load8Byte("data/fuel_64_64_64_8b.raw",64,64,64);




Image im = new Image(Format.RGBA8,64,64,64, al);

Texture3D t3 = new Texture3D(im);




mat.setTexture("Volume", t3);[/java]

and in the fragment-shader:

[java]uniform sampler3D m_Volume;

void main(void){…}


Thanks for posting the example. Unfortunately, I still can’t get it to work: I get the following on stdout:

INFO LwjglRenderer 11:47:03 PM Uniform m_VertexColor is not declared in shader.

Apr 4, 2011 11:47:03 PM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_VertexColor is not declared in shader.

And eventually, a crash:

SEVERE Application 11:47:20 PM Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.IllegalStateException: No material is set for Geometry: (-1.0, 2.0, 0.0)

at com.jme3.renderer.RenderManager.renderScene(

at com.jme3.renderer.RenderManager.renderScene(

at com.jme3.renderer.RenderManager.renderScene(

at com.jme3.renderer.RenderManager.renderViewPort(

at com.jme3.renderer.RenderManager.render(


at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(



My first guess is that I need to declare m_VertexColor in the shader, but I don’t know how to do that.

The other thing that I wonder about is the files:



Do I need those?