- Home /
Changing scrolling textures on a plane using transparency
Hi,
Im trying to change between two textures on a plane with a scrolling effect and have hit a road block trying to achieve this.
My current attempt is to create a texture scrolling effect by setting the textures offset using something like this.
GetComponent<Renderer>().material.mainTextureOffset = new Vector2(F_Scroll_X, F_Scroll_Y);
I would then use the same method to move a second texture from a preset offset to 0,0 making it the visible texture.
I was hoping to find a method of having 2 materials on the mesh renderer and follow something like these steps
First material is shown
First Materials texture is offset to the side creating the scrolling effect
The second materials texture would be starting at an offset, and by changing its offset to 0,0 It would scroll into place as the First material is scrolled out
The problem with this is the first material is not transparent when offset so it is still visible with the result been you see whatever wrapping mode the texture is using rather then the second material.
Im looking for a way to make the original texture appear transparent when its wrapped. Is this possible?
an alternate solution to achieve the same effect I considered was to have the two textures overlap but the original would somehow have an offset alpha channel that I could scroll to make it fully transparent, but I have no idea how I would go about achieving something like this. Is this possible with shaders and something I need to look further into?
Sorry if my question isn't worded to well, but I hope it makes sense. Thanks in advance for any help/advice,
@$$anonymous$$r-Random570 Do you want to make the texture completely transparent or translucent?
And I don't understand where you would fit this, because I didn't quite understand your question, maybe the full script, or some images and videos would help.
I would like the texture to be fully transparent on the part that is been wrapped, but im unsure if that is possible. Perhaps its possible to disable texture wrapping and just leave the plane untextured where the texture has been offset?
Perhaps a better way to explain what im looking for is similar to an advertisement billboard in a major city. An ad is shown for a period of time and then a new advertisement is 'scrolled' into the frame as the last one is scrolled out. However instead of a set rotation of ads been cycled I need to replace the original ad with a new ad dependent on some other logic in the program.
I would like it to have an effect where the first texture is 'scrolled' out as the new one is co$$anonymous$$g in rather then a simple instant swap.
So I was hoping to find a method of having 2 materials on the mesh renderer and follow something like these steps
First material is shown
First $$anonymous$$aterials texture is offset to the side creating the scrolling effect
The second materials texture would already be set at an offset, and by changing its offset to 0,0 It would scroll into place as the First material is scrolled out
The problem with this is the first material is not transparent when offset so it is still visible with the result been you see whatever wrapping mode the texture is using rather then the second material.
So essentially what i am trying to achieve is when a texture of material is offset rather then any wrapping I would like it to be transparent. I'll edit the original question to try to make it more clear what im trying to achieve
Do you want this transparency to be immediate or does it have a fadeout effect?
The transparency would be immediate but only only the part of the texture that is wrapped. So for example if the Texture was offset 0.5 to the left, the plane texture would be on the left half of the plane and the right half would be transparent.
I have found the solution to my problem, Ill post it as an answer for future reference
Answer by Mr-Random570 · Jan 07, 2021 at 03:24 AM
This issue came down to my lack of knowledge around TextureWrapMode.Clamp and how it worked.
To solve my problem I had to make a 1 pixel border around the textures that was transparent, this pixel is what is used when the texture is wrapped using the Clamp Wrap mode.
Doing this allows the texture set at an offset of 0.5 to be displayed on half the plane whilst the other half is transparent. Using two materials setup like this I can move both offsets at the same time to scroll 1 texture in as the other is scrolled out.