Skip to content

Commit

Permalink
RGB -> HSV
Browse files Browse the repository at this point in the history
  • Loading branch information
obviousjim committed Dec 12, 2013
1 parent 160740e commit 5bedba5
Show file tree
Hide file tree
Showing 10 changed files with 1,227 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void CloudsVisualSystemPages::selfDraw()
void CloudsVisualSystemPages::selfDrawDebug()
{
for (auto& it : lights) {
ofSetColor((it.second)->lightAmbient);
ofSetColor((it.second)->lightAmbientHSV);
ofSphere((it.second)->lightPos, 10);
ofLine((it.second)->lightPos, (it.second)->lightPos + ((it.second)->lightOrientation * 20));
}
Expand Down
107 changes: 63 additions & 44 deletions CloudsLibrary/src/VisualSystemsLibrary/CloudsVisualSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ void CloudsVisualSystem::exit()
}
lights.clear();

for(map<string, ofMaterial *>::iterator it = materials.begin(); it != materials.end(); ++it)
for(map<string, ofxMaterial *>::iterator it = materials.begin(); it != materials.end(); ++it)
{
ofMaterial *m = it->second;
ofxMaterial *m = it->second;
delete m;
}
materials.clear();
Expand All @@ -573,6 +573,7 @@ void CloudsVisualSystem::exit()
delete cameraTrack;
cameraTrack = NULL;
}

if(timeline != NULL){
ofRemoveListener(timeline->events().bangFired, this, &CloudsVisualSystem::timelineBangEvent);
delete timeline;
Expand Down Expand Up @@ -935,16 +936,22 @@ void CloudsVisualSystem::setupLightingParams()
//LIGHTING
bSmoothLighting = true;
bEnableLights = true;
globalAmbientColor = new float[4];
globalAmbientColor[0] = 0.5;
globalAmbientColor[1] = 0.5;
globalAmbientColor[2] = 0.5;
globalAmbientColor[3] = 1.0;
globalAmbientColorHSV.r = 1.0; //hue
globalAmbientColorHSV.g = 0.0; //sat
globalAmbientColorHSV.b = 0.5; //bri
globalAmbientColorHSV.a = 1.0;

// globalAmbientColor = new float[4];
// globalAmbientColor[0] = 0.5;
// globalAmbientColor[1] = 0.5;
// globalAmbientColor[2] = 0.5;
// globalAmbientColor[3] = 1.0;
}

void CloudsVisualSystem::setupMaterialParams()
{
mat = new ofMaterial();
// mat = new ofMaterial();
mat = new ofxMaterial();
}

void CloudsVisualSystem::setupTimeLineParams()
Expand Down Expand Up @@ -1277,10 +1284,10 @@ void CloudsVisualSystem::setupLightingGui()
float length = (lgtGui->getGlobalCanvasWidth()-lgtGui->getWidgetSpacing()*5)/3.;
float dim = lgtGui->getGlobalSliderHeight();
lgtGui->addLabel("GLOBAL AMBIENT COLOR", OFX_UI_FONT_SMALL);
lgtGui->addMinimalSlider("R", 0.0, 1.0, &globalAmbientColor[0], length, dim)->setShowValue(false);
lgtGui->addMinimalSlider("H", 0.0, 1.0, &globalAmbientColorHSV.r, length, dim)->setShowValue(false);
lgtGui->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
lgtGui->addMinimalSlider("G", 0.0, 1.0, &globalAmbientColor[1], length, dim)->setShowValue(false);
lgtGui->addMinimalSlider("B", 0.0, 1.0, &globalAmbientColor[2], length, dim)->setShowValue(false);
lgtGui->addMinimalSlider("S", 0.0, 1.0, &globalAmbientColorHSV.g, length, dim)->setShowValue(false);
lgtGui->addMinimalSlider("V", 0.0, 1.0, &globalAmbientColorHSV.b, length, dim)->setShowValue(false);
lgtGui->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
lgtGui->autoSizeToFitWidgets();
ofAddListener(lgtGui->newGUIEvent,this,&CloudsVisualSystem::guiLightingEvent);
Expand All @@ -1291,18 +1298,30 @@ void CloudsVisualSystem::setupLightingGui()
void CloudsVisualSystem::guiLightingEvent(ofxUIEventArgs &e)
{
string name = e.widget->getName();
if(name == "R")
{
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientColor);
}
else if(name == "G")
{
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientColor);
}
else if(name == "B")
{
if(name == "H" ||
name == "S" ||
name == "V")
{
ofFloatColor globalAmbientColorRGB = ofFloatColor::fromHsb(globalAmbientColorHSV.r,
globalAmbientColorHSV.g,
globalAmbientColorHSV.b);
float globalAmbientColor[4] = {
globalAmbientColorRGB.r,
globalAmbientColorRGB.g,
globalAmbientColorRGB.b,
globalAmbientColorRGB.a
};

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientColor);
}
// else if(name == "G")
// {
// glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientColor);
// }
// else if(name == "B")
// {
// glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbientColor);
// }
}


Expand Down Expand Up @@ -1529,7 +1548,7 @@ void CloudsVisualSystem::guiPresetEvent(ofxUIEventArgs &e)
}
}

void CloudsVisualSystem::setupMaterial(string name, ofMaterial *m)
void CloudsVisualSystem::setupMaterial(string name, ofxMaterial *m)
{
materials[name] = m;
ofxUISuperCanvas* g = new ofxUISuperCanvas(name, gui);
Expand All @@ -1544,38 +1563,38 @@ void CloudsVisualSystem::setupMaterial(string name, ofMaterial *m)
float dim = g->getGlobalSliderHeight();

g->addLabel("AMBIENT", OFX_UI_FONT_SMALL);
g->addMinimalSlider("AR", 0.0, 1.0, &m->getAmbientColor().r, length, dim)->setShowValue(false);
g->addMinimalSlider("AH", 0.0, 1.0, &m->matAmbientHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("AG", 0.0, 1.0, &m->getAmbientColor().g, length, dim)->setShowValue(false);
g->addMinimalSlider("AB", 0.0, 1.0, &m->getAmbientColor().b, length, dim)->setShowValue(false);
g->addMinimalSlider("AS", 0.0, 1.0, &m->matAmbientHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("AV", 0.0, 1.0, &m->matAmbientHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
g->addSpacer();

g->addLabel("DIFFUSE", OFX_UI_FONT_SMALL);
g->addMinimalSlider("AR", 0.0, 1.0, &m->getDiffuseColor().r, length, dim)->setShowValue(false);
g->addMinimalSlider("DH", 0.0, 1.0, &m->matDiffuseHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("AG", 0.0, 1.0, &m->getDiffuseColor().g, length, dim)->setShowValue(false);
g->addMinimalSlider("AB", 0.0, 1.0, &m->getDiffuseColor().b, length, dim)->setShowValue(false);
g->addMinimalSlider("DS", 0.0, 1.0, &m->matDiffuseHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("DV", 0.0, 1.0, &m->matDiffuseHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
g->addSpacer();

g->addLabel("EMISSIVE", OFX_UI_FONT_SMALL);
g->addMinimalSlider("ER", 0.0, 1.0, &m->getEmissiveColor().r, length, dim)->setShowValue(false);
g->addMinimalSlider("EH", 0.0, 1.0, &m->matEmissiveHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("EG", 0.0, 1.0, &m->getEmissiveColor().g, length, dim)->setShowValue(false);
g->addMinimalSlider("EB", 0.0, 1.0, &m->getEmissiveColor().b, length, dim)->setShowValue(false);
g->addMinimalSlider("ES", 0.0, 1.0, &m->matEmissiveHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("EV", 0.0, 1.0, &m->matEmissiveHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
g->addSpacer();

g->addLabel("SPECULAR", OFX_UI_FONT_SMALL);
g->addMinimalSlider("SR", 0.0, 1.0, &(m->getSpecularColor().r), length, dim)->setShowValue(false);
g->addMinimalSlider("SH", 0.0, 1.0, &m->matSpecularHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("SG", 0.0, 1.0, &(m->getSpecularColor().g), length, dim)->setShowValue(false);
g->addMinimalSlider("SB", 0.0, 1.0, &(m->getSpecularColor().b), length, dim)->setShowValue(false);
g->addMinimalSlider("SS", 0.0, 1.0, &m->matSpecularHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("SV", 0.0, 1.0, &m->matSpecularHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
g->addSpacer();

g->addMinimalSlider("SHINY", 0.0, 128.0, (m->getShininess()))->setShowValue(false);
g->addMinimalSlider("SHINY", 0.0, 128.0, m->matShininess)->setShowValue(false);

g->autoSizeToFitWidgets();
g->setPosition(ofGetWidth()*.5-g->getRect()->getHalfWidth(), ofGetHeight()*.5 - g->getRect()->getHalfHeight());
Expand Down Expand Up @@ -1745,26 +1764,26 @@ void CloudsVisualSystem::setupGenericLightProperties(ofxUISuperCanvas *g, ofxLig
}

g->addLabel("AMBIENT", OFX_UI_FONT_SMALL);
g->addMinimalSlider("AR", 0.0, 1.0, &l->lightAmbient.r, length, dim)->setShowValue(false);
g->addMinimalSlider("AH", 0.0, 1.0, &l->lightAmbientHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("AG", 0.0, 1.0, &l->lightAmbient.g, length, dim)->setShowValue(false);
g->addMinimalSlider("AB", 0.0, 1.0, &l->lightAmbient.b, length, dim)->setShowValue(false);
g->addMinimalSlider("AS", 0.0, 1.0, &l->lightAmbientHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("AV", 0.0, 1.0, &l->lightAmbientHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);

g->addSpacer();
g->addLabel("DIFFUSE", OFX_UI_FONT_SMALL);
g->addMinimalSlider("DR", 0.0, 1.0, &l->lightDiffuse.r, length, dim)->setShowValue(false);
g->addMinimalSlider("DH", 0.0, 1.0, &l->lightDiffuseHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("DG", 0.0, 1.0, &l->lightDiffuse.g, length, dim)->setShowValue(false);
g->addMinimalSlider("DB", 0.0, 1.0, &l->lightDiffuse.b, length, dim)->setShowValue(false);
g->addMinimalSlider("DS", 0.0, 1.0, &l->lightDiffuseHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("DV", 0.0, 1.0, &l->lightDiffuseHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);

g->addSpacer();
g->addLabel("SPECULAR", OFX_UI_FONT_SMALL);
g->addMinimalSlider("SR", 0.0, 1.0, &l->lightSpecular.r, length, dim)->setShowValue(false);
g->addMinimalSlider("SH", 0.0, 1.0, &l->lightSpecularHSV.r, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT);
g->addMinimalSlider("SG", 0.0, 1.0, &l->lightSpecular.g, length, dim)->setShowValue(false);
g->addMinimalSlider("SB", 0.0, 1.0, &l->lightSpecular.b, length, dim)->setShowValue(false);
g->addMinimalSlider("SS", 0.0, 1.0, &l->lightSpecularHSV.g, length, dim)->setShowValue(false);
g->addMinimalSlider("SV", 0.0, 1.0, &l->lightSpecularHSV.b, length, dim)->setShowValue(false);
g->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN);
g->addSpacer();
}
Expand Down
9 changes: 5 additions & 4 deletions CloudsLibrary/src/VisualSystemsLibrary/CloudsVisualSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class CloudsVisualSystem {
void setupPresetGui();
void guiPresetEvent(ofxUIEventArgs &e);

void setupMaterial(string name, ofMaterial *m);
void setupMaterial(string name, ofxMaterial *m);
void guiMaterialEvent(ofxUIEventArgs &e);

void setupPointLight(string name);
Expand Down Expand Up @@ -330,15 +330,16 @@ class CloudsVisualSystem {
vector<ofx1DExtruder *> extruders;

//MATERIAL
ofMaterial *mat;
map<string, ofMaterial *> materials;
ofxMaterial *mat;
map<string, ofxMaterial *> materials;
map<string, ofxUISuperCanvas *> materialGuis;

bool bIsSetup;
bool bIs2D;

//LIGHTING
float *globalAmbientColor;
//float *globalAmbientColor;
ofFloatColor globalAmbientColorHSV;
bool bSmoothLighting;
bool bEnableLights;

Expand Down
59 changes: 53 additions & 6 deletions CloudsLibrary/src/VisualSystemsLibrary/ofxLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ofMath.h"
#include "ofColor.h"
#include "ofLight.h"
#include "ofMaterial.h"

class ofxLight
{
Expand All @@ -38,9 +39,11 @@ class ofxLight
// light.setup();
lightPos.set(0.0f,0.0f,0.0f);
lightOrientation.set(0.0f,0.0f,0.0f);
lightAmbient = ofFloatColor(.5f,.5f,.5f,1.f);
lightDiffuse = ofFloatColor(.5f,.5f,.5f,1.f);
lightSpecular = ofFloatColor(.5f,.5f,.5f,1.f);
// ofFloatColor(.5f,.5f,.5f,1.f);
lightAmbientHSV = ofFloatColor(1.0f, .0f, .5f, 1.f);
lightDiffuseHSV = ofFloatColor(1.0f, .0f, .5f, 1.f);
lightSpecularHSV = ofFloatColor(1.0f, .0f, .5f, 1.f);

lightSpotCutOff = 45.0f;
lightExponent = 0.0f;

Expand Down Expand Up @@ -79,6 +82,10 @@ class ofxLight
break;
}

ofFloatColor lightAmbient = ofFloatColor::fromHsb(lightAmbientHSV.r, lightAmbientHSV.g, lightAmbientHSV.b);
ofFloatColor lightDiffuse = ofFloatColor::fromHsb(lightDiffuseHSV.r, lightDiffuseHSV.g, lightDiffuseHSV.b);
ofFloatColor lightSpecular = ofFloatColor::fromHsb(lightSpecularHSV.r, lightSpecularHSV.g, lightSpecularHSV.b);

light.setAmbientColor(lightAmbient);
light.setDiffuseColor(lightDiffuse);
light.setSpecularColor(lightSpecular);
Expand All @@ -103,9 +110,49 @@ class ofxLight
ofLight light;
ofVec3f lightPos;
ofVec3f lightOrientation;
ofFloatColor lightAmbient;
ofFloatColor lightDiffuse;
ofFloatColor lightSpecular;
ofFloatColor lightAmbientHSV;
ofFloatColor lightDiffuseHSV;
ofFloatColor lightSpecularHSV;
};


class ofxMaterial
{
public:

// ofxMaterial(){}
// ~ofxMaterial(){}

void begin()
{
ofFloatColor matAmbient = ofFloatColor::fromHsb(matAmbientHSV.r, matAmbientHSV.g, matAmbientHSV.b);
ofFloatColor matDiffuse = ofFloatColor::fromHsb(matDiffuseHSV.r, matDiffuseHSV.g, matDiffuseHSV.b);
ofFloatColor matEmissive = ofFloatColor::fromHsb(matEmissiveHSV.r, matEmissiveHSV.g, matEmissiveHSV.b);
ofFloatColor matSpecular = ofFloatColor::fromHsb(matSpecularHSV.r, matSpecularHSV.g, matSpecularHSV.b);

mat.setAmbientColor(matAmbient);
mat.setDiffuseColor(matDiffuse);
mat.setSpecularColor(matSpecular);
mat.setEmissiveColor(matEmissive);
mat.setShininess(matShininess);

mat.begin();
}

void end(){
mat.end();
}

// bool bEnabled;

ofMaterial mat;

float matShininess;
ofFloatColor matDiffuseHSV;
ofFloatColor matSpecularHSV;
ofFloatColor matEmissiveHSV;
ofFloatColor matAmbientHSV;

};

#endif
Loading

0 comments on commit 5bedba5

Please sign in to comment.