Dynamic render target size?

  • MajorPainTheCactus
  • MajorPainTheCactus's Avatar Topic Author
  • Offline
4 months 3 weeks 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.

4 months 2 weeks 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:

    #define FAKE_GI_WIDTH 384
    #define FAKE_GI_HEIGHT 216

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.