/** * Zeichnet die Textur. */ void glArchivItem_Bitmap::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/) { if(GetTexture() == 0) return; RTTR_Assert(dstArea.getSize().x > 0 && dstArea.getSize().y > 0); RTTR_Assert(srcArea.getSize().x > 0 && srcArea.getSize().y > 0); // Compatibility only! Extent srcSize = srcArea.getSize(); if(srcSize.x == 0) srcSize.x = getWidth(); if(srcSize.y == 0) srcSize.y = getHeight(); srcArea.setSize(srcSize); Extent dstSize = dstArea.getSize(); if(dstSize.x == 0) dstSize.x = srcSize.x; if(dstSize.y == 0) dstSize.y = srcSize.y; dstArea.setSize(dstSize); RTTR_Assert(getBobType() != libsiedler2::BOBTYPE_BITMAP_PLAYER); std::array<Point<GLfloat>, 4> texCoords, vertices; dstArea.move(-GetOrigin()); vertices[0].x = vertices[1].x = GLfloat(dstArea.left); vertices[2].x = vertices[3].x = GLfloat(dstArea.right); vertices[0].y = vertices[3].y = GLfloat(dstArea.top); vertices[1].y = vertices[2].y = GLfloat(dstArea.bottom); Point<GLfloat> srcOrig = Point<GLfloat>(srcArea.getOrigin()) / GetTexSize(); Point<GLfloat> srcEndPt = Point<GLfloat>(srcArea.getEndPt()) / GetTexSize(); texCoords[0].x = texCoords[1].x = srcOrig.x; texCoords[2].x = texCoords[3].x = srcEndPt.x; texCoords[0].y = texCoords[3].y = srcOrig.y; texCoords[1].y = texCoords[2].y = srcEndPt.y; glVertexPointer(2, GL_FLOAT, 0, vertices.data()); glTexCoordPointer(2, GL_FLOAT, 0, texCoords.data()); VIDEODRIVER.BindTexture(GetTexture()); glColor4ub(GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color)); glDrawArrays(GL_QUADS, 0, 4); }
void glArchivItem_Bitmap::FillTexture() { int iformat = GetInternalFormat(), dformat = GL_BGRA; const Extent texSize = GetTexSize(); libsiedler2::PixelBufferARGB buffer(texSize.x, texSize.y); print(buffer); glTexImage2D(GL_TEXTURE_2D, 0, iformat, texSize.x, texSize.y, 0, dformat, GL_UNSIGNED_BYTE, buffer.getPixelPtr()); }
void BilateralBlur( const Ptr<ShaderResourceView> & src, const Ptr<RenderTargetView> & dst, const Ptr<ShaderResourceView> & depthTex, const std::vector<float> & weights, float depthDiffThreshold) { auto srcTex = src->GetResource()->Cast<Texture>(); auto tmpTexDesc = dst->GetResource()->Cast<Texture>()->GetDesc(); auto tmpTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, tmpTexDesc }); { auto ps = Shader::FindOrCreate<BilateralBlurXPS>(); ps->SetScalar("bilateralBlurWeights", &weights[0], (int32_t)(sizeof(float) * weights.size())); ps->SetScalar("texSize", srcTex->GetTexSize()); ps->SetScalar("depthDiffThreshold", depthDiffThreshold); ps->SetSRV("bilateralDepthTex", depthTex); ps->SetSRV("bilateralBlurInTex", src); ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->Flush(); DrawQuad({ tmpTexRef->Get()->Cast<Texture>()->GetRenderTargetView(0, 0, 1) }); } { auto ps = Shader::FindOrCreate<BilateralBlurYPS>(); ps->SetScalar("bilateralBlurWeights", &weights[0], (int32_t)(sizeof(float) * weights.size())); ps->SetScalar("texSize", srcTex->GetTexSize()); ps->SetScalar("depthDiffThreshold", depthDiffThreshold); ps->SetSRV("bilateralDepthTex", depthTex); ps->SetSRV("bilateralBlurInTex", tmpTexRef->Get()->Cast<Texture>()->GetShaderResourceView()); ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->Flush(); DrawQuad({ dst }); } }
void BilateralUpSampling( const Ptr<ShaderResourceView> & src, const Ptr<RenderTargetView> & dst, const Ptr<ShaderResourceView> & lowResDepthTex, const Ptr<ShaderResourceView> & highResDepthTex, float depthDiffThreshold) { auto srcTex = src->GetResource()->Cast<Texture>(); auto ps = Shader::FindOrCreate<BilateralUpSamplingPS>(); ps->SetScalar("texSize", srcTex->GetTexSize()); ps->SetScalar("depthDiffThreshold", depthDiffThreshold); ps->SetSRV("lowResDepthTex", lowResDepthTex); ps->SetSRV("highResDepthTex", highResDepthTex); ps->SetSRV("upSamplingInTex", src); ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->Flush(); DrawQuad({ dst }); }
int Read3dfHeader( const char *filename, Gu3dfInfo *data ) { FILE * file3df; char buffer[255]; int temp1, temp2, lod1, lod2, nWidth, nHeight; file3df = fopen( filename, "rb" ); if ( file3df == NULL ) { return 0; } fgets( buffer, 255, file3df ); fgets( buffer, 255, file3df ); data->header.format = ParseTextureFormat( buffer ); fgets( buffer, 255, file3df ); sscanf( buffer, "lod range: %d %d\n", &lod1, &lod2 ); data->header.small_lod = ParseLod( lod1 ); data->header.large_lod = ParseLod( lod2 ); fgets( buffer, 255, file3df ); sscanf( buffer, "aspect ratio: %d %d\n", &temp1, &temp2 ); data->header.aspect_ratio = ParseAspect( temp1, temp2 ); switch ( data->header.aspect_ratio ) { case GR_ASPECT_8x1: nWidth = lod2; nHeight = lod2 >> 3; break; case GR_ASPECT_4x1: nWidth = lod2; nHeight = lod2 >> 2; break; case GR_ASPECT_2x1: nWidth = lod2; nHeight = lod2 >> 1; break; case GR_ASPECT_1x1: nWidth = lod2; nHeight = lod2; break; case GR_ASPECT_1x2: nWidth = lod2 >> 1; nHeight = lod2; break; case GR_ASPECT_1x4: nWidth = lod2 >> 2; nHeight = lod2; break; case GR_ASPECT_1x8: nWidth = lod2 >> 3; nHeight = lod2; break; } data->header.width = nWidth; data->header.height = nHeight; { GrLOD_t l; data->mem_required = 0; for ( l = data->header.large_lod; l <= data->header.small_lod; l++ ) data->mem_required += GetTexSize( l, data->header.aspect_ratio, data->header.format ); } temp1 = ftell( file3df ); fclose( file3df ); return temp1; }
void SSR::Render(const Ptr<RenderView> & view) { auto sceneTex = view->GetViewRenderContext()->GetSharedTexture("RenderResult"); auto sceneClipDepth = view->GetViewRenderContext()->GetSharedTexture("SceneClipDepth"); auto gbuffer0 = view->GetViewRenderContext()->GetSharedTexture("GBuffer0"); auto gbuffer1 = view->GetViewRenderContext()->GetSharedTexture("GBuffer1"); TextureDesc ssrDesc = sceneTex->GetDesc(); ssrDesc.format = RENDER_FORMAT_R16G16B16A16_FLOAT; auto ssrResultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, ssrDesc }); auto ssrResult = ssrResultTexRef->Get()->Cast<Texture>(); auto tmpDepthTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, sceneClipDepth->GetDesc() }); auto tmpDepthTex = tmpDepthTexRef->Get()->Cast<Texture>(); sceneClipDepth->CopyTo(tmpDepthTex, 0, 0, 0, 0, 0, 0, 0); auto ps = Shader::FindOrCreate<ScreenSpaceReflectionPS>(); view->BindShaderParams(ps); ps->SetScalar("frameCount", Global::GetInfo()->frameCount); ps->SetScalar("ssrMaxRoughness", _ssrMaxRoughness); ps->SetScalar("ssrIntensity", _ssrIntensity); ps->SetSRV("sceneTex", sceneTex->GetShaderResourceView()); ps->SetSRV("depthTex", tmpDepthTex->GetShaderResourceView(0, 0, 0, 0, false, RENDER_FORMAT_R24_UNORM_X8_TYPELESS)); ps->SetSRV("gbuffer0", gbuffer0->GetShaderResourceView()); ps->SetSRV("gbuffer1", gbuffer1->GetShaderResourceView()); ps->SetSampler("pointClampSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->SetSampler("linearSampler", SamplerTemplate<>::Get()); ps->Flush(); auto rc = Global::GetRenderEngine()->GetRenderContext(); rc->SetDepthStencilState( DepthStencilStateTemplate< false, DEPTH_WRITE_ZERO, COMPARISON_LESS, true, 0xff, 0xff, STENCIL_OP_KEEP, STENCIL_OP_KEEP, STENCIL_OP_KEEP, COMPARISON_NOT_EQUAL>::Get(), 0); DrawQuad( { ssrResult->GetRenderTargetView(0, 0, 1) }, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); auto ssrSharedRef = SSRNeighborShare(view, ssrResult, gbuffer1, tmpDepthTex, sceneClipDepth); auto ssrShared = ssrSharedRef->Get()->Cast<Texture>(); // Temporal AA for SSR auto ssrAAedResultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, sceneTex->GetDesc() }); auto ssrAAedResultTex = ssrAAedResultTexRef->Get()->Cast<Texture>(); { auto adaptedExposureScale = view->GetViewRenderContext()->GetSharedTexture("AdaptedExposureScale"); float2 offsets[5] = { float2(0.0f, 0.0f), float2(-1.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, -1.0f), float2(0.0f, 1.0f), }; float filterWeights[5]; float weightsSum = 0.0f; for (int i = 0; i < 5; ++i) { float2 offset = offsets[i] - float2(0.5f, -0.5f) * view->temporalAAJitter; //filterWeights[i] = CatmullRom(offset.x()) * CatmullRom(offset.y()); offset.x() *= 1.0f + 0.0f * 0.5f; offset.y() *= 1.0f + 0.0f * 0.5f; filterWeights[i] = exp(-2.29f * (offset.x() * offset.x() + offset.y() * offset.y())); weightsSum += filterWeights[i]; } for (auto & i : filterWeights) i /= weightsSum; std::map<String, String> macros; macros["TAA_DYNAMIC"] = "0"; macros["TAA_HISTORY_BICUBIC"] = "0"; auto ps = Shader::FindOrCreate<TemporalAAPS>(macros); view->BindShaderParams(ps); ps->SetScalar("texSize", ssrResult->GetTexSize()); ps->SetScalar("neighborFilterWeights", filterWeights, (int)sizeof(float) * 5); ps->SetScalar("frameCount", (uint32_t)Global::GetInfo()->frameCount); ps->SetScalar("lerpFactor", 0.125f); //ps->SetSRV("linearDepth", sceneLinearClipDepth->GetShaderResourceView()); ps->SetSRV("sceneDepth", sceneClipDepth->GetShaderResourceView(0, 0, 0, 0, false, RENDER_FORMAT_R24_UNORM_X8_TYPELESS)); ps->SetSRV("sceneTex", ssrShared->GetShaderResourceView()); //ps->SetSRV("velocityTex", velocityTex->GetShaderResourceView()); //ps->SetSRV("adaptedExposureScale", adaptedExposureScale->GetShaderResourceView()); if (_preSSRResultRef) ps->SetSRV("historyTex", _preSSRResultRef->Get()->Cast<Texture>()->GetShaderResourceView()); else ps->SetSRV("historyTex", nullptr); ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->SetSampler("linearSampler", SamplerTemplate<>::Get()); ps->Flush(); DrawQuad( { ssrAAedResultTex->GetRenderTargetView(0, 0, 1) }, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); _preSSRResultRef = ssrResultTexRef; } /*rc->SetBlendState( BlendStateTemplate<false, false, true, BLEND_PARAM_ONE, BLEND_PARAM_ONE, BLEND_OP_ADD>::Get()); rc->SetDepthStencil(sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); Transform( ssrAAedResultTex->GetShaderResourceView(), sceneTex->GetRenderTargetView(0, 0, 1), { COLOR_WRITE_R, COLOR_WRITE_G ,COLOR_WRITE_B ,COLOR_WRITE_A }, 0.0f, 0.0f, nullptr, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT));*/ rc->SetBlendState(nullptr); rc->SetDepthStencilState(nullptr); view->GetViewRenderContext()->SetSharedResource("SSR", ssrAAedResultTexRef); }