Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to use new framebuffer apis #1616

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Oct 5, 2021

1. Create the targets

There are two types of targets:

1. Buffer target : render to a buffer

To create this target you need to specify a valid format

FrameBufferBufferTarget depthTarget= FrameBufferTarget.newTarget(Format.Depth);
FrameBufferBufferTarget colorTarget0= FrameBufferTarget.newTarget(Format.RGBA16F);
FrameBufferBufferTarget colorTarget1= FrameBufferTarget.newTarget(Format.RGB8);

2. Texture target : render to a texture

To create this target you need a valid texture, you might use an existing texture, or create a new one:

Texture2D myTexture = new Texture2D(512, 512, Format.RGBA8);

Note: we use this constructor to specify width,height and format, since those parameters are required by the renderer ( we cannot render on something of which we don't know sizes or format). You can also use the constructor that takes int numSamples, if you want to render on a multisample texture.

You can then create a target

FrameBufferTextureTarget colorTarget0= FrameBufferTarget.newTarget(myTexture);

Note: the type differs from the previous one ( FrameBufferTextureTarget vs FrameBufferBufferTarget) as you can guess, there are two overloaded newTarget methods one that takes Texture and outputs FrameBufferTextureTarget and one that takes Format and outputs FrameBufferBufferTarget .

2. Attach everything to the framebuffer

Once you have your targets, you can attach them to the framebuffer

Firstly we create the framebuffer

FrameBuffer fb = new FrameBuffer(512, 512, 1);

Note: if we are using texture targets, they must be of the same size of the framebuffer and have the same number of samples (>1 for multisample textures), in this case we have 512x512 textures without multisample (=1 sample), that's why we are passing those params.

Then we attach the targets

fb.setDepthTarget(depthTarget);
fb.addColorTarget(colorTarget);

We can have many color targets, just attach all of them with addColorTarget in the correct order.

3. Additional settings

  1. Enable multi render target
fb.setMultiTarget(true);

A MRT compatible shader will now be able to render on multiple color targets at the same time

  1. Render in srgb mode
myTexture.getImage().setColorSpace(ColorSpace.sRGB);
fb.setSrgb(true);

Everything that is rendered to this framebuffer will be converted from linear to sRGB space.

@stephengold
Copy link
Member

Thanks for the explanation of targets.

@stephengold stephengold added this to the v3.5.0 milestone Oct 24, 2021
@stephengold stephengold added the examples specific to the jme3-examples sub-project label Nov 12, 2021
@stephengold stephengold linked an issue Dec 2, 2021 that may be closed by this pull request
@stephengold
Copy link
Member

@riccardobl are you still available to work on this?

@stephengold stephengold modified the milestones: v3.5.0, Future Release Jan 23, 2022
@Ali-RS
Copy link
Member

Ali-RS commented Dec 31, 2022

What is the state of this PR?
I see there are some conflicts reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples specific to the jme3-examples sub-project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using deprecated FrameBuffer methods in jme3-examples
3 participants