@@ -5347,7 +5347,33 @@ static Model LoadGLTF(const char *fileName)
5347
5347
Image imMetallicRoughness = LoadImageFromCgltfImage (data -> materials [i ].pbr_metallic_roughness .metallic_roughness_texture .texture -> image , texPath );
5348
5348
if (imMetallicRoughness .data != NULL )
5349
5349
{
5350
- model .materials [j ].maps [MATERIAL_MAP_ROUGHNESS ].texture = LoadTextureFromImage (imMetallicRoughness );
5350
+ Image imMetallic , imRoughness ;
5351
+
5352
+ imMetallic .data = RL_MALLOC (imMetallicRoughness .width * imMetallicRoughness .height );
5353
+ imRoughness .data = RL_MALLOC (imMetallicRoughness .width * imMetallicRoughness .height );
5354
+
5355
+ imMetallic .width = imRoughness .width = imMetallicRoughness .width ;
5356
+ imMetallic .height = imRoughness .height = imMetallicRoughness .height ;
5357
+
5358
+ imMetallic .format = imRoughness .format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE ;
5359
+ imMetallic .mipmaps = imRoughness .mipmaps = 1 ;
5360
+
5361
+ for (int x = 0 ; x < imRoughness .width ; x ++ ) {
5362
+ for (int y = 0 ; y < imRoughness .height ; y ++ ) {
5363
+ Color color = GetImageColor (imMetallicRoughness , x , y );
5364
+
5365
+ Color roughness = (Color ) {color .g };
5366
+ Color metallic = (Color ) {color .b };
5367
+
5368
+ ((unsigned char * )imRoughness .data )[y * imRoughness .width + x ] = color .g ;
5369
+ ((unsigned char * )imMetallic .data )[y * imMetallic .width + x ] = color .b ;
5370
+ }
5371
+ }
5372
+ model .materials [j ].maps [MATERIAL_MAP_ROUGHNESS ].texture = LoadTextureFromImage (imRoughness );
5373
+ model .materials [j ].maps [MATERIAL_MAP_METALNESS ].texture = LoadTextureFromImage (imMetallic );
5374
+
5375
+ UnloadImage (imRoughness );
5376
+ UnloadImage (imMetallic );
5351
5377
UnloadImage (imMetallicRoughness );
5352
5378
}
5353
5379
0 commit comments