Dynamic render target size?

  • MajorPainTheCactus
  • Topic Author
More
1 year 11 months ago #1 by MajorPainTheCactus Dynamic render target size? was created by MajorPainTheCactus
Hi I've create an effect with a few passes in but one of the first passes requires a render target to be of a certain size based on the content being displayed.

Is there any way to dynamically resize this render target from values set in ImGui?

Please Log in or Create an account to join the conversation.

  • rj200
More
1 year 11 months ago #2 by rj200 Replied by rj200 on topic Dynamic render target size?
Texture buffer sizes have to be static at compile time. Options:

1. (fastest but not such a nice GUI) Use preprocessor definitions in your shader. It will appear underneath all the runtime ImGUI sliders in the GUI (user may have to click to expand "preprocessor definitions" section). It must have a name 10 or more characters or it won't appear. Simplified example from Glamayre:

#ifndef FAKE_GI_WIDTH
    #define FAKE_GI_WIDTH 384
#endif
#ifndef FAKE_GI_HEIGHT
    #define FAKE_GI_HEIGHT 216
#endif

texture GITexture {
    Width = FAKE_GI_WIDTH;
    Height = FAKE_GI_HEIGHT ;
    Format = RGBA16F;    
};

 2. Use biggest possible buffer size. Only read and write from a subset of it. If you use "discard" in your pixel shader it will still be reasonably fast - discard makes it exit early and write nothing. 

//first line of pixel shader
if(pos.x > maxwidth || pox.y > maxheight) discard;

3. Use biggest possible buffer size. Change the position of the triangle created by the vertex shader to only cover the top left corner of the texture. control size of that triangle using a ImGUI slider. Anything outside won't be rendered. I believe this will be faster than using discard.

uniform float fraction_to_draw < __UNIFORM_SLIDER_FLOAT1    
    ui_min = 0; ui_max = 1; ui_step = .01;    
    ui_label = "fraction_to_draw";
> = .5;

// Vertex shader generating a triangle covering the top left quarter of screen
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{    
        texcoord = fraction_to_draw;
        texcoord.x = (id == 2) ? -fraction_to_draw : fraction_to_draw;
        texcoord.y = (id == 1) ? -fraction_to_draw : fraction_to_draw;
        position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
    
}

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.