Why is Random Tint Hands not working?

I have loaded 3 glTF models for instancing and constructed a few button click handlers to generate some characters, randomly tint the bodies, and randomly tint the hands. However, the hands are not being tinted when the button is clicked.

I set the uv_offset of the hands to (2. , 2.) in order to do some branching in the fragment shader.

if(vUV.x>1.){
    gl_FragColor = texture2D(headTexSampler,vec2(.5,.5)) - vec4(vNormal/8.,0.);
    if(vTint.r>0.) gl_FragColor = vec4(vNormal * vTint, 1.);
}

This is more of a learning exercise than anything. My shader(s) would be significantly different otherwise. Nonetheless, the instancedBuffer.tint attribute seems to be set and updates just fine for the head and body , yet not for the hands. I am perplexed.

Here is a playground.

You are messing badly with the handedness of the meshes by doing scale.x = -1: you should not need to do that, you should instead fix your meshes in your DCC tool.

To somewhat correct the problem, you should also set a scale.x = -1 on the left/right hand, else the system can’t make real instances (meaning a single draw call for all instances - one draw call will be issued for each mesh) and the instanced buffers are not taken into account when drawing those meshes:

https://playground.babylonjs.com/#4DM30C#21

[EDIT]
Another (better) way to fix the problem is to set scene.useRightHandedSystem = true and remove the -1 scaling:

https://playground.babylonjs.com/#4DM30C#22
[/EDIT]

1 Like

Thanks a bunch @Evgeni_Popov ! I know I’m just goofing around here. I am very impressed by the system. I just have to avoid tripping over my own feet. I wish a most rewarding week! :pray:

If I am required to use the left handed system, what would be the best fix to apply in a DCC tool?

I guess you should apply the x scaling directly on your meshes in the DCC tool, but I have never used one, so I may miss something here.

1 Like