Git Product home page Git Product logo

Comments (8)

veins1 avatar veins1 commented on June 29, 2024 1

I would be very glad if anti-aliasing on rendertextures were possible, I often use them to make videos by converting a rendertexture to an image and piping that to ffmpeg. It's a bit of a pity that the video isn't anti-aliased then.

A quick and easy way to get 4x SSAA is to make render texture 4x times bigger (2x on each axis) and then draw that texture to a regular size render texture ( don't forget to enable bilinear texture filtering on a big render texture). I assume additional overhead is not that important for an offline workflow that you have.

from raylib.

raysan5 avatar raysan5 commented on June 29, 2024 1

MSAA on RenderTextures is cumbersome to implement on OpenGL and it's not supported by raylib, it's not as easy as enabling a flag, like it is for main frmaebuffer.

About FXAA, it's just a shader and it can be used with RenderTextures BUT note that it is applied to all the RenderTexture buffer and not specific parts of the drawing, it could generate not expected results. Probably in many cases a small blur shader would give better results.

Drawing everything on a 4x RenderTexture is a good solution but it increases the render cost A LOT (not done by hardware like MSAA).

I'm closing this issue because it seems more a discussion about a topic than an issue with raylib library.

from raylib.

veins1 avatar veins1 commented on June 29, 2024

Here's an example: it's the core_3d_camera_free example modified to be DPI aware and rendered to a render texture. Looks no different compared to rendering directly to a back-buffer.

#include "raylib.h"

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    SetConfigFlags(FLAG_WINDOW_HIGHDPI);

    InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");

    // Define the camera to look into our 3d world
    Camera3D camera = { 0 };
    camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
    camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };      // Camera looking at point
    camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };          // Camera up vector (rotation towards target)
    camera.fovy = 45.0f;                                // Camera field-of-view Y
    camera.projection = CAMERA_PERSPECTIVE;             // Camera projection type

    Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };

    DisableCursor();                    // Limit cursor to relative movement inside the window

    SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    int width = GetRenderWidth();
    int height = GetRenderHeight();
    RenderTexture2D renderTexture = LoadRenderTexture(width, height);

    // Main game loop
    while (!WindowShouldClose())        // Detect window close button or ESC key
    {
        //Since our render texture is tied to our render resolution we need to reload it when window size changes
        //That can happen when changing the window size directly, when changing scaling factor of our current display or dragging the window to a display with a different scaling factor
        if (IsWindowResized()) {
            UnloadRenderTexture(renderTexture);
            int width = GetRenderWidth();
            int height = GetRenderHeight();
            renderTexture = LoadRenderTexture(width, height);
        }

        // Update
        //----------------------------------------------------------------------------------
        UpdateCamera(&camera, CAMERA_FREE);

        if (IsKeyPressed('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();
            
        BeginTextureMode(renderTexture);
            ClearBackground(RAYWHITE);

            BeginMode3D(camera);

                DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
                DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);

                DrawGrid(10, 1.0f);

            EndMode3D();

            DrawRectangle( 10, 10, 320, 93, Fade(SKYBLUE, 0.5f));
            DrawRectangleLines( 10, 10, 320, 93, BLUE);

            DrawText("Free camera default controls:", 20, 20, 10, BLACK);
            DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
            DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
            DrawText("- Z to zoom to (0, 0, 0)", 40, 80, 10, DARKGRAY);

        EndTextureMode();

        DrawTexturePro(renderTexture.texture, (Rectangle) { 0, 0, renderTexture.texture.width, -renderTexture.texture.height }, (Rectangle) { 0, 0, screenWidth, screenHeight }, (Vector2) {0.0, 0.0}, 0, WHITE);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

from raylib.

Lucrecious avatar Lucrecious commented on June 29, 2024

No, this wouldn't work. Even when the resolution is matched to the render width and height, the lines are still jagged, they don't seem to have any filter applied.

I'm not sure if #65 is still accurate today (almost 10 years later) in that RenderTexture still doesn't use MSAA for performance reasons. However, that FXAA shader that helps with antialiasing in that issue seems outdated as well somehow.

from raylib.

veins1 avatar veins1 commented on June 29, 2024

I'm trying to get RenderTexture to be DPI aware.

That's literally the first sentence in your message. I've provided an example on how to do it.

If your issue is aliasing - then dpi awareness has nothing to do with it. There's obviously going to be regular rasterization aliasing, but there's additional aliasing I see on your screenshot that (I guess) is caused by stretching that texture. My example doesn't have this issue.

So, let's be clear: this issue is about anti-aliasing for render textures? ( Either MSAA or FXAA)

from raylib.

Lucrecious avatar Lucrecious commented on June 29, 2024

Yes, I can see why that would be confusing, but I was mostly saying that to provide context. I think the rest of my issue makes it pretty clear though that I'm trying to get a smoother image using some type of anti-aliasing on the render texture.

from raylib.

th555 avatar th555 commented on June 29, 2024

I would be very glad if anti-aliasing on rendertextures were possible, I often use them to make videos by converting a rendertexture to an image and piping that to ffmpeg. It's a bit of a pity that the video isn't anti-aliased then.

from raylib.

th555 avatar th555 commented on June 29, 2024

A quick and easy way to get 4x SSAA is to make render texture 4x times bigger (2x on each axis) and then draw that texture to a regular size render texture ( don't forget to enable bilinear texture filtering on a big render texture). I assume additional overhead is not that important for an offline workflow that you have.

Yes, thanks, I was thinking of something like that, but now I found an even better (for this usecase at least) way: grab the actual (anti-aliased) framebuffer from the main window, similar to what TakeScreenshot does internally:

#include "rlgl.h"
unsigned char *imgData = rlReadScreenPixels(screenWidth, screenHeight);
Image img = { imgData, screenWidth, screenHeight, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };

(apologies for going a bit off-topic)

from raylib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.