Tutorial: Shading a Blender Cube

https://docs.google.com/fileview?id=0B9hhZie2D-fENzE5NGY3OTctZmRmZC00NzRjLThmNTAtZWZjMjY5ODBjNzE2&hl=en links to a tutorial that demonstrates how to set up a simple shader in jME3.



Like I said, I am writing these tutorials as I figure stuff out, which very well might mean to say I have gotten it completely wrong… any chance someone in the know could vet the work?



Also, I am unsure whether I need to add the disclaimer. Java is a safe language with respect to damaging hardware, but am I being paranoid believing shaders have the power to corrupt graphics cards?



Lastly, I have been looking around for it but can’t see it anywhere, so is there any chance a piece of shading code that uses the shader to interpolate animations between (boned) keyframes could be thrown at me? I would like to work a tut up on this.

2 Likes

Dude, I love your attitude :slight_smile:



About shaders receiving other data but the “normal” opengl material data: Its not so easily possible right now, you can of course change the parameters of your material while the scenegraph is updated, its only used while rendering anyway. So some Controller class for example that modifies your material while updateLogicalState() is called should work fine for your requirements atm.



Cheers,

Normen

I think Kirill has planned hardware skinning for JME3, but it’s not in the top of the list right now.

Thanks for the reply guys. I got the idea from the cgFX platform… here is some code:

[java]

//Example 6-3. The C6E3v_keyFrame Vertex Program



void C6E3v_keyFrame(float3 positionA : POSITION,

float3 positionB : TEXCOORD1, //probably openGL spec’d gl_MultiTexCoord1

float4 color : COLOR,

float2 texCoord : TEXCOORD0,

out float4 oPosition : POSITION,

out float2 oTexCoord : TEXCOORD0,

out float4 oColor : COLOR,

uniform float keyFrameBlend,

uniform float4x4 modelViewProj)

{

/lerp is: interpolatedPos=positionA(1-time)+positionB*time; where time is calculated as time till next keyFrame should show

float3 position = lerp(positionA, positionB, keyFrameBlend);

oPosition = mul(modelViewProj, float4(position, 1));//gl_Position

oTexCoord = texCoord;//varying

oColor = color;//varying



}[/java]



They have used a vec4 texcoord to hold the position of the (vertex being processed)'s next keyframe offset. If you had an animation exported from Blender as a series of .obj files, then the offset of any vertex is calculable from the position of the same vertex in the next .obj file and can be represented as a vector. Now the position and the color and normals, etc of the vertex all exist to the shader as attributes of the vertex being shaded. Is it not possible to add a vector offset to that list? Somehow, and this is what I don’t understand, attributes of the vertex are indexed directly from the vertex being processed. Short of independently coloring every vertex of an animation. and using that color as an index into a table of such vector offsets, I can see no way of accessing any such table.

Hardware skinning will be possible when we add shader injection, right now it isn’t really feasible.


Also, I am unsure whether I need to add the disclaimer. Java is a safe language with respect to damaging hardware, but am I being paranoid believing shaders have the power to corrupt graphics cards?

I never heard of this happening.
The closest thing I heard about was games which don't limit their fps causing video cards to overheat and cause the video card to break permanently. Overclocking can cause the same issue as well.
Shaders too can cause video cards to overheat if they do a very complex operation, but then the driver should just crash in that case, so this really shouldn't happen.