void UIShader::checkShaderFile(){ int currTime = ofGetElapsedTimeMillis(); if( ((currTime - lastTimeCheckMillis) > millisBetweenFileCheck) ){ if( fragFile.exists() ){ std::time_t fragmentShaderFileLastChangeTime = getLastModified( fragFile ); if( fragmentShaderFileLastChangeTime != fragChangedTimes ){ fragChangedTimes = fragmentShaderFileLastChangeTime; reloadShader(fragFilename,vertFilename,geomFilename); } else if (bVertex){ if( vertFile.exists() ){ std::time_t vertexShaderFileLastChangeTime = getLastModified( vertFile ); if( vertexShaderFileLastChangeTime != vertChangedTimes ){ vertChangedTimes = vertexShaderFileLastChangeTime; reloadShader(fragFilename,vertFilename,geomFilename); } } if( geomFile.exists() ){ std::time_t geometryShaderFileLastChangeTime = getLastModified( geomFile ); if( geometryShaderFileLastChangeTime != geomChangedTimes ){ vertChangedTimes = geometryShaderFileLastChangeTime; reloadShader(fragFilename,vertFilename,geomFilename); } } } } lastTimeCheckMillis = currTime; } }
// selfSetup is called when the visual system is first instantiated // This will be called during a "loading" screen, so any big images or // geometry should be loaded here void CloudsVisualSystemLaplacianTunnel::selfSetup(){ frameCount = 0; bUseExternalCamera = false; bPalindrome = false; lastFrameTime = 0; growthFPS = 0; currentGrowthIndex = 0; ofDirectory objs(GetCloudsMediaPath() + "assets/LaplacianTunnel/Meshes/"); objs.allowExt("vbo"); objs.listDir(); clear(); min.set(999999); max.set(-99999); center.set(14.000,5.900,-13.950); int numFiles = objs.numFiles(); vbos.resize( numFiles ); for(int i = 0; i < numFiles; i++){ vbos[i].vbo = new ofVboByteColor(); vbos[i].name = objs.getName(i); vbos[i].indexCount = loadMesh(*vbos[i].vbo, objs.getPath( i ) ); //vbos[i].indexCount = loadMeshPLY(*vbos[i].vbo, objs.getPath( i ) ); } sort(vbos.begin(), vbos.end(), meshsort); reloadShader(); tunnelCam.setNearClip(.01); tunnelCam.setFov(70); }
ofxRGBDRenderer::ofxRGBDRenderer(){ //come up with better names xmult = 0; ymult = 0; edgeCull = 4000; simplify = 1; farClip = 6000; ZFuzz = 0; meshRotate = ofVec3f(0,0,0); calculateNormals = false; hasDepthImage = false; hasRGBImage = false; shaderBound = false; rendererBound = false; mirror = false; calibrationSetup = false; reloadShader(); setSimplification(1); hasVerts = false; forceUndistortOff = false; addColors = false; calculateTextureCoordinates = false; }
void Goal::setup() { loader_.setScaleNomalization(false); loader_.loadModel("goal.obj"); goal_ = loader_.getMesh(0); setPosition(28.2, 51.607, 187.8); reloadShader(); }
bool RendererServiceSetFocalDistance::reload(const std::string& shaderPath, Logger* logger) { return reloadShader(shaderPath, "FocalDistance", "focalDistance/focalDistance.vs", "shared/trivial.fs", logger); }
//-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ vector<string> file = ofSplitString(dragInfo.files[0], "."); if ( file[1] == "fs" || file[1] == "frg" || file[1] == "frag" ) { cout << dragInfo.files[0] << " loaded"<< endl; reloadShader(dragInfo.files[0]); } }
void Bloom::initialize(uint a_xRes, uint a_yRes) { m_bloomResultTexture.initialize(GLTexture::ESizedFormat::RGB8, a_xRes, a_yRes, GLConfig::getMultisampleType()); m_bloomResultFBO.initialize(GLConfig::getMultisampleType()); m_bloomResultFBO.addFramebufferTexture(m_bloomResultTexture); m_gaussianBlur.initialize(GaussianBlur::EBlurValueType::VEC3, a_xRes, a_yRes); reloadShader(); m_initialized = true; }
bool UIShader::loadFrag(string _fragShader){ bVertex = false; ofFile fragFile = ofFile(_fragShader); if (!fragFile.exists() ){ ofBuffer frag; frag.append(fragmentShader); ofBufferToFile(_fragShader, frag); } return reloadShader( _fragShader ); }
void testApp::checkShaderFile(){ int currTime = ofGetElapsedTimeMillis(); if( ((currTime - lastTimeCheckMillis) > millisBetweenFileCheck) ){ if( shaderFile.exists() ){ std::time_t fragmentShaderFileLastChangeTime = getLastModified( shaderFile ); if( fragmentShaderFileLastChangeTime != shaderChangedTimes ){ shaderChangedTimes = fragmentShaderFileLastChangeTime; reloadShader(); } } lastTimeCheckMillis = currTime; } }
void MainWindow::shaderAction(int type) { QString errMessage; bool useUserShader = false; wz_shader_type_t stype = static_cast<wz_shader_type_t>(type); if (m_actionEnableUserShaders->isChecked()) { useUserShader = reloadShader(stype, true, &errMessage); if (!useUserShader) { QMessageBox::warning(this, "External shaders error", "Unable to load external shaders, so please ensure that they are correct and hit reload!"\ "\nNOTE: Model might temporarily go into stealth mode due to this error...\n\n" + errMessage); } }; if (!useUserShader) reloadShader(stype, false); if (static_cast<wz_shader_type_t>(type) != WZ_SHADER_NONE) { if (!m_model.setActiveShader(static_cast<wz_shader_type_t>(type))) { QMessageBox::warning(this, "Shaders error", "Unable to activate requested shaders!"); } } else { m_model.disableShaders(); } updateModelRender(); setWindowTitle(buildAppTitle()); }
//-------------------------------------------------------------- void testApp::setup(){ ofEnableAlphaBlending(); ofSetVerticalSync(true); // ofSetDataPathRoot("data/"); ofSetWindowShape(640, 480); millisBetweenFileCheck = 2 * 1000; oscReceiver.setup(PORT); sServer.setName(ofGetTimestampString("%H-%M-%S")); pingpong.allocate(ofGetScreenWidth(), ofGetScreenHeight()); video = NULL; reloadShader("shader.fs"); }
void CpuClipmapRenderer::onCreateGpuResources() { assert( window_ ); #ifndef OLD_GEOCLIP _pTerrainShader = SimpleSHLChunk::create(); #endif reloadShader(); const int levelCount = int(levels_.size()); // if the extension is supported: useVertexBufferObjects_ = true; for( int i = 0; i < levelCount; ++i ) { TerrainLevelRenderData& levelData = levels_[ i ]; GeometryClipmapLevel& level = geoClipmaps_->getLevel( i ); // create vbo for the vertex data: // todo: create a dynamic vbo for the index data? const int vertexCount = int(levelData.vertices.size()); // todo: use ReadOnly Vbo (for speed) if( !levelData.vertexBuffer.create( window_, GL_ARRAY_BUFFER_ARB, sizeof( OpenGLTerrainVertex ) * vertexCount, BufferUsage_Dynamic_ReadWrite ) ) { useVertexBufferObjects_ = false; break; } levelData.vertexBuffer.uploadData( &levelData.vertices[ 0 ], 0, sizeof( OpenGLTerrainVertex ) * vertexCount ); levelData.vertexBuffer.deactivate(); // create the texture: levelData.texture = TextureObjChunk::create(); levelData.texture->setImage( level.textureData ); levelData.texture->setMinFilter( GL_NEAREST ); // TODO: use linear min/mag filters (but no mipmapping! levelData.texture->setMagFilter( GL_NEAREST ); levelData.texture->setWrapS( GL_REPEAT ); levelData.texture->setWrapT( GL_REPEAT ); //levelData.texture->setEnvMode( GL_MODULATE ); } }
//-------------------------------------------------------------- void ofApp::setup(){ // OF init ofEnableDepthTest(); oculusRift.baseCamera = &cam; oculusRift.setup(); oculusRift.fullscreenOnRift(); reloadShader(); // rect textures are fine by default in GL3, we can just use GL_TEXTURE_2D. // disabling allows simpler normalized texture coordinates, not pixel coords ofDisableArbTex(); panoLeft.loadImage("panoL.jpg"); panoRight.loadImage("panoR.jpg"); cam.setAutoDistance(false); }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ // dismiss safety warning on any key oculusRift.dismissSafetyWarning(); if( key == 'f' ) { //gotta toggle full screen for it to be right ofToggleFullscreen(); } if(key == 's'){ reloadShader(); } if(key == 'v'){ oculusRift.setNoVsync( !oculusRift.getNoVsync() ); } if(key == 'z'){ cout << "FPS: " << ofGetFrameRate() << endl; } }
void MainWindow::viewerInitialized() { // Only do init once disconnect(m_ui->centralWidget, SIGNAL(viewerInitialized()), this, SLOT(viewerInitialized())); m_ui->centralWidget->addToRenderList(&m_model); m_ui->centralWidget->addToAnimateList(&m_model); m_meshDock->setModel(&m_model); m_actionEnableUserShaders = new QAction("Enable external shaders", this); m_actionEnableUserShaders->setCheckable(true); m_actionEnableUserShaders->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E)); connect(m_actionEnableUserShaders, SIGNAL(triggered(bool)), this, SLOT(actionEnableUserShaders(bool))); m_actionLocateUserShaders = new QAction("Locate external shaders...", this); m_actionLocateUserShaders->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); connect(m_actionLocateUserShaders, SIGNAL(triggered()), this, SLOT(actionLocateUserShaders())); m_actionReloadUserShaders = new QAction("Reload external shaders", this); m_actionReloadUserShaders->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); connect(m_actionReloadUserShaders, SIGNAL(triggered()), this, SLOT(actionReloadUserShader())); m_shaderGroup = new QActionGroup(this); for (int i = WZ_SHADER__FIRST; i < WZ_SHADER__LAST; ++i) { QString shadername = QWZM::shaderTypeToString(static_cast<wz_shader_type_t>(i)); QAction* shaderAct = new QAction(shadername, this); m_shaderSignalMapper->setMapping(shaderAct, i); shaderAct->setActionGroup(m_shaderGroup); if (i < 9) // FIXME shaderAct->setShortcut(QKeySequence(tr("Ctrl+%1").arg(i+1))); shaderAct->setCheckable(true); reloadShader(static_cast<wz_shader_type_t>(i), false); connect(shaderAct, SIGNAL(triggered()), m_shaderSignalMapper, SLOT(map())); } connect(m_shaderSignalMapper, SIGNAL(mapped(int)), this, SLOT(shaderAction(int))); QMenu* rendererMenu = new QMenu(this); rendererMenu->addActions(m_shaderGroup->actions()); // other user shader related stuff rendererMenu->addSeparator(); rendererMenu->addAction(m_actionEnableUserShaders); rendererMenu->addAction(m_actionLocateUserShaders); rendererMenu->addAction(m_actionReloadUserShaders); m_ui->actionRenderer->setMenu(rendererMenu); connect(m_ui->actionShowModelCenter, SIGNAL(triggered(bool)), &m_model, SLOT(setDrawCenterPointFlag(bool))); connect(m_ui->actionShowNormals, SIGNAL(triggered(bool)), &m_model, SLOT(setDrawNormalsFlag(bool))); connect(m_ui->actionShowNormals, SIGNAL(triggered(bool)), m_ui->actionShow_Tangent_And_Bitangent, SLOT(setEnabled(bool))); connect(m_ui->actionShow_Tangent_And_Bitangent, SIGNAL(triggered(bool)), &m_model, SLOT(setDrawTangentAndBitangentFlag(bool))); connect(m_ui->actionShow_Connectors, SIGNAL(triggered(bool)), &m_model, SLOT(setDrawConnectors(bool))); /// Load previous state m_ui->actionShowModelCenter->setChecked(m_settings->value("3DView/ShowModelCenter", false).toBool()); m_model.setDrawCenterPointFlag(m_ui->actionShowModelCenter->isChecked()); m_ui->actionShowNormals->setChecked(m_settings->value("3DView/ShowNormals", false).toBool()); m_model.setDrawNormalsFlag(m_ui->actionShowNormals->isChecked()); m_ui->actionShow_Connectors->setChecked(m_settings->value("3DView/ShowConnectors", false).toBool()); m_model.setDrawConnectors(m_ui->actionShow_Connectors->isChecked()); m_ui->actionShow_Tangent_And_Bitangent->setChecked(m_settings->value("3DView/ShowTangentAndBitangent", false).toBool()); m_model.setDrawTangentAndBitangentFlag(m_ui->actionShow_Tangent_And_Bitangent->isChecked()); m_ui->actionShow_Tangent_And_Bitangent->setEnabled(m_ui->actionShowNormals->isChecked()); m_ui->actionShowAxes->setChecked(m_settings->value("3DView/ShowAxes", true).toBool()); m_ui->actionShowGrid->setChecked(m_settings->value("3DView/ShowGrid", true).toBool()); m_ui->actionShowLightSource->setChecked(m_settings->value("3DView/ShowLightSource", true).toBool()); m_ui->actionLink_Light_Source_To_Camera->setChecked(m_settings->value("3DView/LinkLightToCamera", true).toBool()); m_actionEnableUserShaders->setChecked(m_settings->value("3DView/EnableUserShaders", false).toBool()); m_ui->actionAnimate->setChecked(m_settings->value("3DView/Animate", true).toBool()); actionEnableUserShaders(m_actionEnableUserShaders->isChecked()); // Default to 3.1 int shaderTag = m_settings->value("3DView/ShaderTag", wz_shader_type_tag[WZ_SHADER_WZ31]).toInt(); int shaderActIdx = -1; for (int i = WZ_SHADER__FIRST; i < WZ_SHADER__LAST; ++i) { if (shaderTag == wz_shader_type_tag[i]) shaderActIdx = i; } // Select any previous selection if (shaderActIdx >= 0) { if (m_shaderGroup->actions().at(shaderActIdx)->isEnabled()) m_shaderGroup->actions().at(shaderActIdx)->activate(QAction::Trigger); else shaderActIdx = -1; } // Otherwise use old approach if (shaderActIdx < 0) { for (int i = m_shaderGroup->actions().size() - 1; i >= 0; --i) { if (m_shaderGroup->actions().at(i)->isEnabled()) { m_shaderGroup->actions().at(i)->activate(QAction::Trigger); break; } } } }
void App::update(float delta_time) { if (anim_play) frame_count++; if (!hide_gui) gui(); // autoreload frag shader (every 60 frames) if (shader_filepath && shader_file_autoreload && (frame_count % 60) == 0) { struct stat attr; if (!stat(shader_filepath, &attr)) { // file exists if (attr.st_mtime > shader_file_mtime) { // file has been modified shader_file_mtime = (int)attr.st_mtime; reloadShader(); } } } // update camera (-z: forward, y: up) camera_euler_angles += 2.0f*delta_time * v3(-movement_command.rotate.x, -movement_command.rotate.y, 0.0f); camera_euler_angles.x = fminf(fmaxf(-0.5f*(float)M_PI, camera_euler_angles.x), 0.5f*(float)M_PI); // clamp mat3 rot_x = rotationMatrix(v3(1.0f, 0.0f, 0.0f), camera_euler_angles.x); mat3 rot_y = rotationMatrix(v3(0.0f, 1.0f, 0.0f), camera_euler_angles.y); mat3 rot_z = rotationMatrix(v3(0.0f, 0.0f, 1.0f), camera_euler_angles.z); mat3 rot = rot_y * rot_x * rot_z; camera_location += rot * (8.0f*delta_time*movement_command.move); mat4 view_to_world = translationMatrix(camera_location) * m4(rot); mat4 world_to_view = m4(transpose(rot)) * translationMatrix(-camera_location); // bind textures for (int tsi = 0; tsi < (int)ARRAY_COUNT(texture_slots); tsi++) { glActiveTexture(GL_TEXTURE0+tsi); glBindTexture(texture_slots[tsi].target, texture_slots[tsi].texture); } // draw fullscreen triangle(s) glClearColor(0.2f, 0.21f, 0.22f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); { BindShader bind_shader(shader); if (!compile_error_log) { for (int i = 0; i < uniform_count; i++) { uniforms[i].apply(); } } // apply builtin uniforms u_time = (float)frame_count / 60.0f; glUniform1f(shader.getUniformLocation(u_time_name), u_time); vec2 u_resolution = v2(video.pixel_scale*video.width, video.pixel_scale*video.height); glUniform2fv(shader.getUniformLocation(u_resolution_name), 1, u_resolution.e); glUniformMatrix4fv(shader.getUniformLocation(u_view_to_world_name), 1, GL_FALSE, view_to_world.e); glUniformMatrix4fv(shader.getUniformLocation(u_world_to_view_name), 1, GL_FALSE, world_to_view.e); if (single_triangle_mode) { { BindArrayBuffer bind_array_buffer(single_triangle_vbo); glEnableVertexAttribArray(VAT_POSITION); glVertexAttribPointer(VAT_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(VAT_POSITION); } } else { { BindArrayBuffer bind_array_buffer(two_triangles_vbo); glEnableVertexAttribArray(VAT_POSITION); glVertexAttribPointer(VAT_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableVertexAttribArray(VAT_POSITION); } } } }
//events are called when the system is active //Feel free to make things interactive for you, and for the user! void CloudsVisualSystemLaplacianTunnel::selfKeyPressed(ofKeyEventArgs & args){ if(args.key == 'R'){ reloadShader(); } }
bool UIShader::load(string _fragShader, string _vertShader, string _geomShader){ return reloadShader(_fragShader,_vertShader, _geomShader); }
void CpuClipmapRenderer::onRender( const ClipmapRenderParameters& renderParameters ) { // activate the gpu program: //glDisable( GL_LIGHTING ); #ifdef OLD_GEOCLIP terrainShader_.activate(); if( programTextChanged_ ) { reloadShader(); programTextChanged_ = false; } #else _pTerrainShader->activate(renderParameters.drawEnv); #endif // bool useDependentTextureLookup = false; if( renderParameters.globalTextureObj != NULL ) { renderParameters.globalTextureObj->activate( renderParameters.drawEnv ); renderParameters.globalTextureEnv->activate( renderParameters.drawEnv ); } else if( renderParameters.heightColorTexture != NULL ) { // todo: use a different pixel shader here // useDependentTextureLookup = true; renderParameters.heightColorTexture->activate( renderParameters.drawEnv ); } // render all levels from finest to coarsest: const int levelCount = int(levels_.size()); // for( int i = 0; i < levelCount; ++i ) for( int i = 0; i < levelCount; ++i ) { int levelIdx = levelCount - i - 1; //std::cerr << "Rendering Level " << levelIdx << std::endl; GeometryClipmapLevel& level = geoClipmaps_->getLevel( levelIdx ); GeometryClipmapLevel* coarserLevel = 0; GeometryClipmapLevel* finerLevel = 0; if( levelIdx > 0 ) { coarserLevel = &geoClipmaps_->getLevel( levelIdx - 1 ); } if( levelIdx + 1 < levelCount ) { finerLevel = &geoClipmaps_->getLevel( levelIdx + 1 ); } const Color3f& debugColor = getDebugColor( levelIdx ); #ifdef OLD_GEOCLIP terrainShader_.setUniform( "baseColor0", colorToVector( debugColor ) ); terrainShader_.setUniform( "sampleDistance", renderParameters.worldTransform.sampleDistance ); terrainShader_.setUniform( "worldOffset", renderParameters.worldTransform.offset ); terrainShader_.setUniform( "heightScale", renderParameters.worldTransform.heightScale ); terrainShader_.setUniform( "heightOffset", renderParameters.worldTransform.heightOffset ); #else #ifdef NOTUSED _pTerrainShader->setUniformParameter( "baseColor0", colorToVector( debugColor ) ); #endif _pTerrainShader->addUniformVariable( "sampleDistance", renderParameters.worldTransform.sampleDistance ); _pTerrainShader->addUniformVariable( "worldOffset", renderParameters.worldTransform.offset ); _pTerrainShader->addUniformVariable( "heightScale", renderParameters.worldTransform.heightScale ); _pTerrainShader->addUniformVariable( "heightOffset", renderParameters.worldTransform.heightOffset ); #endif if( renderParameters.showTransitionRegions ) { // todo: add a sensible debug representation.. drawSampleRectangle( level.getCoveredSampleRect(), debugColor, renderParameters.worldTransform ); //drawSamples( level, Color3f( 0, 1, 0 ) ); //drawVertices( level, debugColor ); drawBlendLines( level, debugColor, renderParameters.worldTransform ); } if( !level.isActive ) { continue; } // only use the finer level, if it is active: if( finerLevel && !finerLevel->isActive ) { finerLevel = 0; } // buildIndices dynamically builds the indices for this level and // does frustum culling // the method returns false if nothing is visible // todo: dont rebuild the indices every time.. just rebuild them if // something changed (inside the update() call) if( buildIndices( level, finerLevel ) ) { // finally: draw the block: renderBlock( level, coarserLevel, renderParameters, debugColor ); } stats_.drawnLevelCount++; } if( renderParameters.globalTextureObj != NULL ) { renderParameters.globalTextureObj->deactivate( renderParameters.drawEnv ); renderParameters.globalTextureEnv->deactivate( renderParameters.drawEnv ); } else if(renderParameters.heightColorTexture != NULL) { renderParameters.heightColorTexture->deactivate( renderParameters.drawEnv ); } #ifdef OLD_GEOCLIP terrainShader_.deactivate(); #else _pTerrainShader->deactivate(renderParameters.drawEnv); #endif }
void Raycaster::draw( GLint volumeTextureHandle, GLint importanceVolumeTextureHandle, glm::vec3 volumeScale, glm::vec3 volumeResolution, VolumeProperties volumeProperties, GLfloat aspectRatio, GLfloat fieldOfView, glm::vec3 cameraPosition, glm::mat4 viewMatrix, glm::vec3 sunDirection, glm::vec3 sunColor, GLfloat sunBrightness, glm::vec3 ambientColor, GLint colorAlphaFunctionHandle, GLint ambientSpecularFunctionHandle, GLint advancedFunctionHandle, GLint colorAlphaPreintegrationHandle, GLint ambientSpecularPreintegrationHandle, GLint advancedPreintegrationHandle, GLint tfResolution, GLint reflectionHandle, glm::vec3 volumeExtent, glm::vec3 volumeExtentOffset) { if(shaderShouldBeReloaded) { reloadShader(); shaderShouldBeReloaded = GL_FALSE; } // basicInput.x has many jobs // Standard: stepSize // Adaptive Sampling: minAdaptiveStepSize // Voxel Spaced Samp.: stepSizeMultiplier // Ad. Voxel Spaced Samp.: minAdaptiveStepSizeMultiplier // Set basic input (need not to be set each frame..) glm::vec4 basicInput; GLfloat stepSize; GLfloat minAdaptiveStepSize; GLfloat maxAdaptiveStepSize; // When voxel spaced sampling is used, step size depends on direction and volume if(!useVoxelSpacedSampling) { stepSize = properties.stepSize; minAdaptiveStepSize = properties.minAdaptiveStepSize; maxAdaptiveStepSize = properties.maxAdaptiveStepSize; } else { stepSize = 1; minAdaptiveStepSize = 1; maxAdaptiveStepSize = 1; } if(useAdaptiveSampling) { // Max adaptive step size is filled into advanced input's w value basicInput.x = minAdaptiveStepSize * properties.minAdaptiveStepSizeMultiplier; } else { basicInput.x = stepSize * properties.stepSizeMultiplier; } basicInput.y = static_cast<GLfloat>(properties.outerIterations); basicInput.z = static_cast<GLfloat>(properties.innerIterations); basicInput.w = properties.alphaThreshold; // Set advanced input glm::vec4 advancedInput; advancedInput.x = properties.jitteringRangeMultiplier; advancedInput.y = properties.normalRangeMultiplier; advancedInput.z = properties.fresnelPower; advancedInput.w = maxAdaptiveStepSize * properties.maxAdaptiveStepSizeMultiplier; // Set volume value information glm::vec2 volumeValueInformation; volumeValueInformation.x = volumeProperties.valueOffset; volumeValueInformation.y = volumeProperties.valueScale; glm::vec3 mirrorUVW(0,0,0); if(volumeProperties.mirrorX) { mirrorUVW.x = 1; } if(volumeProperties.mirrorY) { mirrorUVW.y = 1; } if(volumeProperties.mirrorZ) { mirrorUVW.z = 1; } // Compute model matrix glm::mat4 modelScaleMatrix = glm::mat4(1.0f); glm::mat4 modelRotationMatrix = glm::mat4(1.0f); modelScaleMatrix = glm::scale(modelScaleMatrix, volumeProperties.voxelScaleMultiplier * volumeScale); modelRotationMatrix = glm::rotate(modelRotationMatrix, glm::radians(volumeProperties.eulerZXZRotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); modelRotationMatrix = glm::rotate(modelRotationMatrix, glm::radians(volumeProperties.eulerZXZRotation.y), glm::vec3(1.0f, 0.0f, 0.0f)); modelRotationMatrix = glm::rotate(modelRotationMatrix, glm::radians(volumeProperties.eulerZXZRotation.x), glm::vec3(0.0f, 0.0f, 1.0f)); // Compute projection matrix glm::mat4 projectionMatrix = glm::perspective(glm::radians(fieldOfView), aspectRatio, 0.1f, 100.f); // Use program because setUniform needs ist shader.use(); // Set matrices and vectors shader.setUniformValue(uniformModelScaleHandle, modelScaleMatrix); shader.setUniformValue(uniformModelRotationHandle, modelRotationMatrix); shader.setUniformValue(uniformViewHandle, viewMatrix); shader.setUniformValue(uniformProjectionHandle, projectionMatrix); shader.setUniformValue(uniformCameraPosHandle, cameraPosition); shader.setUniformValue(uniformBasicInputHandle, basicInput); shader.setUniformValue(uniformAdvancedInputHandle, advancedInput); shader.setUniformValue(uniformVolumeValueInformationHandle, volumeValueInformation); shader.setUniformValue(uniformMirrorUVWHandle, mirrorUVW); // Volume clipping glm::mat4 volumeExtentMatrix = glm::mat4(1.0f); volumeExtentMatrix = glm::scale(volumeExtentMatrix, volumeExtent); shader.setUniformValue(uniformVolumeExtentHandle, volumeExtentMatrix); shader.setUniformValue(uniformVolumeExtentOffsetHandle, volumeExtentOffset); // Set up depending on defines shader.setUniformTexture(uniformVolumeHandle, volumeTextureHandle, GL_TEXTURE_3D); if(usePreintegration) { shader.setUniformTexture(uniformColorAlphaPreintegrationHandle, colorAlphaPreintegrationHandle, GL_TEXTURE_2D); } else { shader.setUniformTexture(uniformColorAlphaHandle, colorAlphaFunctionHandle, GL_TEXTURE_1D); } if(useGradientAlphaMultiplier || useFresnelAlphaMultiplier || useReflectionColorMultiplier || useEmissionColorMultiplier) { if(usePreintegration) { shader.setUniformTexture(uniformAdvancedPreintegrationHandle, advancedPreintegrationHandle, GL_TEXTURE_2D); } else { shader.setUniformTexture(uniformAdvancedHandle, advancedFunctionHandle, GL_TEXTURE_1D); } } if(useReflectionColorMultiplier) { shader.setUniformTexture(uniformReflectionHandle, reflectionHandle, GL_TEXTURE_2D); } if(useLocalIllumination) { if(usePreintegration) { shader.setUniformTexture(uniformAmbientSpecularPreintegrationHandle, ambientSpecularPreintegrationHandle, GL_TEXTURE_2D); } else { shader.setUniformTexture(uniformAmbientSpecularHandle, ambientSpecularFunctionHandle, GL_TEXTURE_1D); } shader.setUniformValue(uniformSunDirectionHandle, sunDirection); shader.setUniformValue(uniformSunColorHandle, glm::vec4(sunColor, sunBrightness)); shader.setUniformValue(uniformAmbientColorHandle, ambientColor); } if(useJittering) { shader.setUniformTexture(uniformNoiseHandle, noiseHandle, GL_TEXTURE_2D); } if(useAdaptiveSampling) { shader.setUniformTexture(uniformImportanceVolumeHandle, importanceVolumeTextureHandle, GL_TEXTURE_3D); } if(useVoxelSpacedSampling) { shader.setUniformValue(uniformVolumeResolutionHandle, volumeResolution); } // Draw it shader.draw(GL_TRIANGLES); }