Review mesh loading and textures generation

This commit is contained in:
raysan5 2017-07-21 09:34:09 +02:00
parent 63fd96354e
commit 2679c4ae9b
6 changed files with 49 additions and 34 deletions

View file

@ -27,7 +27,7 @@ int main()
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f });
Model model = LoadModelFromMesh(mesh, false);
Model model = LoadModelFromMesh(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture

View file

@ -142,6 +142,11 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
Shader shdrIrradiance = LoadShader(PATH_SKYBOX_VS, PATH_IRRADIANCE_FS);
Shader shdrPrefilter = LoadShader(PATH_SKYBOX_VS, PATH_PREFILTER_FS);
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
// Setup required shader locations
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1);
SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1);
Texture2D texHDR = LoadTexture("resources/pinetree.hdr");
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);

View file

@ -24,24 +24,24 @@ int main()
// Define the camera to look into our 3d world
Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
// Load skybox model and shader
// Load skybox model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube, false);
Model skybox = LoadModelFromMesh(cube);
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
Texture2D texHDR = LoadTexture("resources/pinetree.hdr");
skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(texHDR, 512);
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
// Get skybox shader locations
skybox.material.shader.locs[LOC_MATRIX_PROJECTION] = GetShaderLocation(skybox.material.shader, "projection");
skybox.material.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(skybox.material.shader, "view");
// Then before rendering, configure the viewport to the actual screen dimensions
Matrix proj = MatrixPerspective(60.0, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0);
MatrixTranspose(&proj);
SetShaderValueMatrix(skybox.material.shader, skybox.material.shader.locs[LOC_MATRIX_PROJECTION], proj);
// Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "environmentMap"), (int[1]){ 0 }, 1);
Texture2D texHDR = LoadTexture("resources/pinetree.hdr");
skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
UnloadShader(shdrCubemap); // Cubemap generation shader not required any more
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@ -53,9 +53,6 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
Matrix view = MatrixLookAt(camera.position, camera.target, camera.up);
SetShaderValueMatrix(skybox.material.shader, skybox.material.shader.locs[LOC_MATRIX_VIEW], view);
//----------------------------------------------------------------------------------
// Draw