Browse Source

First working build on windows.

Angel Ortiz 7 years ago
parent
commit
015d7202cf
3 changed files with 12 additions and 8 deletions
  1. 2 1
      include/buffer.h
  2. 7 6
      include/shader.h
  3. 3 1
      src/displayManager.cpp

+ 2 - 1
include/buffer.h

@@ -7,6 +7,7 @@
 // ===============================
 
 #include "SDL.h"
+#include <cstring>
 #include <type_traits>
 
 //Templated struct to emulate GPU buffers such as 
@@ -41,7 +42,7 @@ struct Buffer{
             }
 			else{
 				//Set to a 15% white color to make it nicer looking.
-				memset(buffer,0xD, mPitch*mHeight);       
+				std::memset(buffer,0xD, mPitch*mHeight);       
 			}
         }
 };

+ 7 - 6
include/shader.h

@@ -18,6 +18,9 @@
 #include "matrix.h"
 #include "texture.h"
 #include <math.h>
+#ifndef M_PI
+    #define M_PI 3.14159265358979323846f
+#endif
 
 //Shader Interface for a class that emulates modern GPU fragment and vertex shaders
 struct IShader {
@@ -311,7 +314,7 @@ struct PBRShader : public IShader {
         float NdotH2 = NdotH*NdotH;
         
         float denom = (NdotH2 * (a2 - 1.0f) + 1.0f);
-        denom =  M_1_PIf32/ (denom * denom);
+        denom =  1.0f/ (M_PI * denom * denom);
         
         return a2 * denom;
     }
@@ -378,8 +381,8 @@ struct PBRShader : public IShader {
         const int maxLights = numLights;
 
         //Fresnel, normal distribution function and geometry occlusion 
-        Vector3f* F = new Vector3f[maxLights];
-        float*  NDF = new float[maxLights];
+        Vector3f F[maxLights];
+        float  NDF[maxLights];
         float  G[maxLights];
         
         //Storing in array for vectorizing
@@ -422,7 +425,7 @@ struct PBRShader : public IShader {
             kD[light] = (Vector3f(1.0f) - F[light])*invMetal;
 
             //The rendering equation result for a given light
-            radianceLights[light] = (kD[light] * (interpCol * (M_1_PIf32)) + specular[light] ) * nDotL[light] * lightCol[light];
+            radianceLights[light] = (kD[light] * (interpCol * (1/ M_PI)) + specular[light] ) * nDotL[light] * lightCol[light];
         }
 
         //Summing up all radiance values since SIMD won't work if I do this within the
@@ -435,8 +438,6 @@ struct PBRShader : public IShader {
         //Simplistic ambient term
         ambient =  interpCol * (ambientInt * interpAO);
 
-        delete [] F;
-
         return ambient + radianceOut;
     }
     

+ 3 - 1
src/displayManager.cpp

@@ -5,6 +5,8 @@
 
 //Includes
 #include "displayManager.h"
+#include <cstdio>
+#include <cstring>
 
 //Dummy constructors/destructors
 DisplayManager::DisplayManager(){}
@@ -45,7 +47,7 @@ void DisplayManager::swapBuffers(Buffer<Uint32> *pixels){
     SDL_LockSurface(mSurface);
 
     //Copy pixels buffer resuls to screen surface
-    memcpy(mSurface->pixels, pixels->buffer, pixels->mHeight*pixels->mPitch);
+    std::memcpy(mSurface->pixels, pixels->buffer, pixels->mHeight*pixels->mPitch);
     SDL_UnlockSurface(mSurface);
 
     //Apply surface changes to window