void ofxPBR::setup(function<void()> scene, ofCamera* camera, int depthMapResolution) { this->scene = scene; this->camera = camera; sphereMesh = ofSpherePrimitive(1, 100).getMesh(); for (int i = 0; i<sphereMesh.getNormals().size(); i++) { sphereMesh.setNormal(i, ofVec3f(1.0, 1.0, -1.0) * glm::normalize(sphereMesh.getVertex(i))); } spotShadow.setup(4, depthMapResolution); omniShadow.setup(1, depthMapResolution); directionalShadow.setup(1, depthMapResolution); directionalShadow.setBoundingBox(0, 0, 0, 1000, 1000, 1000); renderMode = Mode_PBR; // load env shader envShader = new ofShader(); envShader->setupShaderFromSource(GL_VERTEX_SHADER, environmentShaderSource.gl3VertShader); envShader->setupShaderFromSource(GL_FRAGMENT_SHADER, environmentShaderSource.gl3FragShader); envShader->bindDefaults(); envShader->linkProgram(); // load defalut pbr shader defaultShader = ofShader(); defaultShader.setupShaderFromSource(GL_VERTEX_SHADER, pbrShaderSource.gl3VertShader); defaultShader.setupShaderFromSource(GL_FRAGMENT_SHADER, pbrShaderSource.gl3FragShader); defaultShader.bindDefaults(); defaultShader.linkProgram(); }
//---------- void Register::traverseDirectoryShaders(string dataPath, vector<string> outputNamespace) { if (ofDirectory::doesDirectoryExist(dataPath)) { ofDirectory files; files.listDir(dataPath); for (int i = 0; i<files.size(); i++) { const auto filename = files.getPath(i); auto outputName = ofFilePath::getBaseName(filename); //check if it's a subfolder if (ofDirectory(filename).isDirectory()) { auto innerNamespace = outputNamespace; innerNamespace.push_back(outputName); this->traverseDirectoryShaders(dataPath + "/" + outputName, innerNamespace); } //if not, check whether it has the right extension const auto extension = ofFilePath::getFileExt(filename); if (!(extension == "vert" || extension == "frag" || extension == "geom")) { continue; } //transform the output name to include namespace transformName(outputName, outputNamespace); //check if the shader already exists (this often happens when you hit a .vert file and we've already loaded when we hit the .geom) if (this->shaders.find(outputName) != this->shaders.end()) { continue; } //insert the shader this->shaders.insert(pair<string, ofShader>(outputName, ofShader())); auto & shader = this->shaders[outputName]; //load any available shader stages const auto withoutExtension = filename.substr(0, filename.length() - extension.length() - 1); if (ofFile::doesFileExist(withoutExtension + ".frag")) shader.setupShaderFromFile(GL_FRAGMENT_SHADER, withoutExtension + ".frag"); if (ofFile::doesFileExist(withoutExtension + ".vert")) shader.setupShaderFromFile(GL_VERTEX_SHADER, withoutExtension + ".vert"); #ifndef TARGET_IPHONE_SIMULATOR if (ofFile::doesFileExist(withoutExtension + ".geom")) shader.setupShaderFromFile(GL_GEOMETRY_SHADER, withoutExtension + ".geom"); #endif shader.linkProgram(); ofLogNotice("ofxAssets") << "Loaded shader asset '" << outputName << "'" << endl; } } }
LightScene::LightScene(vector<Particle*>* people, vector<Particle*>* hands) : IScene(people, hands) { const ofVec2f fogVerts[] = { ofVec2f(0.f, 0.f), ofVec2f(ofGetWidth(), 0.f), ofVec2f(ofGetWidth(), ofGetHeight()), ofVec2f(0.0f, ofGetHeight()) }; pPeople = people; pHandPositions = hands; //load all images m_hexImgBorder.loadImage("LightScene/hex-02.png"); m_hexImgInner.loadImage("LightScene/hex-03.png"); m_lightImg.loadImage("LightScene/light.png"); m_fogImg.loadImage("LightScene/fog.png"); m_lights = vector<Light>(); for(int i = 0; i < ofGetWidth(); i += m_lightImg.width){ Light l = Light(); l.isOn = false; l.x = i; m_lights.push_back(l); } //create an image that holds is the length of the amount of lights. set pixel to white if light is on m_lightsOnTexture.allocate(m_lights.size(), 1, GL_LUMINANCE); m_lightsOnTexture.clear(); m_lightsOnTexture.readToPixels(m_lightsOnPixels); //setting up shader for fog m_fogShader = ofShader(); m_fogShader.load("LightScene/fog"); m_fogVbo = ofVbo(); m_fogVbo.setVertexData( &fogVerts[0], 4, GL_STATIC_DRAW); m_fogVbo.setTexCoordData(&s_fogTexCoords[0], 4, GL_STATIC_DRAW); m_fogInt = 0; }
//--------- void Register::loadAssets(string addon) { ofLogNotice("ofxAssets") << "//--------------------"; ofLogNotice("ofxAssets") << "//ofxAssets::init"; ofLogNotice("ofxAssets") << "//--------------------"; ofLogNotice("ofxAssets") << "//"; string filename, name, extension, withoutExtension, folder; ofDirectory files; string dataPath = "assets"; if (addon.size() > 0) { dataPath += "/" + addon; } if (!ofDirectory::doesDirectoryExist(dataPath)) { ofLogNotice("ofxAssets") << "Assets data path cannot be found. Be sure to have a ./assets subfolder inside your app's data/ folder if you want to use ofxAssets"; return; } //// //images //// // folder = ofToDataPath(dataPath + "/images/", true); if (ofDirectory::doesDirectoryExist(folder)) { files.listDir(folder); for (int i=0; i<files.size(); i++) { filename = files.getPath(i); extension = ofFilePath::getFileExt(filename); withoutExtension = filename.substr(0, filename.length() - extension.length() - 1); name = ofFilePath::getBaseName(filename); transformName(name, addon); if (!(extension == "png" || extension == "jpeg" || extension == "jpg")) continue; if (this->images.count(name) > 0) continue; this->images.insert(pair<string, ofImage>(name, ofImage())); this->images[name].loadImage(filename); ofLogNotice("ofxAssets") << "Loaded image asset '" << name << "'" << endl; } } // //// //// //shaders //// // folder = ofToDataPath(dataPath + "/shaders/", true); if (ofDirectory::doesDirectoryExist(folder)) { files.listDir(folder); bool hasFrag, hasVert; for (int i=0; i<files.size(); i++) { filename = files.getPath(i); extension = ofFilePath::getFileExt(filename); withoutExtension = filename.substr(0, filename.length() - extension.length() - 1); name = ofFilePath::getBaseName(filename); transformName(name, addon); if (!(extension == "vert" || extension == "frag" || extension == "geom")) continue; if (this->shaders.count(name) > 0) continue; this->shaders.insert(pair<string, ofShader>(name, ofShader())); if (ofFile::doesFileExist(withoutExtension + ".frag")) this->shaders[name].setupShaderFromFile(GL_FRAGMENT_SHADER, withoutExtension + ".frag"); if (ofFile::doesFileExist(withoutExtension + ".vert")) this->shaders[name].setupShaderFromFile(GL_VERTEX_SHADER, withoutExtension + ".vert"); if (ofFile::doesFileExist(withoutExtension + ".geom")) this->shaders[name].setupShaderFromFile(GL_GEOMETRY_SHADER, withoutExtension + ".geom"); this->shaders[name].linkProgram(); ofLogNotice("ofxAssets") << "Loaded shader asset '" << name << "'" << endl; } } // //// //// //fonts //// // folder = ofToDataPath(dataPath + "/fonts/", true); if (ofDirectory::doesDirectoryExist(folder)) { files.listDir(folder); for (int i=0; i<files.size(); i++) { filename = files.getPath(i); extension = ofFilePath::getFileExt(filename); withoutExtension = filename.substr(0, filename.length() - extension.length() - 1); name = ofFilePath::getBaseName(filename); transformName(name, addon); if (!(extension == "ttf")) continue; if (this->fontFilenames.count(name) > 0) continue; this->fontFilenames.insert(pair<string, string>(name, filename)); ofLogNotice("ofxAssets") << "Found font asset '" << name << "'" << endl; } } // //// //// //videos //// // folder = ofToDataPath(dataPath + "/videos/", true); if (ofDirectory::doesDirectoryExist(folder)) { files.listDir(folder); for (int i=0; i<files.size(); i++) { filename = files.getPath(i); extension = ofFilePath::getFileExt(filename); withoutExtension = filename.substr(0, filename.length() - extension.length() - 1); name = ofFilePath::getBaseName(filename); transformName(name, addon); if (!(extension == "mov")) continue; if (this->videos.count(name) > 0) continue; this->videos.insert(pair<string, ofVideoPlayer>(name, ofVideoPlayer())); this->videos[name].loadMovie(filename); this->videos[name].play(); ofLogNotice("ofxAssets") << "Loaded video asset '" << name << "'" << endl; } } // //// ofLogNotice("ofxAssets") << "//"; ofLogNotice("ofxAssets") << "//--------------------"; ofNotifyEvent(evtLoad, *this, this); }