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

Changed things to implement correct usage of RMA (or MRA) textures #4678

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions examples/shaders/shaders_basic_pbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else // PLATFORM_ANDROID, PLATFORM_WEB
#define GLSL_VERSION 100
#define GLSL_VERSION 120
raysan5 marked this conversation as resolved.
Show resolved Hide resolved
#endif

#include <stdlib.h> // Required for: NULL
Expand Down Expand Up @@ -143,10 +143,17 @@ int main()
car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.0f;
car.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
car.materials[0].maps[MATERIAL_MAP_EMISSION].color = (Color){ 255, 162, 0, 255 };

// Setup materials[0].maps default textures
car.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = LoadTexture("resources/old_car_d.png");
car.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/old_car_mra.png");

//Load RMA texture and convert it to an image to extract channels
Texture2D carTexture=LoadTexture("resources/old_car_mra.png");
Image carImage =LoadImageFromTexture(carTexture);
//RMA textures -> R corresponds to Roughness, G to Metalness, and B to Occlusion
//Using different channels of RMA map for different parameters
car.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTextureFromImage(ImageFromChannel(carImage,1));
car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = LoadTextureFromImage(ImageFromChannel(carImage,0));
car.materials[0].maps[MATERIAL_MAP_OCCLUSION].texture = LoadTextureFromImage(ImageFromChannel(carImage,2));
car.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/old_car_n.png");
car.materials[0].maps[MATERIAL_MAP_EMISSION].texture = LoadTexture("resources/old_car_e.png");

Expand All @@ -165,9 +172,14 @@ int main()
floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.0f;
floor.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
floor.materials[0].maps[MATERIAL_MAP_EMISSION].color = BLACK;

floor.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = LoadTexture("resources/road_a.png");
floor.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/road_mra.png");

Texture2D floorTexture=LoadTexture("resources/road_mra.png");
Image floorImage=LoadImageFromTexture(floorTexture);
//Using different channels of RMA map for different parameters
floor.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTextureFromImage(ImageFromChannel(floorImage,1));
floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = LoadTextureFromImage(ImageFromChannel(floorImage,0));
floor.materials[0].maps[MATERIAL_MAP_OCCLUSION].texture = LoadTextureFromImage(ImageFromChannel(floorImage,2));
floor.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/road_n.png");

// Models texture tiling parameter can be stored in the Material struct if required (CURRENTLY NOT USED)
Expand Down Expand Up @@ -199,7 +211,7 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL);

//if (IsKeyPressedRepeat(KEY_RIGHT)){UpdateCamera(&camera,CAMERA_ORBITAL);};
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
float cameraPos[3] = {camera.position.x, camera.position.y, camera.position.z};
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
Expand Down Expand Up @@ -261,8 +273,14 @@ int main()

// De-Initialization
//--------------------------------------------------------------------------------------
UnloadImage(floorImage);
UnloadTexture(floorTexture);
UnloadImage(carImage);
UnloadTexture(carTexture);
// Unbind (disconnect) shader from car.material[0]
// to avoid UnloadMaterial() trying to unload it automatically


car.materials[0].shader = (Shader){ 0 };
UnloadMaterial(car.materials[0]);
car.materials[0].maps = NULL;
Expand Down