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

[rmodels] DrawMesh uses SHADER_LOC_COLOR_SPECULAR as a material map index #2908

Closed
3 tasks done
haved opened this issue Feb 4, 2023 · 1 comment · Fixed by #2909
Closed
3 tasks done

[rmodels] DrawMesh uses SHADER_LOC_COLOR_SPECULAR as a material map index #2908

haved opened this issue Feb 4, 2023 · 1 comment · Fixed by #2909

Comments

@haved
Copy link
Contributor

haved commented Feb 4, 2023

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • My code has no errors or misuse of raylib

Issue description

In rmodels.c, the DrawMesh function tries to upload the material's specular color, if the shader has a uniform in shader.locs[SHADER_LOC_COLOR_SPECULAR]. The problem is that the material map should be material.maps[MATERIAL_MAP_SPECULAR], but maps[SHADER_LOC_COLOR_SPECULAR] is used instead, which isn't a real material map.

See the source code in question here:

raylib/src/rmodels.c

Lines 1373 to 1383 in 589892a

if (material.shader.locs[SHADER_LOC_COLOR_SPECULAR] != -1)
{
float values[4] = {
(float)material.maps[SHADER_LOC_COLOR_SPECULAR].color.r/255.0f,
(float)material.maps[SHADER_LOC_COLOR_SPECULAR].color.g/255.0f,
(float)material.maps[SHADER_LOC_COLOR_SPECULAR].color.b/255.0f,
(float)material.maps[SHADER_LOC_COLOR_SPECULAR].color.a/255.0f
};
rlSetUniform(material.shader.locs[SHADER_LOC_COLOR_SPECULAR], values, SHADER_UNIFORM_VEC4, 1);
}

Environment

Linux, OpenGL 3.3. The code in question is within

#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)

Issue Screenshot

I got random specular colors every time I ran my program, but didn't take screenshots

Code Example

Shader shader = LoadShader("res/model.vs", "res/model.fs");
shader.locs[SHADER_LOC_COLOR_SPECULAR] = GetShaderLocation(shader, "colSpecular");

Model model = LoadModel("res/model.glb");
model.materials[0].shader = shader;

// This line ends up doing nothing
model.materials[0].maps[MATERIAL_MAP_SPECULAR].color = {200, 200, 200};

// Within gameloop
DrawModel(model, {0, 0, 0}, 1.0f, WHITE);
@raysan5
Copy link
Owner

raysan5 commented Feb 5, 2023

@haved Good catch! Thanks for the fix!

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 a pull request may close this issue.

2 participants