void CC3PODLight::initAtIndex( GLint aPODIndex, CC3PODResource* aPODRez ) { super::initAtIndex( aPODIndex, aPODRez ); // Get the light content if (getPodContentIndex() >= 0) { SPODLight* psl = (SPODLight*)aPODRez->getLightPODStructAtIndex(getPodContentIndex()); //LogRez(@"Setting %@ parameters from %@", [self class], NSStringFromSPODLight(psl)); setPodTargetIndex( psl->nIdxTarget ); setAmbientColor( kCC3DefaultLightColorAmbient ); setDiffuseColor( ccc4f(psl->pfColour[0], psl->pfColour[1], psl->pfColour[2], 1.0) ); setSpecularColor( kCC3DefaultLightColorSpecular ); setAttenuation( CC3AttenuationCoefficientsMake(psl->fConstantAttenuation, psl->fLinearAttenuation, psl->fQuadraticAttenuation) ); switch (psl->eType) { case ePODDirectional: setIsDirectionalOnly( true ); break; case ePODPoint: setIsDirectionalOnly( false ); break; case ePODSpot: setIsDirectionalOnly( false ); setSpotCutoffAngle( CC3RadToDeg(psl->fFalloffAngle) ); setSpotExponent( psl->fFalloffExponent ); break; default: break; } } }
//---------------------------------------- void ofLight::setup() { if(glIndex==-1){ bool bLightFound = false; // search for the first free block for(int i=0; i<OF_MAX_LIGHTS; i++) { if(getActiveLights()[i] == false) { glIndex = i; retain(glIndex); bLightFound = true; break; } } if( !bLightFound ){ ofLog(OF_LOG_ERROR, "ofLight : Trying to create too many lights: " + ofToString(glIndex)); } if(bLightFound) { // run this the first time, since it was not found before // onPositionChanged(); setAmbientColor( getAmbientColor() ); setDiffuseColor( getDiffuseColor() ); setSpecularColor( getSpecularColor() ); setAttenuation( getAttenuationConstant(), getAttenuationLinear(), getAttenuationQuadratic() ); if(getIsSpotlight()) { setSpotlightCutOff(getSpotlightCutOff()); setSpotConcentration(getSpotConcentration()); } if(getIsSpotlight() || getIsDirectional()) { onOrientationChanged(); } } } }
/* * Create a directional light with light num and init */ DirectionalLight::DirectionalLight(int lightNum, Vector4 ambient, Vector4 diffuse, Vector4 specular) { lightNumber = lightNum; init(); setAmbientColor(ambient); setDiffuseColor(diffuse); setSpecularColor(specular); }
//---------------------------------------- ofLight::ofLight() :data(new Data){ setAmbientColor(ofColor(0,0,0)); setDiffuseColor(ofColor(255,255,255)); setSpecularColor(ofColor(255,255,255)); setPointLight(); // assume default attenuation factors // setAttenuation(1.f,0.f,0.f); }
SpotLight::SpotLight(int lightNum, double cuttoffAngle, double falloffParam, Vector4 ambient, Vector4 diffuse, Vector4 specular) { lightNumber = lightNum; init(); beamWidth = cuttoffAngle; falloff = falloffParam; setAmbientColor(ambient); setDiffuseColor(diffuse); setSpecularColor(specular); }
void CC3PODLight::initAtIndex( GLint aPODIndex, CC3PODResource* aPODRez ) { init(); setPodIndex( aPODIndex ); SPODNode* psn = (SPODNode*)getNodePODStructAtIndex( aPODIndex, aPODRez ); //LogRez(@"Creating %@ at index %i from: %@", [self class], aPODIndex, NSStringFromSPODNode(psn)); setName( psn->pszName ); setPodContentIndex( psn->nIdx ); setPodParentIndex( psn->nIdxParent ); if ( psn->pfAnimPosition ) setLocation( *(CC3Vector*)psn->pfAnimPosition ); if ( psn->pfAnimRotation ) setQuaternion( *(CC3Quaternion*)psn->pfAnimRotation ); if ( psn->pfAnimScale ) setScale( *(CC3Vector*)psn->pfAnimScale ); if ( CC3PODNodeAnimation::sPODNodeDoesContainAnimation((PODStructPtr)psn) ) setAnimation( CC3PODNodeAnimation::animationFromSPODNode( (PODStructPtr)psn, aPODRez->getAnimationFrameCount() ) ); else if (aPODRez->shouldFreezeInanimateNodes()) setAnimation( CC3FrozenNodeAnimation::animationFromNodeState( this ) ); // Get the light content if (getPodContentIndex() >= 0) { SPODLight* psl = (SPODLight*)aPODRez->getLightPODStructAtIndex(getPodContentIndex()); //LogRez(@"Setting %@ parameters from %@", [self class], NSStringFromSPODLight(psl)); setPodTargetIndex( psl->nIdxTarget ); setAmbientColor( kCC3DefaultLightColorAmbient ); setDiffuseColor( ccc4f(psl->pfColour[0], psl->pfColour[1], psl->pfColour[2], 1.0) ); setSpecularColor( kCC3DefaultLightColorSpecular ); setAttenuation( CC3AttenuationCoefficientsMake(psl->fConstantAttenuation, psl->fLinearAttenuation, psl->fQuadraticAttenuation) ); switch (psl->eType) { case ePODDirectional: setIsDirectionalOnly( true ); break; case ePODPoint: setIsDirectionalOnly( false ); break; case ePODSpot: setIsDirectionalOnly( false ); setSpotCutoffAngle( CC3RadToDeg(psl->fFalloffAngle) ); setSpotExponent( psl->fFalloffExponent ); break; default: break; } } }
Material::Material() { mShaderProgram = NULL; setAmbientColor(); setDiffuseColor(); setEmissiveColor(); setSpecularColor(); mUniformsInitialized = false; for (unsigned int i = 0; i < MATERIAL_COMPONENT_COUNT; ++i) { mMaterialComponentEnabled[i] = false; } }
//---------------------------------------- ofLight::ofLight(){ glIndex = -1; isEnabled = false; setAmbientColor(ofColor(0,0,0)); setDiffuseColor(ofColor(255,255,255)); setSpecularColor(ofColor(255,255,255)); setPointLight(); // assume default attenuation factors // setAttenuation(1.f,0.f,0.f); }
//---------------------------------------- void ofLight::setup() { if(data->glIndex==-1){ bool bLightFound = false; // search for the first free block for(size_t i=0; i<ofLightsData().size(); i++) { if(ofLightsData()[i].expired()) { data->glIndex = i; data->isEnabled = true; ofLightsData()[i] = data; bLightFound = true; break; } } if(!bLightFound && ofIsGLProgrammableRenderer()){ ofLightsData().push_back(data); data->glIndex = ofLightsData().size() - 1; data->isEnabled = true; bLightFound = true; } if( bLightFound ){ // run this the first time, since it was not found before // onPositionChanged(); setAmbientColor( getAmbientColor() ); setDiffuseColor( getDiffuseColor() ); setSpecularColor( getSpecularColor() ); setAttenuation( getAttenuationConstant(), getAttenuationLinear(), getAttenuationQuadratic() ); if(getIsSpotlight()) { setSpotlightCutOff(getSpotlightCutOff()); setSpotConcentration(getSpotConcentration()); } if(getIsSpotlight() || getIsDirectional()) { onOrientationChanged(); } }else{ ofLogError("ofLight") << "setup(): couldn't get active GL light, maximum number of "<< ofLightsData().size() << " reached"; } } }
void ofMaterial::setColors(ofFloatColor oDiffuse, ofFloatColor oAmbient, ofFloatColor oSpecular, ofFloatColor oEmissive) { setDiffuseColor(oDiffuse); setAmbientColor(oAmbient); setSpecularColor(oSpecular); setEmissiveColor(oEmissive); }
Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatrixUniform(1), normalMatrixUniform(2), lightUniform(3), diffuseColorUniform(4), ambientColorUniform(5), specularColorUniform(6), lightColorUniform(7), shininessUniform(8), _flags(flags) { #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ if(!Utility::Resource::hasGroup("MagnumShaders")) importShaderResources(); #endif Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES const Version version = Context::current().supportedVersion({Version::GL320, Version::GL310, Version::GL300, Version::GL210}); #else const Version version = Context::current().supportedVersion({Version::GLES300, Version::GLES200}); #endif Shader vert = Implementation::createCompatibilityShader(rs, version, Shader::Type::Vertex); Shader frag = Implementation::createCompatibilityShader(rs, version, Shader::Type::Fragment); vert.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs.get("generic.glsl")) .addSource(rs.get("Phong.vert")); frag.addSource(flags & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "") .addSource(flags & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "") .addSource(flags & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n" : "") .addSource(rs.get("Phong.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag})); attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>(version)) #else if(!Context::current().isVersionSupported(Version::GLES300)) #endif { bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Normal::Location, "normal"); if(flags) bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); } CORRADE_INTERNAL_ASSERT_OUTPUT(link()); #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) #endif { transformationMatrixUniform = uniformLocation("transformationMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix"); normalMatrixUniform = uniformLocation("normalMatrix"); lightUniform = uniformLocation("light"); ambientColorUniform = uniformLocation("ambientColor"); diffuseColorUniform = uniformLocation("diffuseColor"); specularColorUniform = uniformLocation("specularColor"); lightColorUniform = uniformLocation("lightColor"); shininessUniform = uniformLocation("shininess"); } #ifndef MAGNUM_TARGET_GLES if(flags && !Context::current().isExtensionSupported<Extensions::GL::ARB::shading_language_420pack>(version)) #endif { if(flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureLayer); if(flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureLayer); if(flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureLayer); } /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ #ifdef MAGNUM_TARGET_GLES /* Default to fully opaque white so we can see the textures */ if(flags & Flag::AmbientTexture) setAmbientColor(Color4{1.0f}); else setAmbientColor(Color4{0.0f, 1.0f}); if(flags & Flag::DiffuseTexture) setDiffuseColor(Color4{1.0f}); setSpecularColor(Color4{1.0f}); setLightColor(Color4{.0f}); setShininess(80.0f); #endif }
//---------------------------------------- void ofLight::setSpecularColor(float r, float g, float b, float a) { setSpecularColor(ofColor(r, g, b, a)); }