float32 LandscapeEditorDrawSystem::GetHeightAtTexturePoint(Landscape::eTextureLevel level, const Vector2& point) { if (GetTextureRect(level).PointInside(point)) { return GetHeightAtPoint(TexturePointToHeightmapPoint(level, point)); } return 0.f; }
void Barrier::Animate() { currentFrame++; if (currentFrame > maxFrame) { currentFrame = 1; } if (tiled) // Barrier type 4 { // Manually repeat the texture; sf::Texture.setRepeated() will not work because it interferes with animation for (int i = 0; i < tiledSize.x; ++i) { for (int j = 0; j < tiledSize.y; ++j) { // get a pointer to the current tile's quad sf::Vertex* quad = &VerticeList[(j + i * tiledSize.y) * 4]; // define its 4 corners // We subtract GetHitBox().width and height in order for GetPosition() to return the top-left corner quad[0].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + i * 16, GetPosition().y - GetHitBox().height / 2 + j * 16); quad[1].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + (i + 1) * 16, GetPosition().y - GetHitBox().height / 2 + j * 16); quad[2].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + (i + 1) * 16, GetPosition().y - GetHitBox().height / 2 + (j + 1) * 16); quad[3].position = sf::Vector2f(GetPosition().x - GetHitBox().width / 2 + i * 16, GetPosition().y - GetHitBox().height / 2 + (j + 1) * 16); // define its 4 texture coordinates // With animated barriers the textures should be in a straight, horizontal line, so y values do not change // Frames are 1-indexed, but the textures are 0-indexed, hence the (currentFrame - 1) quad[0].texCoords = sf::Vector2f((currentFrame - 1) * 16, 0); quad[1].texCoords = sf::Vector2f((currentFrame) * 16, 0); quad[2].texCoords = sf::Vector2f((currentFrame) * 16, 16); quad[3].texCoords = sf::Vector2f((currentFrame - 1) * 16, 16); } } } else // Barrier type 2 { // Size of one frame sf::Vector2i frameSize(GetSprite().getTexture()->getSize().x / maxFrame, GetSprite().getTexture()->getSize().y); SetTextureRect(frameSize.x * (currentFrame - 1), 0, GetTextureRect().width, GetTextureRect().height); } collided = false; }
void Unit::Draw() { SDL_Rect rect = {0, 0, 76, 76 }; SDL_RendererFlip flip = SDL_FLIP_NONE; if (App->sceneMap->renderUnits) { if (selected) App->render->Blit(App->entityManager->unit_base, (int)round(position.x - 32), (int)round(position.y) - 32, true, NULL); GetTextureRect(rect, flip); int positionY = (int)round(position.y - 38); App->render->Blit(texture, (int)round(position.x - 38), positionY, true, &rect, flip); } //Should be independent from scene if (App->sceneMap->renderForces) DrawDebug(); }
bool ff::SpriteData::CopyTo(IGraphTexture *texture, PointInt pos) const { assertRetVal(_texture && texture, false); ff::RectInt rect = GetTextureRect(); D3D11_BOX box; box.left = rect.left; box.top = rect.top; box.right = rect.right; box.bottom = rect.bottom; box.front = 0; box.back = 1; texture->GetDevice()->GetContext()->CopySubresourceRegion( texture->GetTexture(), 0, pos.x, pos.y, 0, _texture->GetTexture(), 0, &box); return true; }
/* void HDRLight::_starSource_To_BloomSource() { D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; // Get the new render target surface PDIRECT3DSURFACE9 pSurfBloomSource; g_pTexBloomSource->GetSurfaceLevel( 0, &pSurfBloomSource ); // Get the rectangle describing the sampled portion of the source texture. // Decrease the rectangle to adjust for the single pixel black border. RECT rectSrc; _getTextureRect( g_pTexStarSource, &rectSrc ); InflateRect( &rectSrc, -1, -1 ); // Get the destination rectangle. // Decrease the rectangle to adjust for the single pixel black border. RECT rectDest; _getTextureRect( g_pTexBloomSource, &rectDest ); InflateRect( &rectDest, -1, -1 ); // Get the correct texture coordinates to apply to the rendered quad in order // to sample from the source rectangle and render into the destination rectangle CoordRect coords; _getTextureCoords( g_pTexStarSource, &rectSrc, g_pTexBloomSource, &rectDest, &coords ); // Get the sample offsets used within the pixel shader D3DSURFACE_DESC desc; g_pTexBrightPass->GetLevelDesc( 0, &desc ); GetSampleOffsets_DownScale2x2( desc.Width, desc.Height, avSampleOffsets ); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); // Create an exact 1/2 x 1/2 copy of the source texture g_HDREffect->SetTechnique( "DownScale2x2" ); g_pd3dDevice->SetRenderTarget( 0, pSurfBloomSource ); g_pd3dDevice->SetTexture( 0, g_pTexStarSource ); g_pd3dDevice->SetScissorRect( &rectDest ); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); UINT uiPassCount, uiPass; g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad _drawFullScreenQuad( coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); SAFE_RELEASE( pSurfBloomSource ); }*/ void HDRLight::_renderBloom() { UINT uiPassCount, uiPass; int i = 0; D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; FLOAT afSampleOffsets[MAX_SAMPLES]; D3DXVECTOR4 avSampleWeights[MAX_SAMPLES]; PDIRECT3DSURFACE9 pSurfScaledHDR; g_pTexSceneScaled->GetSurfaceLevel( 0, &pSurfScaledHDR ); PDIRECT3DSURFACE9 pSurfBloom; g_apTexBloom[0]->GetSurfaceLevel( 0, &pSurfBloom ); PDIRECT3DSURFACE9 pSurfHDR; g_pTexScene->GetSurfaceLevel( 0, &pSurfHDR ); PDIRECT3DSURFACE9 pSurfTempBloom; g_apTexBloom[1]->GetSurfaceLevel( 0, &pSurfTempBloom ); PDIRECT3DSURFACE9 pSurfBloomSource; g_apTexBloom[2]->GetSurfaceLevel( 0, &pSurfBloomSource ); // Clear the bloom texture g_pd3dDevice->ColorFill( pSurfBloom, NULL, D3DCOLOR_ARGB( 0, 0, 0, 0 ) ); RECT rectSrc; GetTextureRect( g_pTexBloomSource, &rectSrc ); InflateRect( &rectSrc, -1, -1 ); RECT rectDest; GetTextureRect( g_apTexBloom[2], &rectDest ); InflateRect( &rectDest, -1, -1 ); CoordRect coords; GetTextureCoords( g_pTexBloomSource, &rectSrc, g_apTexBloom[2], &rectDest, &coords ); D3DSURFACE_DESC desc; g_pTexBloomSource->GetLevelDesc( 0, &desc ); g_HDREffect->SetTechnique( "GaussBlur5x5" ); GetSampleOffsets_GaussBlur5x5( desc.Width, desc.Height, avSampleOffsets, avSampleWeights, 1.0f ); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) ); g_pd3dDevice->SetRenderTarget( 0, pSurfBloomSource ); g_pd3dDevice->SetTexture( 0, g_pTexBloomSource ); g_pd3dDevice->SetScissorRect( &rectDest ); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); g_apTexBloom[2]->GetLevelDesc( 0, &desc ); GetSampleOffsets_Bloom( desc.Width, afSampleOffsets, avSampleWeights, 3.0f, 2.0f ); for( i = 0; i < MAX_SAMPLES; i++ ) { avSampleOffsets[i] = D3DXVECTOR2( afSampleOffsets[i], 0.0f ); } g_HDREffect->SetTechnique( "Bloom" ); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) ); g_pd3dDevice->SetRenderTarget( 0, pSurfTempBloom ); g_pd3dDevice->SetTexture( 0, g_apTexBloom[2] ); g_pd3dDevice->SetScissorRect( &rectDest ); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); g_apTexBloom[1]->GetLevelDesc( 0, &desc ); GetSampleOffsets_Bloom( desc.Height, afSampleOffsets, avSampleWeights, 3.0f, 2.0f ); for( i = 0; i < MAX_SAMPLES; i++ ) { avSampleOffsets[i] = D3DXVECTOR2( 0.0f, afSampleOffsets[i] ); } GetTextureRect( g_apTexBloom[1], &rectSrc ); InflateRect( &rectSrc, -1, -1 ); GetTextureCoords( g_apTexBloom[1], &rectSrc, g_apTexBloom[0], NULL, &coords ); g_HDREffect->SetTechnique( "Bloom" ); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) ); g_pd3dDevice->SetRenderTarget( 0, pSurfBloom ); g_pd3dDevice->SetTexture( 0, g_apTexBloom[1] ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); SAFE_RELEASE( pSurfBloomSource ); SAFE_RELEASE( pSurfTempBloom ); SAFE_RELEASE( pSurfBloom ); SAFE_RELEASE( pSurfHDR ); SAFE_RELEASE( pSurfScaledHDR ); }
void HDRLight::_brightSource_ToBloomSource() { D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; // Get the new render target surface PDIRECT3DSURFACE9 pSurfBloomSource; g_pTexBloomSource->GetSurfaceLevel( 0, &pSurfBloomSource ); // Get the rectangle describing the sampled portion of the source texture. // Decrease the rectangle to adjust for the single pixel black border. RECT rectSrc; GetTextureRect( g_pTexBrightPass, &rectSrc ); InflateRect( &rectSrc, -1, -1 ); // Get the destination rectangle. // Decrease the rectangle to adjust for the single pixel black border. RECT rectDest; GetTextureRect( g_pTexBloomSource, &rectDest ); InflateRect( &rectDest, -1, -1 ); // Get the correct texture coordinates to apply to the rendered quad in order // to sample from the source rectangle and render into the destination rectangle CoordRect coords; GetTextureCoords( g_pTexBrightPass, &rectSrc, g_pTexBloomSource, &rectDest, &coords ); // Get the sample offsets used within the pixel shader D3DSURFACE_DESC desc; g_pTexBrightPass->GetLevelDesc( 0, &desc ); GetSampleOffsets_DownScale2x2( desc.Width, desc.Height, avSampleOffsets ); g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) ); // Create an exact 1/2 x 1/2 copy of the source texture g_HDREffect->SetTechnique( "DownScale2x2" ); g_pd3dDevice->SetRenderTarget( 0, pSurfBloomSource ); g_pd3dDevice->SetTexture( 0, g_pTexBrightPass ); g_pd3dDevice->SetScissorRect( &rectDest ); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); UINT uiPassCount, uiPass; g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); SAFE_RELEASE( pSurfBloomSource ); }
void HDRLight::_sceneScaled_To_BrightPass() { D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; D3DXVECTOR4 avSampleWeights[MAX_SAMPLES]; // Get the new render target surface PDIRECT3DSURFACE9 pSurfBrightPass; g_pTexBrightPass->GetSurfaceLevel( 0, &pSurfBrightPass ); D3DSURFACE_DESC desc; g_pTexSceneScaled->GetLevelDesc( 0, &desc ); // Get the rectangle describing the sampled portion of the source texture. // Decrease the rectangle to adjust for the single pixel black border. RECT rectSrc; GetTextureRect( g_pTexSceneScaled, &rectSrc ); InflateRect( &rectSrc, -1, -1 ); // Get the destination rectangle. // Decrease the rectangle to adjust for the single pixel black border. RECT rectDest; GetTextureRect( g_pTexBrightPass, &rectDest ); InflateRect( &rectDest, -1, -1 ); // Get the correct texture coordinates to apply to the rendered quad in order // to sample from the source rectangle and render into the destination rectangle CoordRect coords; GetTextureCoords( g_pTexSceneScaled, &rectSrc, g_pTexBrightPass, &rectDest, &coords ); // The bright-pass filter removes everything from the scene except lights and // bright reflections g_HDREffect->SetTechnique( "BrightPassFilter" ); g_pd3dDevice->SetRenderTarget( 0, pSurfBrightPass ); g_pd3dDevice->SetTexture( 0, g_pTexSceneScaled ); g_pd3dDevice->SetTexture( 1, g_pTexAdaptedLuminanceCur ); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); g_pd3dDevice->SetScissorRect( &rectDest ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT ); g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); UINT uiPass, uiPassCount; g_HDREffect->Begin( &uiPassCount, 0 ); for( uiPass = 0; uiPass < uiPassCount; uiPass++ ) { g_HDREffect->BeginPass( uiPass ); // Draw a fullscreen quad to sample the RT DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV ); g_HDREffect->EndPass(); } g_HDREffect->End(); g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); SAFE_RELEASE( pSurfBrightPass ); }
void LandscapeEditorDrawSystem::ClampToTexture(Landscape::eTextureLevel level, Rect& rect) { GetTextureRect(level).ClampToRect(rect); }
Vector2 LandscapeEditorDrawSystem::LandscapePointToTexturePoint(Landscape::eTextureLevel level, const Vector2& point) { return TranslatePoint(point, GetLandscapeRect(), GetTextureRect(level)); }
Vector2 LandscapeEditorDrawSystem::TexturePointToHeightmapPoint(Landscape::eTextureLevel level, const Vector2& point) { return TranslatePoint(point, GetTextureRect(level), GetHeightmapRect()); }