Browse Source

Added normal and specular maps logic to standard...

...shader and updated example.
victorfisac 9 years ago
parent
commit
0ff26f527f
1 changed files with 15 additions and 8 deletions
  1. 15 8
      examples/shaders_standard_lighting.c

+ 15 - 8
examples/shaders_standard_lighting.c

@@ -22,8 +22,8 @@ int main()
 {
 {
     // Initialization
     // Initialization
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
-    int screenWidth = 800;
-    int screenHeight = 450;
+    int screenWidth = 1280;
+    int screenHeight = 720;
     
     
     SetConfigFlags(FLAG_MSAA_4X_HINT);      // Enable Multi Sampling Anti Aliasing 4x (if available)
     SetConfigFlags(FLAG_MSAA_4X_HINT);      // Enable Multi Sampling Anti Aliasing 4x (if available)
 
 
@@ -36,13 +36,18 @@ int main()
     Model dwarf = LoadModel("resources/model/dwarf.obj");                   // Load OBJ model
     Model dwarf = LoadModel("resources/model/dwarf.obj");                   // Load OBJ model
 
 
     Material material = LoadStandardMaterial();
     Material material = LoadStandardMaterial();
+    
     material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model diffuse texture
     material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model diffuse texture
+    material.texNormal = LoadTexture("resources/model/dwarf_normal.png"); // Load model normal texture
+    material.texSpecular = LoadTexture("resources/model/dwarf_specular.png"); // Load model specular texture
     material.colDiffuse = (Color){255, 255, 255, 255};
     material.colDiffuse = (Color){255, 255, 255, 255};
     material.colAmbient = (Color){0, 0, 10, 255};
     material.colAmbient = (Color){0, 0, 10, 255};
     material.colSpecular = (Color){255, 255, 255, 255};
     material.colSpecular = (Color){255, 255, 255, 255};
     material.glossiness = 50.0f;
     material.glossiness = 50.0f;
     
     
     dwarf.material = material;      // Apply material to model
     dwarf.material = material;      // Apply material to model
+    
+    Model dwarf2 = LoadModel("resources/model/dwarf.obj");                   // Load OBJ model
 
 
     Light spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255});
     Light spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255});
     spotLight->target = (Vector3){0.0f, 0.0f, 0.0f};
     spotLight->target = (Vector3){0.0f, 0.0f, 0.0f};
@@ -58,12 +63,14 @@ int main()
     Light pointLight = CreateLight(LIGHT_POINT, (Vector3){0.0f, 4.0f, 5.0f}, (Color){255, 255, 255, 255});
     Light pointLight = CreateLight(LIGHT_POINT, (Vector3){0.0f, 4.0f, 5.0f}, (Color){255, 255, 255, 255});
     pointLight->intensity = 2.0f;
     pointLight->intensity = 2.0f;
     pointLight->diffuse = (Color){100, 100, 255, 255};
     pointLight->diffuse = (Color){100, 100, 255, 255};
-    pointLight->attenuation = 3.0f;
+    pointLight->radius = 3.0f;
 
 
     // Setup orbital camera
     // Setup orbital camera
-    SetCameraMode(CAMERA_ORBITAL);          // Set a orbital camera mode
+    SetCameraMode(CAMERA_ORBITAL);          // Set an orbital camera mode
     SetCameraPosition(camera.position);     // Set internal camera position to match our camera position
     SetCameraPosition(camera.position);     // Set internal camera position to match our camera position
     SetCameraTarget(camera.target);         // Set internal camera target to match our camera target
     SetCameraTarget(camera.target);         // Set internal camera target to match our camera target
+    
+    float framesCounter = 0;                // Define frames counter to update model rotation
 
 
     SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
     SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
@@ -74,6 +81,8 @@ int main()
         // Update
         // Update
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
         UpdateCamera(&camera);              // Update internal camera and our camera
         UpdateCamera(&camera);              // Update internal camera and our camera
+        
+        framesCounter += 0.5f;
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
 
 
         // Draw
         // Draw
@@ -83,8 +92,8 @@ int main()
             ClearBackground(RAYWHITE);
             ClearBackground(RAYWHITE);
 
 
             Begin3dMode(camera);
             Begin3dMode(camera);
-
-                DrawModel(dwarf, position, 2.0f, WHITE);   // Draw 3d model with texture
+                
+                DrawModelEx(dwarf, position, (Vector3){ 0.0f, 1.0f, 0.0f }, framesCounter, (Vector3){ 2.0f, 2.0f, 2.0f}, RED);   // Draw 3d model with texture
                 
                 
                 DrawLights();   // Draw all created lights in 3D world
                 DrawLights();   // Draw all created lights in 3D world
 
 
@@ -94,8 +103,6 @@ int main()
             
             
             DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
             DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
 
 
-            DrawFPS(10, 10);
-
         EndDrawing();
         EndDrawing();
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
     }
     }