Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions examples/gl/materialPBRAdvanced/bin/data/shaders/main.vert
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@

// we set this define in the ofApp class
#if defined(SHADOW_DEPTH_PASS)
uniform mat4 modelMatrix;
in vec4 position;
uniform float iElapsedTime;
uniform float uWiggleVerts;
#else
// the mesh we are using does not have texture coordinates
// so we are going to send the local vertex positions to use for animation
OUT vec3 v_localPos;
#endif


void main (void){
vec4 npos = position;
npos.xyz += uWiggleVerts * 0.25 * vec3( cos(iElapsedTime*1.3+(position.z*1.25)+position.y*1.25), 0.0, 0.0);
#if defined(SHADOW_DEPTH_PASS)
vec3 worldPosition = (modelMatrix * vec4(npos.xyz, 1.0)).xyz;
sendShadowDepthWorldPosition(worldPosition);
#else
v_localPos = position.xyz;
vec4 npos = getTransformedPosition();
// npos.xyz += vec3( cos(iElapsedTime+v_localPos.y*1.85), 0.0, 0.0);
sendVaryings(npos);
gl_Position = modelViewProjectionMatrix * npos;
#endif
}
23 changes: 20 additions & 3 deletions examples/gl/materialPBRAdvanced/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ void ofApp::draw(){
int numShadowPasses = light.getNumShadowDepthPasses();
for( int j = 0; j < numShadowPasses; j++ ) {
light.beginShadowDepthPass(j);
renderScene();
renderScene(true);
light.endShadowDepthPass(j);
}
}


camera.begin(); {

renderScene();
renderScene(false);

if( cubeMap.hasPrefilteredMap() ) {
cubeMap.drawPrefilteredCube(0.2f);
Expand Down Expand Up @@ -108,11 +108,12 @@ void ofApp::draw(){

stringstream ss;
ss << "Reload shader(r): make changes to shader in data/shaders/main.frag and then press 'r' to see changes.";
ss << endl << "Wiggle verts(w): " << (bWiggleVerts ? "yes" : "no");
ofDrawBitmapStringHighlight(ss.str(), 40, 40);
}

//--------------------------------------------------------------
void ofApp::renderScene() {
void ofApp::renderScene(bool bShadowPass) {

matFloor.setMetallic(0.0);
matFloor.setReflectance(0.01);
Expand Down Expand Up @@ -140,7 +141,14 @@ void ofApp::renderScene() {
ofPopMatrix();
matSphere.end();

if( bShadowPass && bWiggleVerts ) {
mDepthShader.begin();
mDepthShader.setUniform1f("iElapsedTime", ofGetElapsedTimef());
mDepthShader.setUniform1f("uWiggleVerts", bWiggleVerts ? 1.0f : 0.0f);
}
// setting custom uniforms on a material automatically adds it to the shader
matLogo.setCustomUniform1f("iElapsedTime", ofGetElapsedTimef());
matLogo.setCustomUniform1f("uWiggleVerts", bWiggleVerts ? 1.0f : 0.0f);
matLogo.begin();
ofPushMatrix();
ofTranslate( -70, -250, 0 );
Expand All @@ -149,6 +157,9 @@ void ofApp::renderScene() {
meshLogoHollow.draw();
ofPopMatrix();
matLogo.end();
if(bShadowPass && bWiggleVerts ) {
mDepthShader.end();
}
}

//--------------------------------------------------------------
Expand All @@ -161,6 +172,9 @@ bool ofApp::reloadShader() {
if( vbuffer.size() && fbuffer.size() ) {
matLogo.setShaderMain(vbuffer.getText(), GL_VERTEX_SHADER, "main.vert");
matLogo.setShaderMain(fbuffer.getText(), GL_FRAGMENT_SHADER, "main.frag");
// configure the shader to include shadow functions for passing depth
// declare a define so we can use the same shader file and run different bits of code
light.getShadow().setupShadowDepthShader(mDepthShader, "#define SHADOW_DEPTH_PASS\n"+vbuffer.getText());
return true;
}
return false;
Expand All @@ -174,6 +188,9 @@ void ofApp::keyPressed(int key){
if( key == 'd' ) {
bDebug = !bDebug;
}
if( key == 'w') {
bWiggleVerts = !bWiggleVerts;
}
}

//--------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion examples/gl/materialPBRAdvanced/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ofApp : public ofBaseApp{
void update();
void draw();

void renderScene();
void renderScene(bool bShadowPass);

bool reloadShader();

Expand All @@ -35,9 +35,12 @@ class ofApp : public ofBaseApp{

ofVboMesh meshPlySphere;

ofShader mDepthShader;

int mode = 0;

ofLight light;
bool bDebug = false;
bool bWiggleVerts = false;

};