aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2017-07-21 09:34:09 +0200
committerraysan5 <raysan5@gmail.com>2017-07-21 09:34:09 +0200
commit2679c4ae9b2fefdb0c150a7cd576d5d3297b027b (patch)
tree31f026ec3d4a0f3a49ecddaa5d9431b61b56de7f /examples
parent63fd96354e7ceffcdf292a1aac6d564dc694377c (diff)
downloadraylib-2679c4ae9b2fefdb0c150a7cd576d5d3297b027b.tar.gz
raylib-2679c4ae9b2fefdb0c150a7cd576d5d3297b027b.zip
Review mesh loading and textures generation
Diffstat (limited to 'examples')
-rw-r--r--examples/models/models_cubicmap.c2
-rw-r--r--examples/models/models_material_pbr.c5
-rw-r--r--examples/models/models_skybox.c31
3 files changed, 20 insertions, 18 deletions
diff --git a/examples/models/models_cubicmap.c b/examples/models/models_cubicmap.c
index 177cf890..268d480a 100644
--- a/examples/models/models_cubicmap.c
+++ b/examples/models/models_cubicmap.c
@@ -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
diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c
index f443e245..d55aa773 100644
--- a/examples/models/models_material_pbr.c
+++ b/examples/models/models_material_pbr.c
@@ -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);
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index d347854f..500cb19b 100644
--- a/examples/models/models_skybox.c
+++ b/examples/models/models_skybox.c
@@ -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