Skip to content

Instantly share code, notes, and snippets.

@kayru
Created August 13, 2012 22:27
Show Gist options
  • Save kayru/3344506 to your computer and use it in GitHub Desktop.
Save kayru/3344506 to your computer and use it in GitHub Desktop.
How to compile BRDF viewer for Windows
How to compile BRDF Explorer for Windows
========================================
Use this code https://github.com/wdas/brdf.git
The following external dependencies are required (versions are ones that I used, other might also work):
- Qt 4.8.1
- GLEW 1.9.0
- ZLib 1.2.5
- GLUT 3.7
All external dependencies except Qt are packaged here: https://dl.dropbox.com/u/1010228/brdf-depends-win32.zip
Make sure that qmake is in your PATH. Also put GLEW, ZLib and GLUT include and library directories somewhere VC can find them.
Use Visual Studio 2010 command prompt. Navigate to "brdf/src/brdf" directory and run "qmake -tp vc", this will generate the vcxproj file.
Navigate to "brdf" directory and run "qmake -tp vc", this will generate sln file. Apply the included patch, open sln file and build.
Patch
=====
diff --git a/.gitignore b/.gitignore
index 9901d63..8043907 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,16 @@
moc_*
Makefile
Linux-*
+*.dll
+*.exe
+*.filters
+*.ipch
+*.opensdf
+*.pdb
+*.sdf
+*.sln
+*.suo
+*.user
+*.vcxproj
+src/brdf/release
+src/brdf/debug
diff --git a/src/brdf/IBLWidget.cpp b/src/brdf/IBLWidget.cpp
index c693d31..9f6e7a0 100644
--- a/src/brdf/IBLWidget.cpp
+++ b/src/brdf/IBLWidget.cpp
@@ -45,7 +45,6 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include <stdlib.h>
@@ -208,8 +207,8 @@ void IBLWidget::randomizeSampleGroupOrder()
// now swap random elements a bunch of times to shuffle the pass order
for( int i = 0; i < stepSize*100; i++ )
{
- int a = random() % stepSize;
- int b = random() % stepSize;
+ int a = rand() % stepSize;
+ int b = rand() % stepSize;
int temp = sampleGroupOrder[a];
sampleGroupOrder[a] = sampleGroupOrder[b];
sampleGroupOrder[b] = temp;
@@ -446,8 +445,8 @@ void IBLWidget::mouseMoveEvent( QMouseEvent* event )
int d = abs(dx) > abs(dy) ? dx : dy;
lookZoom -= float(d) * lookZoom * 0.05;
- lookZoom = fmaxf( lookZoom, 0.01f );
- lookZoom = fminf( lookZoom, 100.0f );
+ lookZoom = std::max<float>( lookZoom, 0.01f );
+ lookZoom = std::min<float>( lookZoom, 100.0f );
}
@@ -744,7 +743,7 @@ void IBLWidget::loadIBL( const char* filename )
printf( "opening %s\n", filename );
// try and load it
- std::string error;
+ Ptex::String error;
PtexTexture* tx = PtexTexture::open(filename, error);
if (!tx) return;
diff --git a/src/brdf/ImageSliceWidget.cpp b/src/brdf/ImageSliceWidget.cpp
index 4dda533..6448aba 100644
--- a/src/brdf/ImageSliceWidget.cpp
+++ b/src/brdf/ImageSliceWidget.cpp
@@ -45,7 +45,6 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include "DGLShader.h"
@@ -218,8 +217,8 @@ void ImageSliceWidget::mouseMoveEvent(QMouseEvent *event)
{
int d = abs(dx) > abs(dy) ? dx : dy;
scaleX += float(d) * scaleX * 0.05;
- scaleX = fmaxf( scaleX, 0.01 );
- scaleX = fminf( scaleX, 50.0 );
+ scaleX = std::max<float>( scaleX, 0.01 );
+ scaleX = std::min<float>( scaleX, 50.0 );
}
// control+right adjusts the x-scale of the graph
@@ -227,8 +226,8 @@ void ImageSliceWidget::mouseMoveEvent(QMouseEvent *event)
{
int d = abs(dx) > abs(dy) ? dx : dy;
scaleY += float(d) * scaleY * 0.05;
- scaleY = fmaxf( scaleY, 0.01 );
- scaleY = fminf( scaleY, 50.0 );
+ scaleY = std::max<float>( scaleY, 0.01 );
+ scaleY = std::min<float>( scaleY, 50.0 );
}
// left mouse button adjusts the viewing dir
@@ -248,8 +247,8 @@ void ImageSliceWidget::mouseMoveEvent(QMouseEvent *event)
int d = abs(dx) > abs(dy) ? dx : dy;
lookZoom -= float(d) * lookZoom * 0.05;
- lookZoom = fmaxf( lookZoom, 0.01f );
- lookZoom = fminf( lookZoom, 50.0f );
+ lookZoom = std::max<float>( lookZoom, 0.01f );
+ lookZoom = std::min<float>( lookZoom, 50.0f );
}
diff --git a/src/brdf/LitSphereWidget.cpp b/src/brdf/LitSphereWidget.cpp
index e7998fe..16b7180 100644
--- a/src/brdf/LitSphereWidget.cpp
+++ b/src/brdf/LitSphereWidget.cpp
@@ -45,7 +45,6 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include "DGLShader.h"
diff --git a/src/brdf/Plot3DWidget.cpp b/src/brdf/Plot3DWidget.cpp
index f5da6e7..ea704df 100644
--- a/src/brdf/Plot3DWidget.cpp
+++ b/src/brdf/Plot3DWidget.cpp
@@ -45,13 +45,15 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include "DGLShader.h"
#include "Plot3DWidget.h"
#include "geodesicHemisphere.h"
+#ifndef M_PI_2
+#define M_PI_2 1.57079632679489661923
+#endif //M_PI_2
Plot3DWidget::Plot3DWidget( QWidget *parent, std::vector<brdfPackage> bList )
: SharedContextGLWidget(parent)
@@ -164,8 +166,8 @@ void Plot3DWidget::paintGL()
// try and set some better viewing planes based on zoom factor... this only kinda works
- float nearPlane = fminf( lookZoom*0.1, 0.5 );
- float farPlane = fminf( lookZoom*10.0, 100.0 );
+ float nearPlane = std::min<float>( lookZoom*0.1, 0.5 );
+ float farPlane = std::min<float>( lookZoom*10.0, 100.0 );
glMatrixMode(GL_PROJECTION);
@@ -294,8 +296,8 @@ void Plot3DWidget::mouseMoveEvent(QMouseEvent *event)
int d = abs(dx) > abs(dy) ? dx : dy;
lookZoom -= float(d) * lookZoom * 0.05;
- lookZoom = fmaxf( lookZoom, 0.01f );
- lookZoom = fminf( lookZoom, 100.0f );
+ lookZoom = std::max<float>( lookZoom, 0.01f );
+ lookZoom = std::min<float>( lookZoom, 100.0f );
}
@@ -351,7 +353,7 @@ void Plot3DWidget::makeGeodesicHemisphereVBO()
int memIndex = 0;
// allocate enough memory for all the vertices in the hemisphere
- numTrianglesInHemisphere = 40 * int(pow(4.0, float(numSubdivisions)));
+ numTrianglesInHemisphere = 40 * int(powf(4.0, float(numSubdivisions)));
hemisphereVertices = new float[ numTrianglesInHemisphere * 3 * 3 ];
//printf( "numTrianglesInHemisphere: %d\n", numTrianglesInHemisphere );
diff --git a/src/brdf/PlotCartesianWidget.cpp b/src/brdf/PlotCartesianWidget.cpp
index 65b3f49..397338f 100644
--- a/src/brdf/PlotCartesianWidget.cpp
+++ b/src/brdf/PlotCartesianWidget.cpp
@@ -45,7 +45,6 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include "DGLShader.h"
@@ -362,8 +361,8 @@ void PlotCartesianWidget::mouseMoveEvent(QMouseEvent *event)
{
int d = abs(dx) > abs(dy) ? dx : dy;
scaleX += float(d) * scaleX * 0.05;
- scaleX = fmaxf( scaleX, 0.01 );
- scaleX = fminf( scaleX, 50.0 );
+ scaleX = std::max<float>( scaleX, 0.01 );
+ scaleX = std::min<float>( scaleX, 50.0 );
}
// control+right adjusts the x-scale of the graph
@@ -371,8 +370,8 @@ void PlotCartesianWidget::mouseMoveEvent(QMouseEvent *event)
{
int d = abs(dx) > abs(dy) ? dx : dy;
scaleY += float(d) * scaleY * 0.05;
- scaleY = fmaxf( scaleY, 0.01 );
- scaleY = fminf( scaleY, 50.0 );
+ scaleY = std::max<float>( scaleY, 0.01 );
+ scaleY = std::min<float>( scaleY, 50.0 );
}
// left mouse button adjusts the viewing dir
@@ -393,8 +392,8 @@ void PlotCartesianWidget::mouseMoveEvent(QMouseEvent *event)
int d = abs(dx) > abs(dy) ? dx : dy;
lookZoom -= float(d) * lookZoom * 0.05;
- lookZoom = fmaxf( lookZoom, 0.01f );
- lookZoom = fminf( lookZoom, 50.0f );
+ lookZoom = std::max<float>( lookZoom, 0.01f );
+ lookZoom = std::min<float>( lookZoom, 50.0f );
}
diff --git a/src/brdf/PlotPolarWidget.cpp b/src/brdf/PlotPolarWidget.cpp
index ef6836e..2ac6bba 100644
--- a/src/brdf/PlotPolarWidget.cpp
+++ b/src/brdf/PlotPolarWidget.cpp
@@ -45,7 +45,6 @@ infringement.
#include <GL/glew.h>
#include <QtGui>
-#include <QtOpenGL>
#include <QString>
#include <math.h>
#include "DGLShader.h"
@@ -251,8 +250,8 @@ void PlotPolarWidget::mouseMoveEvent(QMouseEvent *event)
int d = abs(dx) > abs(dy) ? dx : dy;
lookZoom -= float(d) * lookZoom * 0.05;
- lookZoom = fmaxf( lookZoom, 0.01f );
- lookZoom = fminf( lookZoom, 50.0f );
+ lookZoom = std::max<float>( lookZoom, 0.01f );
+ lookZoom = std::min<float>( lookZoom, 50.0f );
}
diff --git a/src/brdf/SimpleModel.cpp b/src/brdf/SimpleModel.cpp
index fcfd607..9b30b2c 100755
--- a/src/brdf/SimpleModel.cpp
+++ b/src/brdf/SimpleModel.cpp
@@ -142,12 +142,12 @@ bool SimpleModel::dataPass( FILE* file, std::vector<float3>& vertices, std::vect
if( line[0] == 'v' && line[1] == ' ' ) {
float3 data;
if( sscanf(line, "v %f %f %f", &data.x, &data.y, &data.z) == 3 ) {
- maxX = std::max( maxX, data.x );
- minX = std::min( minX, data.x );
- maxY = std::max( maxY, data.y );
- minY = std::min( minY, data.y );
- maxZ = std::max( maxZ, data.z );
- minZ = std::min( minZ, data.z );
+ maxX = std::max<float>( maxX, data.x );
+ minX = std::min<float>( minX, data.x );
+ maxY = std::max<float>( maxY, data.y );
+ minY = std::min<float>( minY, data.y );
+ maxZ = std::max<float>( maxZ, data.z );
+ minZ = std::min<float>( minZ, data.z );
vertices.push_back( data );
}
}
diff --git a/src/brdf/brdf.pro b/src/brdf/brdf.pro
index 52938fd..9cf5f80 100644
--- a/src/brdf/brdf.pro
+++ b/src/brdf/brdf.pro
@@ -1,18 +1,11 @@
TEMPLATE = app
CONFIG += qt4 #debug
-isEmpty(prefix) {
- prefix = $$system(pf-makevar --absolute root)
-}
-isEmpty(prefix) {
- error("Not inside a project directory!")
-}
-
-DEST = $$prefix
-LIBDIR = $$system(pf-makevar lib)
+DEST =
+LIBDIR =
TARGET = brdf
-target.path = $$DEST/bin
+target.path = bin
HEADERS = *.h
SOURCES = \
@@ -51,6 +44,7 @@ SOURCES = \
QT += opengl
LIBS += -lGLEW
+DEFINES += PTEX_STATIC NOMINMAX
brdfs.path = $$DEST/share/brdf/brdfs
brdfs.files = ../brdfs/*
diff --git a/src/brdf/trim.h b/src/brdf/trim.h
index 980fe17..38aa681 100644
--- a/src/brdf/trim.h
+++ b/src/brdf/trim.h
@@ -50,13 +50,13 @@ infringement.
// trim from start
static inline std::string &trimFromLeft(std::string &s) {
- s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
+ s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(::isspace))));
return s;
}
// trim from end
static inline std::string &trimFromRight(std::string &s) {
- s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
+ s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(::isspace))).base(), s.end());
return s;
}
diff --git a/src/shaderTemplates/brdfIBL.frag b/src/shaderTemplates/brdfIBL.frag
index 04f928c..98c8634 100644
--- a/src/shaderTemplates/brdfIBL.frag
+++ b/src/shaderTemplates/brdfIBL.frag
@@ -151,7 +151,7 @@ vec2 vectorToUV( vec3 rsReflVector )
{
uv = -rsReflVector.zy / rsReflVector.x;
uv.y *= -sign(rsReflVector.x);
- face = 0.0 + step(rsReflVector.x,0);
+ face = 0.0 + step(rsReflVector.x,0.0);
}
// y vector?
@@ -159,7 +159,7 @@ vec2 vectorToUV( vec3 rsReflVector )
{
uv = -rsReflVector.xz / rsReflVector.y;
uv.x *= -sign(rsReflVector.y);
- face = 2.0 + step(rsReflVector.y,0);
+ face = 2.0 + step(rsReflVector.y,0.0);
}
// z vector?
@@ -167,14 +167,14 @@ vec2 vectorToUV( vec3 rsReflVector )
{
uv = rsReflVector.xy / rsReflVector.z;
uv.y *= sign(rsReflVector.z);
- face = 4.0 + step(rsReflVector.z,0);
+ face = 4.0 + step(rsReflVector.z,0.0);
}
// transform the sampling location into [0..1]
uv = uv * 0.5 + vec2(0.5);
// transform the coordinate so we're reading from the correct envRotMatrixface
- uv.x = (uv.x + face) * (1.0/6);
+ uv.x = (uv.x + face) * (1.0/6.0);
return uv;
}
@@ -213,11 +213,11 @@ float hammersleySample(uint bits, uint seed)
float warpSample1D( sampler2D tex, float texDim, float u, float v, out float probInv )
{
- float invTexDim = 1/texDim;
+ float invTexDim = 1.0/texDim;
// evaluate approximate inverse cdf
- // Note: cvs are at pixel centers with implied end points at (0,0) and (1,1)
- // data[0] corresponds to u = 0.5/texDim
+ // Note: cvs are at pixel centers with implied end points at (0.0,0.0) and (1.0,1.0)
+ // data[0.0] corresponds to u = 0.5/texDim
float uN = u * texDim - 0.5;
float ui = floor(uN);
float frac = uN - ui;
@@ -225,11 +225,11 @@ float warpSample1D( sampler2D tex, float texDim, float u, float v, out float pro
// sample texture at texel centers (data[ui] = texture((ui+.5)/texDim))
float t0 = (ui+.5)*invTexDim, t1 = (ui+1.5)*invTexDim;
- float cdf0 = t0 < 0 ? // data[-1] is -data[0] (reflect around (0,0))
+ float cdf0 = t0 < 0.0 ? // data[-1] is -data[0] (reflect around (0,0))
-texture2D( tex, vec2(.5 * invTexDim, v) ).r :
texture2D( tex, vec2(t0, v) ).r;
- float cdf1 = t1 > 1 ? // data[texDim] = 2-data[texDim-1] (reflect around (1,1))
- 2-texture2D( tex, vec2(1 - .5 * invTexDim, v) ).r :
+ float cdf1 = t1 > 1.0 ? // data[texDim] = 2.0-data[texDim-1] (reflect around (1,1))
+ 2.0-texture2D( tex, vec2(1.0 - .5 * invTexDim, v) ).r :
texture2D( tex, vec2(t1, v) ).r;
// infer 1/pdf from slope of inverse cdf
@@ -255,7 +255,7 @@ vec2 warpSample( vec2 uv, out float probInv )
vec4 envMapSample( float u, float v )
{
- float probInv = 1;
+ float probInv = 1.0;
vec2 uv = vec2(u,v);
if (useIBLImportance > .5)
@@ -266,20 +266,20 @@ vec4 envMapSample( float u, float v )
vec3 tsSampleDir = normalize(LocalToWorld * mat3(envRotMatrixInverse) * esSampleDir);
// cosine weight
- float cosine = max(0,dot( tsSampleDir, vec3(0,0,1)));
- if (cosine <= 0) return vec4(vec3(0), 1.0);
+ float cosine = max(0.0,dot( tsSampleDir, vec3(0.0,0.0,1.0)));
+ if (cosine <= 0.0) return vec4(vec3(0.0), 1.0);
// since we're working in tangent space, the basis vectors can be nice and easy and hardcoded
- vec3 brdf = max( BRDF( tsSampleDir, tsViewVec, vec3(0,0,1), vec3(1,0,0), vec3(0,1,0) ), vec3(0.0) );
+ vec3 brdf = max( BRDF( tsSampleDir, tsViewVec, vec3(0.0,0.0,1.0), vec3(1.0,0.0,0.0), vec3(0.0,1.0,0.0) ), vec3(0.0) );
// sample env map
//vec3 envSample = sampleEnvMap( uv );
- vec3 envSample = textureCubeLod( envCube, esSampleDir, 0 ).rgb;
+ vec3 envSample = textureCubeLod( envCube, esSampleDir, 0.0 ).rgb;
// dA (area of cube) = (6*2*2)/N (Note: divide by N happens later)
// dw = dA / r^3 = 24 * pow(x*x + y*y + z*z, -1.5) (see pbrt v2 p 947).
- float dw = 24 * pow(esSampleDir.x*esSampleDir.x +
+ float dw = 24.0 * pow(esSampleDir.x*esSampleDir.x +
esSampleDir.y*esSampleDir.y +
esSampleDir.z*esSampleDir.z, -1.5);
@@ -287,7 +287,7 @@ vec4 envMapSample( float u, float v )
// hack - clamp outliers to eliminate hot spot samples
if (useIBLImportance > .5)
- result = min(result, 50);
+ result = min(result, 50.0);
return vec4(result, 1.0 );
}
@@ -316,7 +316,7 @@ vec4 computeIBL()
//result += envMapSample( uu, vv );
}
- result = vec4(0,1,0,1);
+ result = vec4(0.0,1.0,0.0,1.0);
}
// multiple importance sampling
@@ -331,7 +331,7 @@ vec4 computeIBL()
//result += envMapSample( uu, vv );
}
- result = vec4(1,0,0,1);
+ result = vec4(1.0,0.0,0.0,1.0);
}
// importance sample the IBL, or don't importance sample at all
@@ -359,12 +359,10 @@ void main(void)
esTangent = normalize( gl_TexCoord[1].xyz );
esBitangent = normalize( gl_TexCoord[2].xyz );
//viewVec = -normalize(gl_TexCoord[3].xyz);
- viewVec = vec3(0,0,1);
+ viewVec = vec3(0.0,0.0,1.0);
WorldToLocal = mat3( esTangent, esBitangent, esNormal );
- LocalToWorld._m00_m10_m20 = WorldToLocal._m00_m01_m02;
- LocalToWorld._m01_m11_m21 = WorldToLocal._m10_m11_m12;
- LocalToWorld._m02_m12_m22 = WorldToLocal._m20_m21_m22;
+ LocalToWorld = transpose(WorldToLocal);
envSampleRotMatrix = mat3(envRotMatrix) * WorldToLocal;
diff --git a/src/shaderTemplates/measured.func b/src/shaderTemplates/measured.func
index e475206..64312aa 100644
--- a/src/shaderTemplates/measured.func
+++ b/src/shaderTemplates/measured.func
@@ -64,7 +64,7 @@ int phi_diff_index(float phi_diff)
// In: phi_diff in [0 .. pi]
// Out: tmp in [0 .. 179]
- return clamp(int(phi_diff * (1.0/M_PI * (BRDF_SAMPLING_RES_PHI_D / 2))), 0, BRDF_SAMPLING_RES_PHI_D / 2 - 1);
+ return clamp(int(phi_diff * (1.0/M_PI * (BRDF_SAMPLING_RES_PHI_D / 2.0))), 0, BRDF_SAMPLING_RES_PHI_D / 2 - 1);
}
@@ -82,8 +82,8 @@ int theta_half_index(float theta_half)
// Lookup theta_diff index
-// In: [0 .. pi/2]
-// Out: [0 .. 89]
+// In: [0.0 .. pi/2]
+// Out: [0.0 .. 89.0]
int theta_diff_index(float theta_diff)
{
return clamp(int(theta_diff * (2.0/M_PI * BRDF_SAMPLING_RES_THETA_D)), 0, BRDF_SAMPLING_RES_THETA_D - 1);
@@ -92,22 +92,22 @@ int theta_diff_index(float theta_diff)
vec3 BRDF( vec3 toLight, vec3 toViewer, vec3 normal, vec3 tangent, vec3 bitangent )
{
- vec3 half = normalize(toLight + toViewer);
- float theta_half = acos(clamp(dot(normal, half), 0, 1));
- float theta_diff = acos(clamp(dot(half, toLight), 0, 1));
- float phi_diff=0;
+ vec3 half_vec = normalize(toLight + toViewer);
+ float theta_half = acos(clamp(dot(normal, half_vec), 0.0, 1.0));
+ float theta_diff = acos(clamp(dot(half_vec, toLight), 0.0, 1.0));
+ float phi_diff=0.0;
if (theta_diff < 1e-3) {
// phi_diff indeterminate, use phi_half instead
- phi_diff = atan(clamp(-dot(toLight, bitangent), -1, 1), clamp(dot(toLight, tangent), -1, 1));
+ phi_diff = atan(clamp(-dot(toLight, bitangent), -1.0, 1.0), clamp(dot(toLight, tangent), -1.0, 1.0));
}
else if (theta_half > 1e-3) {
// use Gram-Schmidt orthonormalization to find diff basis vectors
- vec3 u = -normalize(normal - dot(normal,half) * half);
- vec3 v = cross(half, u);
- phi_diff = atan(clamp(dot(toLight,v), -1, 1), clamp(dot(toLight,u), -1, 1));
+ vec3 u = -normalize(normal - dot(normal,half_vec) * half_vec);
+ vec3 v = cross(half_vec, u);
+ phi_diff = atan(clamp(dot(toLight,v), -1.0, 1.0), clamp(dot(toLight,u), -1.0, 1.0));
}
- else theta_half = 0;
+ else theta_half = 0.0;
// Find index.
// Note that phi_half is ignored, since isotropic BRDFs are assumed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment