Yes, I was already doing an ofLight object, since you guys already did the work.
But there's something that I' really missing out. Can you help me? I copied the shader from the ofMaterial with only the point light. I removed the rest and the loop and array for >1 lights. The GPU doesn't return any errors, I tested the texcoords, normals, uniforms, etc, and everything seems to be working. Except the shading it self.
I'm I forgetting to enable something?
void ofApp::setup(){
ofSetColor(255);
ofSetBackgroundColor(0);
ofSetVerticalSync(true);
// Before Mipmaps
ofDisableArbTex();
ofEnableDepthTest();
// ofEnableLighting();
earthDayTexture.enableMipmap();
ofLoadImage(earthDayTexture, "textures_low/8081-earthmap10k.jpg");
earthDayTexture.generateMipmap();
shader.load("shaders/phong_ofShader");
earth.set(200, 300);
earth.rotate(190, 0, 1, 0);
earth.rotate(-20, 1, 0, 0);
easyCamera.setVFlip(true);
easyCamera.setDistance(600);
// For the light
lightRadius = 300.f;
lightCenter = ofVec3f(0.f);
// GUI
gui.setup("Esfera");
gui.add(frameRate.set("Framerate", "0"));
// pointLight.setup();
// pointLight.enable();
// pointLight.setPointLight();
pointLight.setAmbientColor(ofFloatColor(0.12, 0.09, 0.14, 1.0f));
pointLight.setDiffuseColor(ofFloatColor(0.5, 0.24, 0.0f, 1.0f));
pointLight.setSpecularColor(ofFloatColor(0.0f, 0.0f, 0.35, 1.0f));
pointLight.setAttenuation(0.000001f, 0.000001f, 0.000001f);
materialLight.setAmbientColor(ofFloatColor(0.0561f, 0.0561f, 0.0561f));
materialLight.setDiffuseColor(ofFloatColor(0.02f, 0.04f, 0.0f));
materialLight.setSpecularColor(ofFloatColor(0.4,0.2,0.3,1.0));
materialLight.setEmissiveColor(ofFloatColor(0.02f, 0.04f, 0.0f));
materialLight.setShininess(5);
}
//--------------------------------------------------------------
void ofApp::update(){
frameRate = ofToString((int)ofGetFrameRate());
flow += ofGetLastFrameTime();
lightPosition = ofVec4f(cos(flow * .05f) * lightRadius + lightCenter.x,
0.f,
sin(flow * .05f) * lightRadius + lightCenter.z,
0.f);
pointLight.setPosition(lightPosition.x, lightPosition.y, lightPosition.z);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofEnableDepthTest();
easyCamera.begin();
// materialLight.begin();
shader.begin();
shader.setUniformMatrix4f("normalMatrix", ofGetCurrentNormalMatrix());
shader.setUniformTexture("earthDayTexture", earthDayTexture, 1);
shader.setUniform4f("light.position", lightPosition * ofGetCurrentViewMatrix());
shader.setUniform4f("light.ambient", pointLight.getAmbientColor());
shader.setUniform4f("light.diffuse", pointLight.getDiffuseColor());
shader.setUniform4f("light.specular", pointLight.getSpecularColor());
shader.setUniform1f("light.constantAttenuation", pointLight.getAttenuationConstant());
shader.setUniform1f("light.linearAttenuation", pointLight.getAttenuationLinear());
shader.setUniform1f("light.quadraticAttenuation", pointLight.getAttenuationQuadratic());
shader.setUniform4f("global_ambient", ofFloatColor(0.2, 0.2, 0.2, 1.0));
shader.setUniform4f("mat_ambient", materialLight.getAmbientColor());
shader.setUniform4f("mat_diffuse", materialLight.getDiffuseColor());
shader.setUniform4f("mat_specular", materialLight.getSpecularColor());
shader.setUniform4f("mat_emissive", materialLight.getEmissiveColor());
shader.setUniform1f("mat_shininess", materialLight.getShininess());
// shader.setUniform4f("mat_ambient", 0.0561f, 0.0561f, 0.0561f, 1.0);
// shader.setUniform4f("mat_diffuse", 0.02f, 0.04f, 0.0f, 1.0);
// shader.setUniform4f("mat_specular", 0.4,0.2,0.3,1.0);
// shader.setUniform4f("mat_emissive", 0.02f, 0.04f, 0.0f, 1.0);
// shader.setUniform1f("mat_shininess", 5.f);
earth.draw();
shader.end();
// materialLight.end();
// Assistance
// ofDrawAxis(600);
ofDrawBox(lightPosition, 5);
easyCamera.end();
ofDisableDepthTest();
}
(Note: some of the stuff that is commented, it's just me testing how OF binds and such.)
When I use ofLight, ofMaterial, bind the texture and no shader, everything works fine... But this, does not.