Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[examples] Update shaders_mesh_instancing, binding matrix location #4723

Closed
wants to merge 1 commit into from

Conversation

MikiZX1
Copy link
Contributor

@MikiZX1 MikiZX1 commented Jan 24, 2025

Due to this missing line of code the example seems is not going to work: shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform");

Due to this missing line of code the example seems is not going to work:
shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform");
@MikiZX1
Copy link
Contributor Author

MikiZX1 commented Jan 24, 2025

Hi Ray,
I just saw we did this alread in 'Update shaders_mesh_instancing.c #4689 '
But users on discord keep reporting this line is fixing the issue they have. You maybe mean the 'MVP' is automatically sent to the shader? Anyway, sorry for this double PR, I'm leaving it as is... you will know better what to do.

@raysan5
Copy link
Owner

raysan5 commented Jan 25, 2025

@MikiZX1 I think there is some confusion here, I tried compiling the example with GCC 14 and VS2022, on Windows 10 and it works as expected.

image

image

Please, could you provide the details on the environment it fails?

@raysan5 raysan5 changed the title Update shaders_mesh_instancing.c [examples] Update shaders_mesh_instancing, binding matrix location Jan 25, 2025
@raysan5
Copy link
Owner

raysan5 commented Jan 25, 2025

Reviewed the issue carefully and as per my understanding that line is not needed, DrawMeshInstanced() binds the instancing matrix data to SHADER_LOC_VERTEX_INSTANCE_TX, that is actually the location point used by that function.

SHADER_LOC_MATRIX_MODEL is not used by DrawMeshInstanced().

Please, correct me if I'm missing some point.

@raysan5 raysan5 closed this Jan 25, 2025
@MikiZX1
Copy link
Contributor Author

MikiZX1 commented Jan 26, 2025

Hello Ray,
You must be right, I just report what I'm told makes the example work.

If you wish to triple check, please have a look here:
https://github.com/raysan5/raylib/blob/139de05e9d68145422b0d625c23a7d7505b8762b/examples/shaders/resources/shaders/glsl330/lighting_instancing.vs#L9C4-L9C8

-'instanceTransform' is the name used in the glsl shader and as far I know raylib does not obtain the glsl location of 'instanceTransform' automatically?
-I haven't checked deeply but I believe the function rlLoadVertexBuffer does not obtain the glsl location of the attribute 'instanceTransform' either.

I'll dig into source to find this (at this time I don't understand where is the glsl identifier 'instanceTransform' linked with the corresponding OpenGL storage by raylib)?

Since it is not done by raylib, the example needs to do it itself. (I currently believe this)

I cannot tell why it works for you. At this time it appears like undefined behavior to me.
Again, I am not able to understand what is happening so please forgive me, I'll do my best not to waste your time in the future, especially now during these months during which you are working on the university as well. It is definitively not my place to correct you.

Thanks for all!
Best wishes,
Miki

@MikiZX1
Copy link
Contributor Author

MikiZX1 commented Jan 26, 2025

I've just gone through the repo and I do see what you mean. The location of 'instanceTransform' is obtained by rcore.h and rlgl.h
So I don't understand what is going on here. OK to close the issue, I will try understand better what is happening. Maybe the users reporting the issue were using an older version of raylib. idk
Sorry for the trouble and thanks for all.
Kind regards
Miki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants