Comments (8)
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.
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.
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.
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.
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.
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.
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.
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)
- [rcore] Provide FLAG_WINDOW_UNFOCUSED functionality for SDL backend HOT 1
- [Examples] Example "models_loading.c" does not build HOT 10
- [core] Memory leak when running first window sample (Nvidia Drivers on Linux) HOT 2
- [misc] Statically linked raylib exposes functions from `src/external/*` HOT 11
- [WIP] [Examples] Update progress for v5.5 HOT 9
- [rcore] [desktop_GLFW] Window System Improvements HOT 10
- [docs] Documentation inconsistently uses Camera/Camera3D. HOT 2
- [rcore] Ability to rebind Capture/F12 hotkey HOT 1
- Request for a Evolve E2 85 Headset instead of the Evolve E2 65
- Truncating buffer in TextFormat might not work as intended HOT 2
- [rcore] Can't compile PLATFORM=PLATFORM_DRM GRAPHICS=GRAPHICS_API_OPENGL_21 HOT 2
- [build] ANGLE/OpenGL ES 2.0 using `build.zig` HOT 2
- [rtextures] Add different wrap modes for NPatches HOT 2
- [rcore] Configuration changes on Android are handled incorrectly HOT 4
- ImageDrawCircle distorting image when `centerX < radius` HOT 1
- [cmake] can't set config.h defines through cmake with CUSTOMIZE_BUILD=ON HOT 6
- [raudio] malloc_consolidate() error HOT 8
- [rcore] INPUT_MOUSE_WHEEL_MOTION events aren't replayed correctly HOT 1
- [rshapes] Specific Names for Color Arguments in DrawGradient Functions HOT 2
- [rcore] Tint Alpha not applied to texture when using BLEND_ALPHA_PREMULTIPLY HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raylib.