GLSLShader pass matrix array

Started by kkl, May 28, 2014, 06:05:43 PM

Previous topic - Next topic

kkl

Hi Egon,

Is it possible for you to add in passing matrix array to shader? I'm trying to implement hardware skinning and the input is matrix array. Some inputs are in 2 dimensional array too and I guess shader does not support it, right?

EgonOlsen

Should be possible. I guess it's not in there, because nobody ever needed it. I'll look into it.
Keep in mind that you will need vertex attributes as well. You'll find them in the Mesh class, not in GLSLShader...just in case that you haven't noticed them yet.


kkl

QuoteKeep in mind that you will need vertex attributes as well. You'll find them in the Mesh class, not in GLSLShader...just in case that you haven't noticed them yet.
You're right. Initially I thought of using the 'uniform' to pass the values, but I guess it doesn't work that way. I need to use VertexAttributes instead, is that right? In this case, is it possible to pass matrix via VertexAttributes? All I can think of is passing 4 float[4] to reconstruct those values to a matrix in shader as a workaround.

EgonOlsen

No, vertex atttributes can only be vectors. You can pass three of them to form a matrix. Or pass all the matrices as uniforms and an index into that array as an attribute. Should work, but might be slower.

kkl

#5
I think I'll pass the matrices via uniform since they have constant 4 matrix palettes for skin animation, if I'm not wrong. BTW, can I have a jpct java version with GLSLShader matrix passing in it so I can debug the shader in pc? Im figuring out how to use glslDevil to debug. Is there any good recommendation for glsl debugger for either Android or pc?

kkl

Hi Egon,

Is it doable to pass dynamic matrix array to shader? It seems like in shader, we have to specify a fixed number of matrix uniform array size and pass values only within that limit. Is it true?

EgonOlsen

Yes, that's how it is. But you might use an array that "big enough" and don't fill it completely.

kkl

Hi Egon,

Sry to bring this up. I shared the the same shader with multiple objects and they pass different length of matrix array, but it causes an error


09-01 13:41:50.153: E/AndroidRuntime(27402): FATAL EXCEPTION: GLThread 35538
09-01 13:41:50.153: E/AndroidRuntime(27402): java.lang.ArrayIndexOutOfBoundsException: length=144; index=144
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.GLSLShader$Uniform.setValue(GLSLShader.java:1340)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.GLSLShader.set(GLSLShader.java:1025)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.GLSLShader.setUniform(GLSLShader.java:582)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.kisionlab.oceanblue3d.objects.TurtleScene$1.beforeRendering(TurtleScene.java:107)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:467)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2314)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.World.draw(World.java:1361)
09-01 13:41:50.153: E/AndroidRuntime(27402): at com.threed.jpct.World.draw(World.java:1099)


Is GLSLShader not meant to be shared among other objects?

EgonOlsen

You should be able to share them. I'll look into this...

EgonOlsen

It's a simple problem, i'll fix it this evening. However, by fixing this, your code will work but you'll create a new array instance each time you alter the length. It might be a better idea to create individual instances of GLSLShader for different array lengths to avoid this. Or isn't that an option?

kkl

Yea, I could do that with the individual instances GLSLShader. Does it cost more in switching the shader program? If the cost is high, is it possible to point the matrix object to shader instead of creating new array instance in GLSLShader (mayb I can convert matrix to float array manually and pass into shader)?

EgonOlsen

The costs shouldn't be too high. Objects will be sorted by state anyway, so objects using the same combination of texture/shader will be batched together. I don't think that it will be noticable.

kkl

It should be ok then, thanks alot ; ).  Just that I worry that it will consume CPU at backend, expecially for live wallpaper. It just drain battery REAL fast if some CPU cycles are wasted.