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

Render to Texture #186

Merged
merged 39 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
67f8089
Init render to texture support
erikhaandrikman Feb 1, 2024
4e4f480
Merge branch 'main' into feature/rtt
erikhaandrikman Feb 2, 2024
c5afe74
Update rtt handling
erikhaandrikman Feb 5, 2024
96282b7
Implement RenderTexture as core supported texture type
erikhaandrikman Feb 14, 2024
7c0b979
Render rtt nodes before normal quads
erikhaandrikman Feb 14, 2024
ca6d7ce
Update RTT examples
erikhaandrikman Feb 21, 2024
e55889e
Update rtt rendering on children update
erikhaandrikman Feb 21, 2024
7c71f15
Prevent RTT Text from being rendered outside texture
erikhaandrikman Feb 23, 2024
a2c3d27
Merge branch 'main' into feature/rtt
erikhaandrikman Feb 23, 2024
555df77
Always render children on render texture updates
erikhaandrikman Feb 25, 2024
53740f8
Add render texture copy support
erikhaandrikman Feb 26, 2024
c403c6e
Update RTT example
erikhaandrikman Feb 26, 2024
b5e59e3
Update RTT examples
erikhaandrikman Feb 27, 2024
3622bb2
refactor(RTT): move WebGL logic into new WebGlCoreCtxRenderTexture
frank-weindel Mar 5, 2024
06f5894
refactor(RTT): move WebGL logic into new WebGlCoreCtxRenderTexture (#…
wouterlucas Mar 19, 2024
ed0ef0a
Nodes provide parent render texture framebuffer dimensions
erikhaandrikman Mar 27, 2024
f7bc917
Implement uniform framebuffer dimensions value
erikhaandrikman Mar 27, 2024
9aaba51
Add framebuffer dimensions to render operation
erikhaandrikman Mar 27, 2024
e6f8872
Update text rendering for render textures
erikhaandrikman Mar 27, 2024
9b66452
Update vertex calculation for render textures
erikhaandrikman Mar 27, 2024
5baaeb2
Update rtt examples
erikhaandrikman Mar 27, 2024
41c0925
Merge branch 'feature/rtt' of github.com:lightning-js/renderer into f…
erikhaandrikman Mar 27, 2024
9b7c616
Merge branch 'main' into feature/rtt
erikhaandrikman Mar 28, 2024
d4eb343
Update memory usage for render textures
erikhaandrikman Mar 29, 2024
7c5145f
Improve batched rendering of rtt enabled nodes
erikhaandrikman Mar 29, 2024
9059f39
Implement rendering nested rtt nodes
erikhaandrikman Apr 3, 2024
8be2497
Implement local transform for render texture children
erikhaandrikman Apr 4, 2024
5d9f623
Reset global transformation for immediate rtt children
erikhaandrikman Apr 8, 2024
3771d43
Reset global transformation for immediate rtt text children
erikhaandrikman Apr 8, 2024
c2f7083
Update examples
erikhaandrikman Apr 9, 2024
f6103d7
Merge branch 'main' into feature/rtt
erikhaandrikman Apr 9, 2024
c8e623f
Remove rtt node ref on destroy
erikhaandrikman Apr 11, 2024
b7208bd
Remove internal prop from writeable node props
erikhaandrikman Apr 11, 2024
1c5ee9c
Track rtt updates in CoreNode
erikhaandrikman Apr 15, 2024
57c6311
Merge branch 'main' into feature/rtt
erikhaandrikman Apr 15, 2024
2800655
Enable dynamic rtt updates
erikhaandrikman Apr 16, 2024
5d58b57
Add render texture snapshot
erikhaandrikman Apr 16, 2024
d46757f
Update snapshot
erikhaandrikman Apr 18, 2024
bdf25f8
Merge branch 'main' into feature/rtt
erikhaandrikman Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions examples/tests/no-rtt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { ExampleSettings } from '../common/ExampleSettings.js';
import test from './alpha-blending.js';
interface AnimationExampleSettings {
duration: number;
easing: string;
delay: number;
loop: boolean;
stopMethod: 'reverse' | 'reset' | false;
}

const animationSettings: Partial<AnimationExampleSettings> = {
duration: 14000,
delay: 400,
loop: true,
stopMethod: 'reverse',
easing: 'ease-in-out-back',
};

export default async function ({ renderer, testRoot }: ExampleSettings) {
const node = renderer.createNode({
x: 0,
y: 0,
width: 1920,
height: 1080,
color: 0x000000ff,
parent: testRoot,
});
const clippingNode = renderer.createNode({
x: 0,
y: 0,
width: 1920,
height: 1080,
parent: node,
clipping: true,
color: 0x00000000,
});

const rootRenderToTextureNode = renderer.createNode({
x: 0,
y: 0,
width: 1920,
height: 1080,
parent: clippingNode,
rtt: false,
zIndex: 5,
colorTop: 0xc0ffee00,
colorBottom: 0xbada5500,
});

new Array(2000).fill(0).forEach((_, i) => {
const image = i % 105;
const a = renderer.createNode({
parent: rootRenderToTextureNode,
x: (i % 15) * 120 + 120,
y: Math.floor(i / 15) * 120 + 150,
width: 120,
height: 120,
scale: 0.85,
// src: '../assets/rocko.png',
src: `https://picsum.photos/id/${image + 30}/120/120`,
});

const animation = a.animate(
{
y: Math.floor(i / 15) * 120 - 5000,
},
animationSettings,
);

animation.start();
});
}
245 changes: 245 additions & 0 deletions examples/tests/rtt-dimension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
import type { ExampleSettings } from '../common/ExampleSettings.js';
import test from './alpha-blending.js';
interface AnimationExampleSettings {
duration: number;
easing: string;
delay: number;
loop: boolean;
stopMethod: 'reverse' | 'reset' | false;
}

const randomColor = () => {
const randomInt = Math.floor(Math.random() * Math.pow(2, 32));
const hexString = randomInt.toString(16).padStart(8, '0');
return parseInt(hexString, 16);
};

export default async function ({ renderer, testRoot }: ExampleSettings) {
const node = renderer.createNode({
x: 0,
y: 0,
width: 1920,
height: 1080,
color: 0x000000ff,
parent: testRoot,
});

// RTT Node 1
const rttNode = renderer.createNode({
x: 100,
y: 200,
width: 300,
height: 300,
parent: node,
rtt: true,
zIndex: 5,
colorTop: 0xfff00fff,
colorBottom: 0x00ffffff,
});

const rect = renderer.createNode({
x: 0,
y: 0,
width: 300,
height: 300,
parent: rttNode,
color: 0xff0000ff,
});

const label1 = renderer.createTextNode({
x: 0,
y: 0,
text: 'Render to texture',
parent: rttNode,
fontSize: 48,
color: 0xffffffff,
fontFamily: 'Ubuntu',
});

const rocko1 = renderer.createNode({
x: 50,
y: 100,
width: 300,
height: 300,
parent: rttNode,
src: '../assets/rocko.png',
});

// RTT Node 2
const rttNode2 = renderer.createNode({
x: 500,
y: 200,
width: 300,
height: 300,
parent: node,
rtt: true,
colorTop: 0xfff00fff,
colorBottom: 0x00ffffff,
});

const rect2 = renderer.createNode({
x: 0,
y: 0,
width: 300,
height: 300,
parent: rttNode2,
color: 0xc0ff33ff,
});

const label2 = renderer.createTextNode({
x: 0,
y: 0,
text: 'Render to texture',
parent: rttNode2,
fontSize: 22,
color: 0xff00ffff,
fontFamily: 'Ubuntu',
});

const rocko2 = renderer.createNode({
x: 50,
y: 100,
width: 300,
height: 300,
parent: rttNode2,
src: '../assets/rocko.png',
});

// RTT Node 2
const rttNode3 = renderer.createNode({
x: 900,
y: 200,
width: 800,
height: 300,
parent: node,
rtt: true,
colorTop: 0x67378dff,
colorBottom: 0x9cbd61ff,
});

const rect3 = renderer.createNode({
x: 0,
y: 0,
width: 300,
height: 300,
parent: rttNode3,
color: 0xc0ff33ff,
});

const label3 = renderer.createTextNode({
x: 0,
y: 0,
text: 'Render to texture',
parent: rttNode3,
fontSize: 22,
color: 0xff00ffff,
fontFamily: 'Ubuntu',
});

const rocko3 = renderer.createNode({
x: 50,
y: 100,
width: 300,
height: 300,
parent: rttNode3,
src: '../assets/rocko.png',
});

const nestedRTTNode1 = renderer.createNode({
x: 400,
y: 0,
width: 150,
height: 150,
parent: rttNode3,
rtt: true,
colorTop: 0x26f1e0ff,
colorBottom: 0xffffffff,
});

const rect4 = renderer.createNode({
x: 0,
y: 0,
width: 150,
height: 150,
parent: nestedRTTNode1,
color: 0xc0ff33ff,
});

const label4 = renderer.createTextNode({
x: 0,
y: 0,
text: 'Nested',
parent: nestedRTTNode1,
fontSize: 22,
color: 0xff00ffff,
fontFamily: 'Ubuntu',
});

const rocko4 = renderer.createNode({
x: -120,
y: 50,
width: 300,
height: 300,
parent: nestedRTTNode1,
src: '../assets/rocko.png',
});

// Copy source texture from rootRenderToTextureNode
for (let i = 0; i < 50; i++) {
const a = renderer.createNode({
parent: node,
x: (i % 15) * 120 + 100,
y: Math.floor(i / 15) * 120 + 600,
width: 100,
height: 100,
texture: nestedRTTNode1.texture,
});
}

const animation = rocko4.animate(
{
rotation: 0.3,
scale: 1.5,
y: 110,
x: -50,
},
{
duration: Math.random() * 4000 + 3000,
loop: true,
stopMethod: 'reverse',
easing: 'ease-in-out',
},
);

animation.start();

renderer.createTextNode({
x: 100,
y: 160,
text: 'RTT Dimension',
parent: node,
fontSize: 22,
color: 0xffffffff,
fontFamily: 'Ubuntu',
});

renderer.createTextNode({
x: 900,
y: 160,
text: 'Nested RTT',
parent: node,
fontSize: 22,
color: 0xffffffff,
fontFamily: 'Ubuntu',
});

renderer.createTextNode({
x: 100,
y: 560,
text: 'Nested RTT copies',
parent: node,
fontSize: 22,
color: 0xffffffff,
fontFamily: 'Ubuntu',
});
}
Loading
Loading