Hello everyone,
I’d like to know what kind of light would be best suited to implement a Cornell box.
And if you have any advice to better visualize the light as I’m modifying it’s position and parameters.
Thank you.
Hello everyone,
I’d like to know what kind of light would be best suited to implement a Cornell box.
And if you have any advice to better visualize the light as I’m modifying it’s position and parameters.
Thank you.
#include “ofApp.h”
//--------------------------------------------------------------
void ofApp::setup() {
ofSetSmoothLighting(true);
// enable lighting //
ofEnableLighting();
ceilingLight.setDiffuseColor(ofColor(255.f, 255.f, 255.f));
ceilingLight.setSpecularColor(ofColor(255.f, 255.f, 255.f));
// turn the light into spotLight, emit a cone of light //
ceilingLight.setSpotlight();
// size of the cone of emitted light, angle between light axis and side of cone //
// angle range between 0 - 90 in degrees //
ceilingLight.setSpotlightCutOff(10);
// rate of falloff, illumitation decreases as the angle from the cone axis increases //
// range 0 - 128, zero is even illumination, 128 is max falloff //
ceilingLight.setSpotConcentration(0);
ceilingLight.rotate(90, ofVec3f(1, 0, 0));
lightOrientation = ceilingLight.getOrientationQuat();
dollyZplus = false;
dollyXminus = false;
orbitYleft = false;
orbitYright = false;
theta = 0.f;
ofSetVerticalSync(true);
ofEnableDepthTest();
posX = 0.f;
posY = 0.f;
posZ = 0.f;
wallWidth = 100;
wallHeight = 100;
wallThickness = -10;
camX = wallWidth / 2;
camY =0;
camZ = 200.f;
ceilingLight.setAreaLight(wallWidth, wallHeight);
backWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
backWall.addVertex(ofVec3f(0, 0, 0));
backWall.addVertex(ofVec3f(wallWidth, 0, 0));
backWall.addVertex(ofVec3f(wallWidth, wallHeight, 0));
backWall.addVertex(ofVec3f(0, wallHeight, 0));
ceilingLight.setPosition(wallWidth / 2, wallHeight, wallWidth / 2);
leftWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
leftWall.addVertex(ofVec3f(0, 0, 0));
leftWall.addVertex(ofVec3f(wallWidth, 0, 0));
leftWall.addVertex(ofVec3f(wallWidth, wallHeight, 0));
leftWall.addVertex(ofVec3f(0, wallHeight, 0));
leftWall.addVertex(ofVec3f(0, 0, wallThickness));
leftWall.addVertex(ofVec3f(wallWidth, 0, wallThickness));
leftWall.addVertex(ofVec3f(wallWidth, wallHeight, wallThickness));
leftWall.addVertex(ofVec3f(0, wallHeight, wallThickness));
rightWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
rightWall.addVertex(ofVec3f(0, 0, 0));
rightWall.addVertex(ofVec3f(wallWidth, 0, 0));
rightWall.addVertex(ofVec3f(wallWidth, wallHeight, 0));
rightWall.addVertex(ofVec3f(0, wallHeight, 0));
ceiling.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
ceiling.addVertex(ofVec3f(0, 0, 0));
ceiling.addVertex(ofVec3f(wallWidth, 0, 0));
ceiling.addVertex(ofVec3f(wallWidth, wallHeight, 0));
ceiling.addVertex(ofVec3f(0, wallHeight, 0));
floor.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
floor.addVertex(ofVec3f(0, 0, 0));
floor.addVertex(ofVec3f(wallWidth, 0, 0));
floor.addVertex(ofVec3f(wallWidth, wallHeight, 0));
floor.addVertex(ofVec3f(0, wallHeight, 0));
cam.setPosition(camX, camY, camZ);
//cout << glGetString(GL_VERSION) << endl;
}
//--------------------------------------------------------------
void ofApp::update(){
if (dollyZplus == true)
{
camZ += 0.1f;
}
if (dollyXminus == true)
{
camX -= 0.1f;
}
if (orbitYleft == true)
{
theta += 0.01f;
cam.rotate(theta, 0, 1, 0);
}
if (orbitYright == true)
{
theta -= 0.01f;
cam.rotate(theta, 0, 1, 0);
}
cam.setPosition(camX, camY, camZ);
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
ceilingLight.enable();
ofPushMatrix();
ofTranslate(0, -ofGetWidth()/15, 0);
ofSetColor(ofColor(75,75,75));
backWall.drawFaces();
ofPopMatrix();
ofPushMatrix();
ofTranslate(0, -ofGetWidth() / 15, wallWidth);
ofRotate(90, 0, 1, 0);
ofSetColor(ofColor(220, 5, 5));
leftWall.drawFaces();
ofPopMatrix();
ofPushMatrix();
ofTranslate( wallWidth, -ofGetWidth() / 15, wallWidth);
ofRotate(90, 0, 1, 0);
ofSetColor(ofColor(5, 210, 5));
rightWall.drawFaces();
ofPopMatrix();
ofPushMatrix();
ofTranslate(0, -ofGetWidth() / 15+wallHeight,0);
ofRotate(90, 1, 0, 0);
ofSetColor(ofColor(40, 40, 40));
ceiling.drawFaces();
ofPopMatrix();
ofPushMatrix();
ofTranslate(0, -ofGetWidth() / 15, 0);
ofRotate(90, 1, 0, 0);
ofSetColor(ofColor(40, 40, 40));
floor.drawFaces();
ofPopMatrix();
cam.end();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
switch (key)
{
case 45:
dollyZplus = true;
break;
case 356://left arrow
dollyXminus = true;
break;
case 97://a
orbitYleft = true;
break;
case 100://w
orbitYright = true;
break;
}
cout << key << endl;
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
switch (key)
{
case 45:
dollyZplus = false;
break;
case 356://left arrow
dollyXminus = false;
break;
case 97://a
orbitYleft = false;
break;
case 100://w
orbitYright = false;
break;
}
}
I want a square light on the ceiling that will shine inside the box. Plus I still don’t understand how to make a mesh…see the left wall were I tried do have two rectangles and figured that would close as a box to make the wall but visibly that’s not how it works.
Please explain this to me a little bit. Thank you.
if you want to use area lights you need to be using opengl 3 at least (using 3.3 at least is the recommended)
in your main:
int main(){
ofGLFWWindowSettings settings;
settings.setGLVersion(3,3);
ofCreateWindow(settings);
return ofRunApp(new ofApp);
}
creating a mesh the way you are doing it should work, i would “bake” the transformations in the geometry instead of using push/translate/rotate/pop but it should also work the way you are doing it. it would help if you posted some screenshots to see what’s the problem
also when working with lights it’s recommended to use ofMaterial to precisely set the material properties of each object you draw.
Hi Arturo,
I’ve done what you said in main and went for version 3.3.
Now here is the photo of the Mesh that’s a bit weird.
Thank you for your help.
void ofApp::setup() {
ofSetSmoothLighting(true);
// enable lighting //
ofEnableLighting();
ceilingLight.setDiffuseColor(ofColor(255.f, 255.f, 255.f));
ceilingLight.setSpecularColor(ofColor(255.f, 255.f, 255.f));
// turn the light into spotLight, emit a cone of light //
ceilingLight.setSpotlight();
// size of the cone of emitted light, angle between light axis and side of cone //
// angle range between 0 - 90 in degrees //
ceilingLight.setSpotlightCutOff(10);
// rate of falloff, illumitation decreases as the angle from the cone axis increases //
// range 0 - 128, zero is even illumination, 128 is max falloff //
ceilingLight.setSpotConcentration(0);
ceilingLight.rotate(90, ofVec3f(1, 0, 0));
lightOrientation = ceilingLight.getOrientationQuat();
dollyZplus = false;
dollyXminus = false;
dollyYplus = false;
dollyYminus = false;
orbitYleft = false;
orbitYright = false;
theta = 0.f;
ofSetVerticalSync(true);
ofEnableDepthTest();
posX = 0.f;
posY = 0.f;
posZ = 0.f;
wallWidth = 100;
wallHeight = 100;
wallThickness = 10;
camX = wallWidth / 2;
camY =wallHeight/2;
camZ = 200.f;
ceilingLight.setAreaLight(wallWidth, wallHeight);
backWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
backWall.addVertex(ofVec3f(0, 0, 0));
backWall.addVertex(ofVec3f(wallWidth, 0, 0));
backWall.addVertex(ofVec3f(wallWidth, wallHeight, 0));
backWall.addVertex(ofVec3f(0, wallHeight, 0));
ceilingLight.setPosition(wallWidth / 2, wallHeight, wallWidth / 2);
leftWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
leftWall.addVertex(ofVec3f(0, 0, 0));
leftWall.addVertex(ofVec3f(0, 0, wallWidth));
leftWall.addVertex(ofVec3f(0,wallHeight, wallWidth));
leftWall.addVertex(ofVec3f(0, wallHeight, 0));
rightWall.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
rightWall.addVertex(ofVec3f(wallWidth, 0, 0));
rightWall.addVertex(ofVec3f(wallWidth, 0, wallWidth));
rightWall.addVertex(ofVec3f(wallWidth, wallHeight, wallWidth));
rightWall.addVertex(ofVec3f(wallWidth, wallHeight, 0));
ceiling.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
ceiling.addVertex(ofVec3f(0, wallHeight, 0));
ceiling.addVertex(ofVec3f(wallWidth, wallHeight, 0));
ceiling.addVertex(ofVec3f(wallWidth, wallHeight, wallHeight));
ceiling.addVertex(ofVec3f(0, wallHeight, wallHeight));
floor.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
floor.addVertex(ofVec3f(0, 0, 0));
floor.addVertex(ofVec3f(wallWidth, 0, 0));
floor.addVertex(ofVec3f(wallWidth, 0, wallHeight));
floor.addVertex(ofVec3f(0, 0, wallHeight));
bubble.set(20, 100);
bubble.setPosition(wallWidth/3, wallWidth*0.3f, wallWidth/2);
sphereMat.setShininess(100);
sphereMat.setAmbientColor(2);
sphereMat.setDiffuseColor(6);
box.set(20);
box.setPosition(wallWidth*0.7f, wallWidth*0.2f, wallWidth / 2);
boxMat.setShininess(50);
boxMat.setAmbientColor(2);
boxMat.setDiffuseColor(6);
boxMat.setEmissiveColor(30);
cam.setPosition(camX, camY, camZ);
//cout << glGetString(GL_VERSION) << endl;
}
//--------------------------------------------------------------
void ofApp::update(){
if (dollyZplus == true)
{
camZ += 0.1f;
}
if (dollyXminus == true)
{
camX -= 0.1f;
}
if (dollyYplus == true)
{
camY += 0.1f;
}
if (dollyYminus == true)
{
camY -= 0.1f;
}
if (orbitYleft == true)
{
theta += 0.01f;
cam.rotate(theta, 0, 1, 0);
}
if (orbitYright == true)
{
theta -= 0.01f;
cam.rotate(theta, 0, 1, 0);
}
cam.setPosition(camX, camY, camZ);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetBackgroundColor(ofColor(20,20,70,20));
cam.begin();
ceilingLight.enable();
ofSetColor(ofColor(75,75,75));
backWall.drawFaces();
ofSetColor(ofColor(220, 5, 5));
leftWall.drawFaces();
ofSetColor(ofColor(5, 210, 5));
rightWall.drawFaces();
ofSetColor(ofColor(40, 40, 40));
ceiling.drawFaces();
ofSetColor(ofColor(40, 40, 40));
floor.drawFaces();
sphereMat.begin();
bubble.draw();
sphereMat.end();
boxMat.begin();
box.draw();
boxMat.end();
cam.end();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
switch (key)
{
case 45:
dollyZplus = true;
break;
case 356://left arrow
dollyXminus = true;
break;
case 357://up arrow
dollyYplus = true;
break;
case 359://down arrow
dollyYminus = true;
break;
case 97://a
orbitYleft = true;
break;
case 100://w
orbitYright = true;
break;
}
cout << key << endl;
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
switch (key)
{
case 45:
dollyZplus = false;
break;
case 356://left arrow
dollyXminus = false;
break;
case 357://up arrow
dollyYplus = false;
break;
case 359://down arrow
dollyYminus = false;
break;
case 97://a
orbitYleft = false;
break;
case 100://w
orbitYright = false;
break;
}
}
now Arturo,
Could you explain to me the range of values I should use for the material parameters please. By testing I could see that a low value is close to the last ofColor selected and a high value goes toward white so I guess I don’t really understand how to obtain the result I’m looking for as I’d like the sphere to be more glassy and the box maybe metal or wood.
Thank you.
the materials in OF are phong materials so it’s impossible to get anything like “glassy”, for metallic you can try changing the specular values to the color of the metal and setting the diffuse to black but it won’t be very realistic either. combining textures with materials can help you get things like wood.
here’s an explanation about ofLight and ofMaterial that can help you understand how it works Understanding ofLight