void FRenderState::Apply() { if (!gl_direct_state_change) { if (mSrcBlend != stSrcBlend || mDstBlend != stDstBlend) { stSrcBlend = mSrcBlend; stDstBlend = mDstBlend; glBlendFunc(mSrcBlend, mDstBlend); } if (mBlendEquation != stBlendEquation) { stBlendEquation = mBlendEquation; glBlendEquation(mBlendEquation); } } //ApplyColorMask(); I don't think this is needed. if (mVertexBuffer != mCurrentVertexBuffer) { if (mVertexBuffer == NULL) glBindBuffer(GL_ARRAY_BUFFER, 0); else mVertexBuffer->BindVBO(); mCurrentVertexBuffer = mVertexBuffer; } ApplyShader(); }
void BloomEffect::Impl::FilterBright( const sf::RenderTexture& input, sf::RenderTexture& output ) { sf::Shader& brightness = mShaders.Get( Shader::BrightnessPass ); brightness.setParameter( "source", input.getTexture() ); ApplyShader( brightness, output ); output.display(); }
void BloomEffect::Impl::Add( const sf::RenderTexture& source, const sf::RenderTexture& bloom, sf::RenderTarget& output ) { sf::Shader& adder = mShaders.Get( Shader::AddPass ); adder.setParameter( "source", source.getTexture() ); adder.setParameter( "bloom", bloom.getTexture() ); ApplyShader( adder, output ); }
void BloomEffect::Impl::Downsample( const sf::RenderTexture& input, sf::RenderTexture& output ) { sf::Shader& downSampler = mShaders.Get( Shader::DownSamplePass ); downSampler.setParameter( "source", input.getTexture() ); downSampler.setParameter( "sourceSize", sf::Vector2f( input.getSize() ) ); ApplyShader( downSampler, output ); output.display(); }
void BloomEffect::Impl::Blur( const sf::RenderTexture& input, sf::RenderTexture& output, sf::Vector2f offsetFactor ) { sf::Shader& gaussianBlur = mShaders.Get( Shader::GaussianBlurPass ); gaussianBlur.setParameter( "source", input.getTexture() ); gaussianBlur.setParameter( "offsetFactor", offsetFactor ); ApplyShader( gaussianBlur, output ); output.display(); }
void ButtonRender( struct Button * b ) { if( b->text != b->oldtext || !b->geotext ) { if( b->oldtext) free( b->oldtext ); if( b->geotext ) DestroyGPUGeometry( b->geotext ); b->geotext = EmitGeometryFromFontString( OldSansBlack, b->text, TEXTFLIPY ); b->oldtext = b->text; } // b->w = sin(TotalTime)*100+100; // b->h = cos(TotalTime)*100+100; ApplyShader( ButtonShader, OverallUniforms ); glColor4fv( b->color ); glBegin(GL_QUADS); glTexCoord4f(0.0, 0.0, b->w, b->h); glVertex3f(b->x, b->y, 0.0); glTexCoord4f(b->w, 0.0, b->w, b->h); glVertex3f(b->x+b->w, b->y, 0.0); glTexCoord4f(b->w, b->h, b->w, b->h ); glVertex3f(b->x+b->w, b->y+b->h, 0.0); glTexCoord4f(0.0, b->h, b->w, b->h ); glVertex3f(b->x, b->y+b->h, 0.0); glEnd(); CancelShader( ButtonShader ); if( b->color[0] + b->color[1] + b->color[2] > 1.5 ) glColor4f( 0, 0, 0, 1 ); else glColor4f( 1,1,1,1 ); if( b->geotext ) { float mx = b->geotext->maxs[0]-b->geotext->mins[0]; float my = b->geotext->maxs[1]-b->geotext->mins[1]; float scaleby = b->h / OldSansBlack->fontsize; glTranslatef( b->x+(b->w-mx*scaleby)/2, b->y+(b->h-(my+32)*scaleby)/2, 0 ); glScalef( scaleby, scaleby, 0.0 ); // ApplyShader( TextShader, OverallUniforms ); RenderGPUGeometry( b->geotext ); // CancelShader( TextShader ); } glColor4f( 1,1,1,1 ); }
int32 CGameObject::Initialize() { ApplyShader(); D3D11_BLEND_DESC blendDesc = {}; blendDesc.RenderTarget[0].BlendEnable = true; blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[0].RenderTargetWriteMask = 0x0F; float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; theDevice->CreateBlendState( &blendDesc, &m_alphaBlendState ); theContext->OMSetBlendState( m_alphaBlendState, blendFactor, 0xFFFFFFFF ); D3D11_SAMPLER_DESC samplerDesc = {}; samplerDesc.AddressU = samplerDesc.AddressV = samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; // samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC; // samplerDesc.MaxAnisotropy = 4; samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; HR( theDevice->CreateSamplerState( &samplerDesc, &m_pTextureSampler ) ); ID3D11Resource* pcolorTex = 00; m_material.GetDiffuse()->GetResource( &pcolorTex ); D3D11_TEXTURE2D_DESC colorTexDesc = {}; (reinterpret_cast<ID3D11Texture2D*>(pcolorTex))->GetDesc( &colorTexDesc ); pcolorTex->Release(); BuildBuffers(); D3D11_SAMPLER_DESC colorMapDesc = {}; colorMapDesc.AddressU = colorMapDesc.AddressV = colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; // colorMapDesc.Filter = D3D11_FILTER_ANISOTROPIC; // colorMapDesc.MaxAnisotropy = 4; colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX; HR( theDevice->CreateSamplerState( &colorMapDesc, &m_pTextureSampler ) ); m_pFXWorld = m_effect->GetVariableByName( "gWorld" )->AsMatrix(); m_pFXTexture = m_effect->GetVariableByName( "gTexture" )->AsShaderResource(); m_pFXTextureSampler = m_effect->GetVariableByName( "gTextureSampler" )->AsSampler(); return 0; }
void OpenGLPostProcessing::Update(u32 width, u32 height) { ApplyShader(); if (m_enable && (width != m_width || height != m_height)) { m_width = width; m_height = height; // alloc texture for framebuffer glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_2D, m_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } }
void Material::Render(Model* modelObj, Transform* transform, Matrix& projectionMatrix, Matrix& viewMatrix) { if(modelObj != NULL) { ApplyShader(); ApplyAttributes(modelObj); ApplyUniforms(transform, projectionMatrix, viewMatrix); ApplyTextures(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelObj->mElementBuffer); int size; glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); glDrawElements(GL_TRIANGLES, size/sizeof(GLushort), GL_UNSIGNED_SHORT, 0); DisableAttributes(); } }
void FRenderState::Apply(bool forcenoshader) { if (!gl_direct_state_change) { if (mSrcBlend != glSrcBlend || mDstBlend != glDstBlend) { glSrcBlend = mSrcBlend; glDstBlend = mDstBlend; glBlendFunc(mSrcBlend, mDstBlend); } if (mAlphaFunc != glAlphaFunc || mAlphaThreshold != glAlphaThreshold) { glAlphaFunc = mAlphaFunc; glAlphaThreshold = mAlphaThreshold; ::glAlphaFunc(mAlphaFunc, mAlphaThreshold); } if (mAlphaTest != glAlphaTest) { glAlphaTest = mAlphaTest; if (mAlphaTest) glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST); } if (mBlendEquation != glBlendEquation) { glBlendEquation = mBlendEquation; ::glBlendEquation(mBlendEquation); } } if (forcenoshader || !ApplyShader()) { GLRenderer->mShaderManager->SetActiveShader(NULL); if (mTextureMode != ffTextureMode) { gl_SetTextureMode((ffTextureMode = mTextureMode)); } if (mTextureEnabled != ffTextureEnabled) { if ((ffTextureEnabled = mTextureEnabled)) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); } if (mFogEnabled != ffFogEnabled) { if ((ffFogEnabled = mFogEnabled)) { glEnable(GL_FOG); } else glDisable(GL_FOG); } if (mFogEnabled) { if (ffFogColor != mFogColor) { ffFogColor = mFogColor; GLfloat FogColor[4]={mFogColor.r/255.0f,mFogColor.g/255.0f,mFogColor.b/255.0f,0.0f}; glFogfv(GL_FOG_COLOR, FogColor); } if (ffFogDensity != mFogDensity) { glFogf(GL_FOG_DENSITY, mFogDensity/64000.f); ffFogDensity=mFogDensity; } } if (mSpecialEffect != ffSpecialEffect) { switch (ffSpecialEffect) { case EFF_SPHEREMAP: glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_S); default: break; } switch (mSpecialEffect) { case EFF_SPHEREMAP: // Use sphere mapping for this glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); break; default: break; } ffSpecialEffect = mSpecialEffect; } } }
void OpenGLPostProcessing::BlitFromTexture(TargetRectangle src, TargetRectangle dst, int src_texture, int src_width, int src_height, int layer) { ApplyShader(); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glViewport(dst.left, dst.bottom, dst.GetWidth(), dst.GetHeight()); OpenGL_BindAttributelessVAO(); m_shader.Bind(); glUniform4f(m_uniform_resolution, (float)src_width, (float)src_height, 1.0f / (float)src_width, 1.0f / (float)src_height); glUniform4f(m_uniform_src_rect, src.left / (float) src_width, src.bottom / (float) src_height, src.GetWidth() / (float) src_width, src.GetHeight() / (float) src_height); glUniform1ui(m_uniform_time, (GLuint)m_timer.GetTimeElapsed()); glUniform1i(m_uniform_layer, layer); if (m_config.IsDirty()) { for (auto& it : m_config.GetOptions()) { if (it.second.m_dirty) { switch (it.second.m_type) { case PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_BOOL: glUniform1i(m_uniform_bindings[it.first], it.second.m_bool_value); break; case PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_INTEGER: switch (it.second.m_integer_values.size()) { case 1: glUniform1i(m_uniform_bindings[it.first], it.second.m_integer_values[0]); break; case 2: glUniform2i(m_uniform_bindings[it.first], it.second.m_integer_values[0], it.second.m_integer_values[1]); break; case 3: glUniform3i(m_uniform_bindings[it.first], it.second.m_integer_values[0], it.second.m_integer_values[1], it.second.m_integer_values[2]); break; case 4: glUniform4i(m_uniform_bindings[it.first], it.second.m_integer_values[0], it.second.m_integer_values[1], it.second.m_integer_values[2], it.second.m_integer_values[3]); break; } break; case PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_FLOAT: switch (it.second.m_float_values.size()) { case 1: glUniform1f(m_uniform_bindings[it.first], it.second.m_float_values[0]); break; case 2: glUniform2f(m_uniform_bindings[it.first], it.second.m_float_values[0], it.second.m_float_values[1]); break; case 3: glUniform3f(m_uniform_bindings[it.first], it.second.m_float_values[0], it.second.m_float_values[1], it.second.m_float_values[2]); break; case 4: glUniform4f(m_uniform_bindings[it.first], it.second.m_float_values[0], it.second.m_float_values[1], it.second.m_float_values[2], it.second.m_float_values[3]); break; } break; } it.second.m_dirty = false; } } m_config.SetDirty(false); } glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_2D_ARRAY, src_texture); g_sampler_cache->BindLinearSampler(9); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }