Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

feat: add <Fbo /> abstraction#228

Merged
alvarosabu merged 28 commits intomainfrom
feature/149-add-useFBO
Oct 7, 2023
Merged

feat: add <Fbo /> abstraction#228
alvarosabu merged 28 commits intomainfrom
feature/149-add-useFBO

Conversation

@kekkorider
Copy link
Copy Markdown
Collaborator

@kekkorider kekkorider commented Sep 21, 2023

This is basically copypasted from Drei 😀

At the moment, when you head over /abstractions/use-fbo the console shows this error:

Screenshot 2023-09-21 alle 21 39 35

That's because here I'm using useTresContext() to get info about the size and viewport.
Any help on how to use useTresContextProvider() would be much appreciated 🥸

Closes #149

@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 21, 2023

Deploy Preview for cientos-tresjs ready!

Name Link
🔨 Latest commit 54b3730
🔍 Latest deploy log https://app.netlify.com/sites/cientos-tresjs/deploys/652165692da6af00087fa9ed
😎 Deploy Preview https://deploy-preview-228--cientos-tresjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kekkorider kekkorider changed the title Add useFBO() abstraction feat: add useFBO() abstraction Sep 21, 2023
@JaimeTorrealba
Copy link
Copy Markdown
Member

Since useTresContextProvider() is a provide/inject value, I believe you can't use outside setup context

Maybe we can convert this one into a renderlessComponent
You can base on the StatsGL component, for example.

Copy link
Copy Markdown
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good :)

Comment thread src/core/abstractions/useFBO.ts Outdated
} & WebGLRenderTargetOptions

export function useFBO(
width?: number | FBOSettings,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Width could be FBOSettings ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comes from Drei.

IMHO this is in case you do not specify the size (i.e. fullscreen) and you provide the settings object as first parameter.

Comment thread src/core/staging/Sky.vue Outdated
:material-uniforms-mieCoefficient-value="props.mieCoefficient"
:material-uniforms-mieDirectionalG-value="props.mieDirectionalG"
:material-uniforms-sunPosition-value="sunPosition"
:material-uniforms-mie-coefficient-value="props.mieCoefficient"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break this abstraction @alvarosabu, what is needed here to use the linter propertly? a git pull??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't blame me, I simply ran pnpm lint --fix 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know heheh this was an issue in others PRs too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kekkorider please merge last main with the eslint over-rule and set the tmeplate of this file to:

  <primitive
    :object="skyImpl"
    :material-uniforms-turbidity-value="props.turbidity"
    :material-uniforms-rayleigh-value="props.rayleigh"
    :material-uniforms-mieCoefficient-value="props.mieCoefficient"
    :material-uniforms-mieDirectionalG-value="props.mieDirectionalG"
    :material-uniforms-sunPosition-value="sunPosition"
    :scale="props.distance"
  />

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvarosabu I just rebased and force-pushed (I'm used to work this way instead merging main).
After running pnpm lint --fix everything was ok as expected.

Comment thread src/core/abstractions/useFBO.ts Outdated
// const viewport = useThree((state) => state.viewport)
const viewport = { dpr: 1.5 }

const _width = typeof width === 'number' ? width : size.width * viewport.dpr
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could pass default values in the props or in the parameters,
but these types of validations (for type) are not necessary, for that is typescript :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking the same thing, but I was having a lot of errors in the editor (despite everything was working).
So I copypasted this stuff as-is from Drei.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it works and then we see if we can clean something :)

@kekkorider
Copy link
Copy Markdown
Collaborator Author

Now we have something 🥸

fbo.mp4

@kekkorider kekkorider force-pushed the feature/149-add-useFBO branch from 4a632f0 to f3a00a1 Compare September 22, 2023 08:50
Copy link
Copy Markdown
Member

@alvarosabu alvarosabu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent first contribution @kekkorider 👏🏻

Just change the naming convention to Fbo rather than useFbo since is not composable and change the file from a ts to a vue component to ensure better reactivity

Comment thread src/core/abstractions/useFBO.ts Outdated
settings?: WebGLRenderTargetOptions
}

export const UseFBO = defineComponent<UseFboProps>({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a component rather than a composable I would probably avoid using use prefix and turn this file into a SFC vue component called <Fbo /> rather than a ts component.

This will make things easier for the props.

Also is not reactive, if any of the props change the target is not disposed and created again.

@kekkorider take a look at this component https://github.com/Tresjs/cientos/blob/main/src/core/staging/ContactShadows.vue let me know if you need help.

<TresBoxGeometry :args="[1, 1, 1]" />
<TresMeshBasicMaterial
:color="0xff8833"
:map="fboRef?.texture || null"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, this way of using is good, but it feels a little odd...

Since it is useful to use a renderless component, could this be made with slots?

Something like:

Is that possible, did you find comfortable? The FBO is use only in :map property?
What do you think, guys?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaimeTorrealba how would it look if done via slots for example?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the code could be something like:

const slots = useSlots()
const material = slot.default()[0].children.material // and here you access the material of the slot component
//and you can assign the "texture" created directly, obviously some validations are needed first

Just by the record, I'm not demanding a change, you did this abstraction @alvarosabu you know what is better, is just I feel this way of usage a little weird, you don't. Other solutions are considered too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what I mean actually, you mention passing the fboRef as a map it's odd. What would be the alternative?

const slots = useSlots()
const material = slot.default()[0].children.material

Here you are mentioning the possible implementation, what I mean is how would this look in the template? Like this?

<Fbo>
  <TresMesh>
        <TresBoxGeometry :args="[1, 1, 1]" />
   </TresMesh> 
 </Fbo>

@kekkorider
Copy link
Copy Markdown
Collaborator Author

I refactored everything to make it a renderless component following the new naming convention as @alvarosabu requested.

Basically it works, but whenever I change a prop the box turns black (no map set).
I'm logging the UUID of the FBO texture in the browser console and it stays the same no matter what.

@kekkorider kekkorider changed the title feat: add useFBO() abstraction feat: add <Fbo /> abstraction Sep 26, 2023
Copy link
Copy Markdown
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvarosabu when you have time please check this one, when the components have WebGlRenders I couldn't make then reactive... Example of that is the Reflector, so please if you know a way to achieve this, comment us

@alvarosabu
Copy link
Copy Markdown
Member

alvarosabu commented Sep 28, 2023

@kekkorider only missing the docs and add the composable as well in them (the composable needs to be used inside of a child component since it needs the context of TresCanvas)

@kekkorider
Copy link
Copy Markdown
Collaborator Author

@alvarosabu awesome! I will work on it next week. 🍻

@kekkorider kekkorider force-pushed the feature/149-add-useFBO branch from c17039a to 023422b Compare October 4, 2023 22:05
@kekkorider kekkorider marked this pull request as ready for review October 5, 2023 12:44
@kekkorider
Copy link
Copy Markdown
Collaborator Author

@alvarosabu @JaimeTorrealba I guess we're there 🥳

@alvarosabu
Copy link
Copy Markdown
Member

Hey @kekkorider amazing job! There seem to be some conflicts with main, could you please check it?

@kekkorider kekkorider force-pushed the feature/149-add-useFBO branch from 48749bd to 81acaed Compare October 6, 2023 13:02
@kekkorider
Copy link
Copy Markdown
Collaborator Author

Hey @kekkorider amazing job! There seem to be some conflicts with main, could you please check it?

@alvarosabu I just rebased and removed the conflicts 🙌

Copy link
Copy Markdown
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work man, the component looks nice, I'll include it for the next v3.5 of cientos
Thanks you
I've just some little changes, docs related, and one question

Comment thread docs/guide/abstractions/fbo.md Outdated
Comment thread docs/guide/abstractions/fbo.md Outdated
Comment thread docs/guide/abstractions/fbo.md Outdated
Comment thread docs/components.d.ts Outdated
@kekkorider
Copy link
Copy Markdown
Collaborator Author

@JaimeTorrealba I just fixed everything you asked 🙌

Copy link
Copy Markdown
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been a difficult one :D. But great work.

I'll not merge until @alvarosabu check this one but see everything fine

Comment thread docs/guide/abstractions/use-fbo.md
Copy link
Copy Markdown
Member

@alvarosabu alvarosabu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant work @kekkorider @JaimeTorrealba

<TresBoxGeometry :args="[1, 1, 1]" />
<TresMeshBasicMaterial
:color="0xff8833"
:map="fboRef?.texture || null"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what I mean actually, you mention passing the fboRef as a map it's odd. What would be the alternative?

const slots = useSlots()
const material = slot.default()[0].children.material

Here you are mentioning the possible implementation, what I mean is how would this look in the template? Like this?

<Fbo>
  <TresMesh>
        <TresBoxGeometry :args="[1, 1, 1]" />
   </TresMesh> 
 </Fbo>

Comment thread docs/components.d.ts Outdated
Comment thread docs/guide/abstractions/use-fbo.md
@alvarosabu alvarosabu merged commit 6efc076 into main Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useFBO abstraction

3 participants