void FireParticleSystem::Process(float delta_t) { UpdateParameters(delta_t); glUseProgram(m_animateProgram.program); CHECK_GL_ERRORS; setUniform(m_animateProgram.program, "delta_t", delta_t); setUniform(m_animateProgram.program, "wind", m_wind); //setUniform(m_animateProgram.program, "epicenter", float3(0,1,0)); glBindBuffer(GL_TEXTURE_BUFFER, m_posAndSizeBuffers[1-m_currPinPongId]); CHECK_GL_ERRORS; bindTextureBuffer(m_animateProgram.program, 1, "vertPosBuffer", m_vertexPosTBO); CHECK_GL_ERRORS; glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, m_vertexPosTBO); CHECK_GL_ERRORS; glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_posAndSizeBuffers[m_currPinPongId]); CHECK_GL_ERRORS; glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, m_velAndHPBuffers[m_currPinPongId]); CHECK_GL_ERRORS; glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 2, m_randBuffers[m_currPinPongId]); CHECK_GL_ERRORS; glEnable(GL_RASTERIZER_DISCARD); glBeginTransformFeedback(GL_POINTS); CHECK_GL_ERRORS; glBindVertexArray(m_animVAOs[1-m_currPinPongId]); CHECK_GL_ERRORS; glDrawArrays(GL_POINTS, 0, m_particlesNum); CHECK_GL_ERRORS; glBindVertexArray(0); glEndTransformFeedback(); CHECK_GL_ERRORS; glDisable(GL_RASTERIZER_DISCARD); glBindBuffer(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0); m_currPinPongId = 1 - m_currPinPongId; m_lastDeltaTime = delta_t; }
void water::sim_step() { GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); glViewport(0, 0, grid_size_x_, grid_size_z_); glDisable(GL_DEPTH_TEST); int temp = a_; a_ = b_; b_ = c_; c_ = temp; pos_tex_[c_]->BeginRenderingToThisTexture(); glUseProgram(sim_prog_.program); setUniform(sim_prog_.program, "gridSizeX", grid_size_x_); setUniform(sim_prog_.program, "gridSizeZ", grid_size_z_); bindTexture(sim_prog_.program, WATER_POSITIONS_PREV, "inPositionsPrev", pos_tex_[a_]->GetColorTexId()); bindTexture(sim_prog_.program, WATER_POSITIONS, "inPositions", pos_tex_[b_]->GetColorTexId()); full_screen_quad_->Draw(); pos_tex_[c_]->EndRenderingToThisTexture(); glEnable(GL_DEPTH_TEST); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); }
ReflectorShader::ReflectorShader() { Utility::Resource rs("data"); Shader vert(Version::GL330, Shader::Type::Vertex); vert.addSource(rs.get("ReflectorShader.vert")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); attachShader(vert); Shader frag(Version::GL330, Shader::Type::Fragment); frag.addSource(rs.get("ReflectorShader.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); attachShader(frag); CORRADE_INTERNAL_ASSERT_OUTPUT(link()); transformationMatrixUniform = uniformLocation("transformationMatrix"); normalMatrixUniform = uniformLocation("normalMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix"); cameraMatrixUniform = uniformLocation("cameraMatrix"); reflectivityUniform = uniformLocation("reflectivity"); diffuseColorUniform = uniformLocation("diffuseColor"); setUniform(uniformLocation("textureData"), TextureLayer); setUniform(uniformLocation("tarnishTextureData"), TarnishTextureLayer); }
void material::setup_shader(GLuint program) const { setUniform(program, "material.ambient", ambient_); setUniform(program, "material.diffuse", diffuse_); setUniform(program, "material.specular", specular_); float3 shininess; shininess.x = shininess_; setUniform(program, "material.shininess", shininess); }
void BasicShader::updateUniforms(const Matrix4f& projectedMatrix, const Material& material) { bind(); material.texture.bind(); setUniform("transform", projectedMatrix); setUniform("color", material.color); }
void NormalShader::updateUniforms() { setUniform(std::string("transform"), transform_); setUniform(std::string("perspective"), *perspective_); setUniform(std::string("camera"), *cameraTranslation_); setUniform(std::string("cameraRotation"), *cameraRotation_); setUniform(std::string("model_col"), eyePos_); }
int main() { circe::SceneApp<> app(800, 800, "", false); app.init(); app.addViewport(0, 0, 800, 800); ponos::RawMeshSPtr mesh(new ponos::RawMesh()); // circe::loadOBJ("/mnt/windows/Users/fuiri/Desktop/dragon.obj", &mesh); circe::loadOBJ( "/mnt/windows/Projects/ponos/circe/examples/assets/torusknot.obj", mesh.get()); mesh->apply(ponos::scale(0.1, 0.1, 0.1)); mesh->computeBBox(); mesh->splitIndexData(); mesh->buildInterleavedData(); auto texture = circe::ImageTexture::checkBoard(64, 64); ponos::RawMeshSPtr m( ponos::create_icosphere_mesh(ponos::Point3(), 1.f, 3, true, false)); // create a vertex buffer for base mesh // circe::SceneMesh sm(*m.get()); circe::SceneMesh smesh(mesh); auto s = circe::ShaderProgram( circe::ShaderManager::instance().loadFromTexts(vs, nullptr, fs)); s.addVertexAttribute("position", 0); s.addVertexAttribute("normal", 1); s.addVertexAttribute("texcoord", 2); s.addUniform("proj", 3); s.addUniform("model", 4); s.addUniform("tex", 5); // create a buffer for particles positions + sizes app.viewports[0].renderCallback = [&](const circe::CameraInterface *camera) { smesh.bind(); smesh.vertexBuffer()->locateAttributes(s); texture.bind(GL_TEXTURE0); s.begin(); s.setUniform("proj", ponos::transpose(camera->getProjectionTransform().matrix())); s.setUniform("model", ponos::transpose(camera->getViewTransform().matrix())); circe::CHECK_GL_ERRORS; s.setUniform("tex", 0); // s.setUniform("ldir", ponos::vec3(1,0,0)); circe::CHECK_GL_ERRORS; auto ib = smesh.indexBuffer(); glDrawElements(ib->bufferDescriptor.elementType, ib->bufferDescriptor.elementCount * ib->bufferDescriptor.elementSize, ib->bufferDescriptor.dataType, 0); circe::CHECK_GL_ERRORS; s.end(); }; circe::SceneObjectSPtr grid(new circe::CartesianGrid(5)); app.scene.add(grid.get()); app.run(); return 0; }
void UniformRegistry::performGlobalSync(const UniformRegistry & globalUniforms, bool forced){ if(forced){ // set all global uniforms for(auto it=globalUniforms.orderedList.begin(); it!=globalUniforms.orderedList.end() && (*it)->stepOfLastSet>stepOfLastGlobalSync; ++it ) setUniform( (*it)->uniform,false,true); }else { // set all uniforms of the globalUniforms-Set that have been changed since the last call. for(auto it=globalUniforms.orderedList.begin(); it!=globalUniforms.orderedList.end() && (*it)->stepOfLastSet>stepOfLastGlobalSync; ++it ) setUniform( (*it)->uniform,false,false); } stepOfLastGlobalSync = getNewGlobalStep(); }
ColorCorrectionShader::ColorCorrectionShader() { Corrade::Utility::Resource rs("shader"); attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, rs.get("ColorCorrectionShader.vert"))); attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, rs.get("ColorCorrectionShader.frag"))); link(); transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); setUniform(uniformLocation("textureData"), TextureLayer); setUniform(uniformLocation("colorCorrectionTextureData"), ColorCorrectionTextureLayer); }
void BasicShader::updateUniforms(const Matrix4f& worldMatrix, const Matrix4f& projectedMatrix, Material& material) { static Texture WHITE = Texture(1, 1, whitePixel); if (material.texture != NULL) material.texture->bind(); else WHITE.bind(); setUniform("transform", projectedMatrix); setUniform("color", material.color); }
//! Constructor COGLES2ParallaxMapRenderer::COGLES2ParallaxMapRenderer( video::COGLES2Driver* driver, io::IFileSystem* fs, s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial ) : COGLES2SLMaterialRenderer( driver, fs, 0, baseMaterial, sBuiltInShaderUniformNames, UNIFORM_COUNT ), CompiledShaders( true ) { #ifdef _DEBUG setDebugName( "COGLES2ParallaxMapRenderer" ); #endif // set this as callback. We could have done this in // the initialization list, but some compilers don't like it. CallBack = this; // basically, this simply compiles the hard coded shaders if the // hardware is able to do them, otherwise it maps to the base material // check if already compiled normal map shaders are there. video::IMaterialRenderer* renderer = driver->getMaterialRenderer( EMT_PARALLAX_MAP_SOLID ); if ( renderer ) { // use the already compiled shaders video::COGLES2ParallaxMapRenderer* pmr = reinterpret_cast<video::COGLES2ParallaxMapRenderer*>( renderer ); CompiledShaders = false; Program = pmr->Program; UniformInfo = pmr->UniformInfo; AttributeInfo = pmr->AttributeInfo; outMaterialTypeNr = driver->addMaterialRenderer( this ); } else { // compile shaders on our own if (initFromFiles( outMaterialTypeNr, VertexShaderFile, FragmentShaderFile)) { useProgram(); int dummy = 0; setUniform( TEXTURE_UNIT0, &dummy ); dummy = 1; setUniform( TEXTURE_UNIT1, &dummy ); } } // fallback if compilation has failed if ( -1 == outMaterialTypeNr ) outMaterialTypeNr = driver->addMaterialRenderer( this ); }
void pool::update(const float4x4& view_projection, const camera& camera, const point_light& light, GLuint caustics_tex_id, int num_wall) { glUseProgram(render_prog_.program); setUniform(render_prog_.program, "cameraPosition", camera.get_pos()); setUniform(render_prog_.program, "viewProjectionMatrix", view_projection); setUniform(render_prog_.program, "objectMatrix", object_matrix_[num_wall]); setUniform(render_prog_.program, "inversedObjectMatrix", inversed_object_matrix_[num_wall]); setUniform(render_prog_.program, "gridSizeX", 256); setUniform(render_prog_.program, "gridSizeZ", 256); setUniform(render_prog_.program, "sizeX", size_x_[num_wall]); setUniform(render_prog_.program, "sizeZ", size_z_[num_wall]); light.setup_shader(render_prog_.program); material_.setup_shader(render_prog_.program); bindTexture(render_prog_.program, CAUSTICS + num_wall, "caustics", caustics_tex_id); bindTexture(render_prog_.program, FLOOR_TILT, "floorTilt", floor_tex_->GetColorTexId()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); pool_mesh_->Draw(GL_TRIANGLES); glDisable(GL_BLEND); glDisable(GL_CULL_FACE); }
void ForwardPass::onPrep(const DirectionalLight &dLight) { glm::mat4 textureSpaceOffset( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f ); //lights setUniform("dLColor", nsfw::UNIFORM::FLO3, glm::value_ptr((dLight.color))); setUniform("dLDirection", nsfw::UNIFORM::FLO3, glm::value_ptr((dLight.direction))); setUniform("LightMatrix", nsfw::UNIFORM::MAT4, glm::value_ptr(textureSpaceOffset * dLight.getMatrix())); setUniform("dLCoefficient", nsfw::UNIFORM::FLO1, &dLight.dLCoefficient); }
void Lightmap::render(const Falltergeist::Point &pos) { if (_indexes<=0) return; GL_CHECK(glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR)); auto shader = ResourceManager::getInstance()->shader("lightmap"); GL_CHECK(shader->use()); GL_CHECK(shader->setUniform(_uniformMVP, Game::getInstance()->renderer()->getMVP())); // set camera offset GL_CHECK(shader->setUniform(_uniformOffset, glm::vec2((float)pos.x(), (float)pos.y()) )); GL_CHECK(shader->setUniform(_uniformFade,Game::getInstance()->renderer()->fadeColor())); GL_CHECK(glBindVertexArray(_vao)); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _coords)); GL_CHECK(glVertexAttribPointer(_attribPos, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 )); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _lights)); GL_CHECK(glVertexAttribPointer(_attribLights, 1, GL_FLOAT, GL_FALSE, 0, (void*)0 )); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo)); GL_CHECK(glEnableVertexAttribArray(_attribPos)); GL_CHECK(glEnableVertexAttribArray(_attribLights)); GL_CHECK(glDrawElements(GL_TRIANGLES, _indexes, GL_UNSIGNED_INT, 0 )); GL_CHECK(glDisableVertexAttribArray(_attribPos)); GL_CHECK(glDisableVertexAttribArray(_attribLights)); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0)); GL_CHECK(glBindVertexArray(0)); GL_CHECK(shader->unuse()); GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); }
void DynamicPartialLoudnessGM::loadParameterSet(ParameterSet set) { //common to all setTimeStep(0.001); setHpf(true); setDiffuseField(false); setGoertzel(false); setDiotic(true); setUniform(true); setInterpRoexBank(false); setFilterSpacing(0.25); setCompressionCriterion(0.0); setFastBank(false); setStereoToMono(true); switch(set){ case GM02: break; case FASTER1: setFastBank(true); setInterpRoexBank(true); setCompressionCriterion(0.3); break; default: setFastBank(true); setCompressionCriterion(0.3); } }
void Element::setColor(const glm::vec4 color) noexcept { this->color = color; auto uniform = Uniform(); uniform.setData("color", color); setUniform(uniform); }
template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): transformationProjectionMatrixUniform(0), colorUniform(1), _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 & Flag::Textured ? "#define TEXTURED\n" : "") .addSource(rs.get("generic.glsl")) .addSource(rs.get(vertexShaderName<dimensions>())); frag.addSource(flags & Flag::Textured ? "#define TEXTURED\n" : "") .addSource(rs.get("Flat.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"); if(flags & Flag::Textured) 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 { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); colorUniform = uniformLocation("color"); } #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported<Extensions::GL::ARB::shading_language_420pack>(version)) #endif { if(flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureLayer); } /* 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 texture */ if(flags & Flag::Textured) setColor(Color4(1.0f)); #endif }
bool VolumeRenderer::bindVolumes(tgt::Shader* shader, const std::vector<VolumeStruct>& volumes, const tgt::Camera* camera, const tgt::vec4& lightPosition) { shader->setIgnoreUniformLocationError(true); bool success = true; for (size_t i=0; i < volumes.size(); ++i) { const VolumeStruct& volumeStruct = volumes[i]; const VolumeGL* volumeGL = volumeStruct.volume_->getRepresentation<VolumeGL>(); if (!volumeGL || !volumeGL->getTexture()) { LWARNING("No volume texture while binding volumes"); continue; } const TextureUnit* texUnit = volumeStruct.texUnit_; if (!texUnit) { LERROR("No texture unit while binding volumes"); continue; } success &= bindVolumeTexture(volumeStruct.volume_, texUnit, volumeStruct.filterMode_, volumeStruct.wrapMode_, volumeStruct.borderColor_); // set volume meta-data setUniform(shader, volumeStruct.volumeIdentifier_, volumeStruct.volumeStructIdentifier_, volumeStruct.volume_, texUnit, camera, lightPosition); LGL_ERROR; } shader->setIgnoreUniformLocationError(false); LGL_ERROR; return success; }
void reShader::setTexture( int name, GLuint texture, int index ) { setUniform(name, varTable[name]->index, index); glActiveTexture(GL_TEXTURE0+varTable[name]->index); glBindTexture(GL_TEXTURE_2D, texture); glEnable(GL_TEXTURE_2D); }
void Slider::update() { int newMouseX, newMouseY; glfwGetMousePos( &newMouseX, &newMouseY ); float relativeMouseX = convertXToRelative( newMouseX ); float relativeMouseY = convertYToRelative( newMouseY ); // Check if mouse press is on button if( !glfwGetMouseButton(0) ) { buttonPressed = false; } else if( ( relativeMouseX - buttonPosition.X ) * ( relativeMouseX - buttonPosition.X ) + (relativeMouseY - buttonPosition.Y ) * ( relativeMouseY - buttonPosition.Y ) < slider_consts::buttonSize * slider_consts::buttonSize || buttonPressed ){ buttonPressed = true; buttonPosition.X = relativeMouseX; float minPos = sliderPosition.X - slider_consts::sliderLength / 2; float maxPos = sliderPosition.X + slider_consts::sliderLength / 2; if( buttonPosition.X < minPos ) buttonPosition.X = minPos; if( buttonPosition.X > maxPos ) buttonPosition.X = maxPos; currentPercentage = ( buttonPosition.X - minPos ) / ( maxPos - minPos ); setUniform( shaderProperty, min + currentPercentage * (max - min) ); } }
void BasicShader::UpdateUniforms(const Transform& transform, const Material& material, RenderingEngine* renderingEngine) { static Texture WHITE = Texture(1, 1, whitePixel); if (material.texture != NULL) material.texture->bind(); else WHITE.bind(); glm::mat4 worldMatrix = transform.getTransform(); glm::mat4 projectedMatrix = renderingEngine->GetMainCamera().GetViewProjection() * worldMatrix; setUniform("transform", projectedMatrix); setUniform("color", material.color); setUniformi("time", (int)SDL_GetTicks()); }
unsigned int shader::addUniform( char t, const char* name, void* value) { GLuint id = glGetUniformLocationARB(shaderobj, name); if((int)id < 0) return id; uniformId.push_back(id); type.push_back(t); this->value.push_back(value); stu.insert( make_pair<const char*, unsigned int>( name, uniformIdx ) ); if(t=='t') textures.insert( make_pair<GLuint, GLuint>( id, n_tex ) ); setUniform(uniformIdx, value); n_tex++; uniformIdx++; return uniformIdx-1; }
void ForwardAmbientLightShader::draw(const RenderComponent& renderComponent) { if (!renderComponent.material.hasDiffuse()) { return; } setMaterial(renderComponent.material); setUniform("modelToWorldMatrix", renderComponent.getTransformationMatrix()); renderComponent.mesh->draw(); }
void SkyBox::UpdateUniforms(const Transform& transform, const Material& material, RenderingEngine* renderingEngine) { static Texture WHITE = Texture(1, 1, whitePixel); if (material.texture != NULL) material.texture->bind(); else WHITE.bind(); glm::mat4 worldMatrix = transform.getTransform(); glm::mat4 projectedMatrix = renderingEngine->GetMainCamera().GetViewProjection() * worldMatrix; setUniform("view", renderingEngine->GetMainCamera().GetViewProjection()); setUniform("projection", transform.getTransform()); setUniform("cameraPos", renderingEngine->GetMainCamera().getPosition()); }
bool ShaderProgram::setUniform(const std::string &name, const Vector4i &value) { GLint l = getUniformLocation(name); if (l == -1) return false; setUniform(l, value); return true; }
bool ShaderProgram::setUniform(const std::string &name, bool value) { GLint l = getUniformLocation(name); if (l == -1) return false; setUniform(l, static_cast<GLint>(value)); return true; }
void PagShaderProgram::setColor(GLfloat c1, GLfloat c2, GLfloat c3){ vcolor[0] = c1; vcolor[1] = c2; vcolor[2] = c3; setUniform("vColor", vcolor[0], vcolor[1], vcolor[2]); }
bool ShaderProgram::setUniform(const std::string &name, bool v1, bool v2, bool v3, bool v4) { GLint l = getUniformLocation(name); if (l == -1) return false; setUniform(l, static_cast<GLint>(v1), static_cast<GLint>(v2), static_cast<GLint>(v3), static_cast<GLint>(v4)); return true; }
//-------------------------------------------------------------------------------------------------- /// Set all uniforms contained in \a sourceUniformSet //-------------------------------------------------------------------------------------------------- void Effect::setUniformsFromUniformSet(UniformSet* sourceUniformSet) { size_t uniformCount = sourceUniformSet->count(); for (size_t i = 0; i < uniformCount; i++) { setUniform(sourceUniformSet->uniform(i)); } }
bool ShaderProgram::setUniform(const std::string &name, const Matrix4f &value, bool transpose) { GLint l = getUniformLocation(name); if (l == -1) return false; setUniform(l, value, transpose); return true; }