-
A little confused about progress here Imagine I have the following component function HeroWrapper() {
const el = useRef(null)
return (
<>
<div id="hero" ref={el} className="top-0 h-[400vh]"></div>
<UseCanvas>
<ScrollScene track={el}>{(props) => <Hero {...props} />}</ScrollScene>
</UseCanvas>
</>
)
}
In this component, I am using a particular timeline (inside I've made the scrollable part of this section 400vh or 4x the viewport height. What I am expecting, is I'm actually expecting these to be normalized - e.g, progress starting at 0, and ending at 1.0. I can probably write a function to map this range to something I'm expecting, but I'm wondering why it starts at 0.2 (or 0.5 if 100vh etc)? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @mokargas You are correct in your thinking that Indeed Your confusion comes from the fact that the hero is already in the viewport when the page loads, hence the progress is already started. You can figure out your starting value based on the height and remap the progress. Your container is 400vh - each section is 100vh. The container actually has to travel 500vh to enter and fully exit the viewport (after 400vh the last section is still inside the viewport). 0 - No part of the container is in view (all of it is below the viewport) - this never happens as your hero sits at the top of the page |
Beta Was this translation helpful? Give feedback.
-
Lots to cover here, I'll do my best without having access to the actual code
I wasn't aware - do you have a link to share so I can take a look how it works? I can try to take a look and see if I can make VSS compatible with a declarative EffectComposer
Got it, yes this is true since the VSS runs in separate renders. So if you have two distinct scenes, with no RenderTexture transition in between them (as discussed previiously) - are you sure you even need the scroll-rig at this point? If all you are doing is scrolling between two scenes could you not have two canvases after each other in the DOM? (maybe I'm oversimplifying here but worth asking)
Not sure I understand this part:
But if you defined lights and fog in the Hero component - and the hero unmounts you would remove them from the global scene - is that what you were asking? Here's a test where the global scene has a city environment and a magenta directional light - you can see it on the ScrollScenes - and the ViewportScrollScene has a "dawn" environment and no directional light. But scene containers are 300vh. https://codesandbox.io/s/ss-vs-vss-300vh-test-jjldcy?file=/src/App.jsx Do you maybe need to adjust the scale of the content inside your VSS? |
Beta Was this translation helpful? Give feedback.
-
@ffdead Thanks for taking the time to work through this with me
Mmy project one is complicated since it uses events and regression to control effects and performance, I'll see if I can make a simple one when I get a few mins.
Thanks I understand this now. I had an incorrect assumption about VSS
Yes. The idea is not to render two or Canvas. The reason is the need to maintain events and the fact that each Canvas will treat materials, assets etc as new entities even if they are "reused" in the project. So each Canvas will recompile everything which has very poor performance for what I'm doing (Tried that already 😂)
Not quite, as the component isn't unmounted. If I define a directional light inside the Hero component which is wrapped by a ScrollScene, my directional light will not render (the lack of the blue light in the second screenshot). I have to move it to the . Same issue with fog. I'm not 100% sure if this is an issue with my stack or versions, so I was more wondering if you'd encountered it. e.g Let's say we have two scroll scenes, not v scroll scenes
The thing I didn't understand is why VSS would need to be scaled but not SS. In my screenshots the only difference was using VSS or SS, nothing else. But judging from the example you've given where both scale to the 300vh container height, I am going to put this down to an issue with my stack. Basically Hero needs to be visually 100vh, but scroll 300vh. However I now understand that's something I need to solve, probably by making the Hero VSS/SS sticky like you would with a standard Lenis setup. |
Beta Was this translation helpful? Give feedback.
Hi @mokargas
You are correct in your thinking that
scrollState
is relative to the component you are tracking.Indeed
progress
is0
when the DOM element enters the viewport at the bottom of the screen, and1
when it exists the viewport at the top of the screen.Your confusion comes from the fact that the hero is already in the viewport when the page loads, hence the progress is already started. You can figure out your starting value based on the height and remap the progress.
Your container is 400vh - each section is 100vh. The container actually has to travel 500vh to enter and fully exit the viewport (after 400vh the last section is still inside the viewport).
0 - No part of the containe…