GeometryBuffers initializeGeometryBuffers(FrameGraph &frameGraph, int width, int height) { return frameGraph.addPass<GeometryBuffers>( ////////////////////////////////////////////////////// // SETUP [&](FrameGraph::PassBuilder &builder, GeometryBuffers &data) { data.depth = builder.createTexture2D(ImageFormat::D32_SFLOAT, width, height, "depth"); data.diffuse = builder.createTexture2D(ImageFormat::R8G8B8A8_UNORM, width, height, "diffuse"); data.normals = builder.createTexture2D(ImageFormat::R16G16_SFLOAT, width, height, "normals"); data.objectIDs = builder.createTexture2D(ImageFormat::R16G16_SINT, width, height, "objectIDs"); data.velocity = builder.createTexture2D(ImageFormat::R32G32_SFLOAT, width, height, "velocity"); builder.setName("InitGeometryBuffers"); }, ////////////////////////////////////////////////////// // EXECUTE [](GeometryBuffers &data, FrameGraph::PassResources &pass) { // Clear targets clearTexture(pass.getTexture(data.diffuse), vec4{0.0f, 0.0f, 0.0f, 1.0f}); clearTexture(pass.getTexture(data.normals), vec4{0.5f, 0.5f, 0.0f, 1.0f}); clearTexture(pass.getTexture(data.objectIDs), ivec4{0, 0, 0, 0}); clearDepthTexture(pass.getTexture(data.depth), 0.0f); clearTexture(pass.getTexture(data.velocity), vec4{0.0f, 0.0f, 0.0f, 1.0f}); }); }
bool ATOM_DOFEffect::createRT(ATOM_RenderDevice *device) { #if 0 ATOM_PostEffect *prevEffect = getPreviousEffect (); ATOM_Texture *inputTexture = prevEffect ? prevEffect->getRenderTarget() : _chain->getInputTexture(); #else ATOM_AUTOREF(ATOM_Texture) inputTexture = getSourceInputTex(); #endif if (!inputTexture) { return false; } _source = inputTexture; // 如果RT未创建,或者RT的大小和当前屏幕大小不一致 重建RT if( !_dofBlurMaskTex || !_blurTexs[0] || !_blurTexs[1] || !_blurTexs[2] || _rtWidth != inputTexture->getWidth() || _rtHeight != inputTexture->getHeight() ) { _rtWidth = inputTexture->getWidth(); _rtHeight = inputTexture->getHeight(); // wangjian modified : 使用ATOM_PostEffectRTMgr创建全局的RenderTarget #if 0 _dofBlurMaskTex = device->allocTexture (0, 0, _rtWidth, _rtHeight, ATOM_PIXEL_FORMAT_RGBA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); if( !_dofBlurMaskTex ) return false; clearTexture (_dofBlurMaskTex.get()); for( int i = 0; i < 3; ++i ) { _blurTexs[i] = device->allocTexture (0, 0, _rtWidth/8, _rtHeight/8, ATOM_PIXEL_FORMAT_RGBA16F, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); if( !_blurTexs[i] ) return false; clearTexture (_blurTexs[i].get()); } #else #if !USE_OPTIMIZATION _dofBlurMaskTex = ATOM_PostEffectRTMgr::getRT( _rtWidth, _rtHeight, ATOM_PIXEL_FORMAT_RGBA8888, 0 ); if( !_dofBlurMaskTex ) return false; clearTexture (_dofBlurMaskTex.get()); #endif for( int i = 0; i < 3; ++i ) { _blurTexs[i] = ATOM_PostEffectRTMgr::getRT( _rtWidth/8, _rtHeight/8, ATOM_PIXEL_FORMAT_RGBA32F, i ); if( !_blurTexs[i] ) return false; clearTexture (_blurTexs[i].get()); } #endif } return true; }
/* TextureEditorPanel::openTexture * Loads a TEXTUREX format texture into the editor *******************************************************************/ bool TextureEditorPanel::openTexture(CTexture* tex, TextureXList* list) { // Check texture was given if (!tex) { clearTexture(); return false; } // Set as current texture if (!tex_current) tex_current = new CTexture(); tex_current->copyTexture(tex); tex_current->setList(list); // Open texture in canvas tex_canvas->openTexture(tex_current, tx_editor->getArchive()); // Set control values updateTextureControls(); populatePatchList(); updatePatchControls(); tex_modified = false; return true; }
/* CTextureCanvas::openTexture * Loads a composite texture to be displayed *******************************************************************/ bool CTextureCanvas::openTexture(CTexture* tex, Archive* parent) { // Clear the current texture clearTexture(); // Set texture texture = tex; this->parent = parent; // Init patches clearPatchTextures(); for (uint32_t a = 0; a < tex->nPatches(); a++) { // Create GL texture patch_textures.push_back(new GLTexture()); // Set selection selected_patches.push_back(false); } // Listen to it listenTo(tex); // Redraw Refresh(); return true; }
void Material::clearTexture(size_t index) { auto ptr = lock(); if ( ptr ) ptr->clearTexture(index); }
void Material::clearTexture() { auto ptr = lock(); if ( ptr ) ptr->clearTexture(); }
void Blur_init(){ blur=Blur_basic; sw=larger_pow2(screen->w); sh=larger_pow2(screen->h); GLint mx; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mx); consoleLog("Blur_init: required texture size is %dx%d\n", sw, sh); if(sw>mx || sh>mx){ consoleLog("Blur_init: too big texture, disabling blur\n"); blur=Blur_none; return; } consoleLog("Blur_init: allocating screen buffer\n"); glGenTextures(1, &tex_screen); glBindTexture(GL_TEXTURE_2D, tex_screen); #if GL_EXT_framebuffer_object if(use_hdr){ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, sw,sh, 0, GL_RGB, GL_HALF_FLOAT_ARB, NULL); }else{ #endif glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, sw,sh, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); #if GL_EXT_framebuffer_object } #endif glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(0.f, 0.f, 0.0f, 1.f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); clearTexture(sw, sh); #if GL_ARB_shader_objects #if GL_ARB_depth_texture if(cap_glsl){ consoleLog("Blur_init: allocating depth buffer\n"); glGenTextures(1, &tex_depth); glBindTexture(GL_TEXTURE_2D, tex_depth); int comp; GLint i; glGetIntegerv(GL_DEPTH_BITS, &i); switch(i){ case 16: comp=GL_DEPTH_COMPONENT16_ARB; break; case 24: comp=GL_DEPTH_COMPONENT24_ARB; break; case 32: comp=GL_DEPTH_COMPONENT32_ARB; break; default: comp=GL_DEPTH_COMPONENT; break; } comp=GL_DEPTH_COMPONENT; if(use_hdr) comp=GL_DEPTH_COMPONENT24_ARB; glTexImage2D(GL_TEXTURE_2D, 0, comp, sw,sh, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); } #endif #endif #if GL_ARB_shader_objects if(cap_glsl){ prg_blurSimple=create_program("res/shaders/blur1.vs", "res/shaders/blur1.fs"); if(prg_blurSimple) consoleLog("Blur_init: compiled program \"blur1\"\n"); else consoleLog("Blur_init: couldn't compile program \"blur1\"\n"); #if GL_ARB_depth_texture prg_blurDepth=create_program("res/shaders/blur2.vs", "res/shaders/blur2.fs"); if(prg_blurDepth) consoleLog("Blur_init: compiled program \"blur2\"\n"); else consoleLog("Blur_init: couldn't compile program \"blur2\"\n"); #endif }else{ #endif consoleLog("Blur_init: no programs to compile\n"); #if GL_ARB_shader_objects } #endif #if GL_ARB_shader_objects if(cap_glsl){ blur=Blur_glsl_simple; #if GL_ARB_depth_texture blur=Blur_glsl_depth; #endif } #endif }
void HDR_Pipeline::setSource (ATOM_RenderDevice *device, ATOM_Texture *hdrSource) { if (_source.get() == hdrSource && hdrSource->getWidth() == _lastSourceWidth && hdrSource->getHeight() == _lastSourceHeight) { return; } _source = hdrSource; _lastSourceWidth = hdrSource->getWidth(); _lastSourceHeight = hdrSource->getHeight(); _cropWidth = hdrSource->getWidth() - (hdrSource->getWidth() % 8); _cropHeight = hdrSource->getHeight() - (hdrSource->getHeight() % 8); //--- wangjian modified for FLOAT BUFFER test ---// _sourceScaled = device->allocTexture (0, 0, _cropWidth/4, _cropHeight/4, /*ATOM_PIXEL_FORMAT_BGRA8888*/ATOM_PIXEL_FORMAT_RGBA16F, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); _brightPass = device->allocTexture (0, 0, _cropWidth/4+2, _cropHeight/4+2, ATOM_PIXEL_FORMAT_BGRA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); _starSource = device->allocTexture (0, 0, _cropWidth/4+2, _cropHeight/4+2, ATOM_PIXEL_FORMAT_BGRA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); _bloomSource = device->allocTexture (0, 0, _cropWidth/8+2, _cropHeight/8+2, ATOM_PIXEL_FORMAT_BGRA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); _adaptedLumCurrent = device->allocTexture (0, 0, 1, 1, /*ATOM_PIXEL_FORMAT_GREY8*/ATOM_PIXEL_FORMAT_R16F, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); _adaptedLumLast = device->allocTexture (0, 0, 1, 1, /*ATOM_PIXEL_FORMAT_GREY8*/ATOM_PIXEL_FORMAT_R16F, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); for(int i = 0; i < NUM_TONEMAP_TEXTURES; ++i) { int iSampleLen = 1 << ( 2 * i ); _toneMapTextures[i] = device->allocTexture (0, 0, iSampleLen, iSampleLen, /*ATOM_PIXEL_FORMAT_GREY8*/ATOM_PIXEL_FORMAT_R16F, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); } for(int i = 1; i < NUM_BLOOM_TEXTURES; ++i) { _bloomTextures[i] = device->allocTexture (0, 0, _cropWidth/8+2, _cropHeight/8+2, ATOM_PIXEL_FORMAT_BGRA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); clearTexture( _bloomTextures[i].get() ); } _bloomTextures[0] = device->allocTexture (0, 0, _cropWidth/8, _cropHeight/8, ATOM_PIXEL_FORMAT_BGRA8888, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); for(int i = 0; i < NUM_STAR_TEXTURES; ++i) { _starTextures[i] = device->allocTexture (0, 0, _cropWidth/4, _cropHeight/4, ATOM_PIXEL_FORMAT_BGRA8888/*ATOM_PIXEL_FORMAT_RGBA16F*/, ATOM_Texture::TEXTURE2D|ATOM_Texture::RENDERTARGET); } clearTexture (_adaptedLumCurrent.get()); clearTexture (_adaptedLumLast.get()); clearTexture (_bloomSource.get()); clearTexture (_brightPass.get()); clearTexture (_starSource.get()); _hdrMaterial = ATOM_MaterialManager::createMaterialFromCore (device, "/materials/builtin/hdr.mat"); _hdrMaterial->getParameterTable()->setFloat( "g_fBloomScale", 1.0f ); _hdrMaterial->getParameterTable()->setFloat( "g_fStarScale", 0.5f ); #if DEBUG_HDR if( bsaveall ) { device->setRenderTarget (0, 0); _source->saveToFile ("/source.png"); } #endif }