Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nstens · Jan 15, 2019 at 10:50 AM · shadermaterialrender texturedynamicallysetpixels

How to dynamically reveal another material/texture

Example outcome


My idea is to basically have a circle/area around the player, and as they move through the level, reveal a different material, you can see the effect in the above picture. (The player has moved from the bottom left, filling the area that they've come from)


I've looked around and tried a couple of different methods. The first being a custom shader that masks out material A to reveal B, and then I'm drawing to a render texture and that's being used as the mask. That somewhat works but it doesn't seem to be exporting to Android at all.


Alternatively I have the effect working with getPixel and setPixel, but that seems to be slow. It uses the player's position to update the texture but there's a slight jitter between the player's location and the texture position being updated. (And also if I wanted a bigger texture that seems to slow it down even more).


So I'm just curious if anybody has achieved this kind of effect or if I'm going down the right/wrong route.

maze-fill-with-texture.png (55.8 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tormentoarmagedoom · Jan 15, 2019 at 12:00 PM 0
Share

Good day.

I don't know the answer yet. I will have to do somethig similar in some months, I will try to find something similar to "fog of war" in other games, I recommend you to investigate about how fog of war is done, and sure you can adapt that to your issue.

Good luck!

avatar image Klarzahs · Jan 15, 2019 at 12:33 PM 0
Share

You can probably solve this by applying sprite masks every second at the player's position. Every new sprite reveals a little bit more of the underlying texture. You might have to merge shapes after a while, as a lot of small sprites will slow unity down.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BastianUrbach · Jan 27, 2019 at 05:34 PM

I guess I'm kinda late but my idea would be to use a trail renderer (or a similar script) and a shader that samples the texture with object space coordinates, like this:

 struct appdata {
     float4 vertex : POSITION;
 };
 
 struct v2f {
     float4 vertex : SV_POSITION;
     float2 uv : TEXCOORD0;
 };
 
 sampler2D _MainTex;
 float4 _MainTex_ST;
 
 v2f vert (appdata v) {
     v2f o;
     o.vertex = UnityObjectToClipPos(v.vertex);
     o.uv = TRANSFORM_TEX(v.vertex.xy, _MainTex);
     return o;
 }
 
 fixed4 frag (v2f i) : SV_Target {
     return tex2D(_MainTex, i.uv);
 }

Trail renderer texture reveal


trailreveal.png (411.1 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nstens · Jan 27, 2019 at 05:41 PM 0
Share

I did actually figure out a solution (using particles to cover the floor and deleting the floor as you go over so it looks seamless) but this actually helps me with another problem I had! I needed to figure out how to get a texture to show in object space (like the picture) and this should help, thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

171 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

How do I change render.material at runtime seamlessly? 2 Answers

Assign Texture To Material Unity 4.6 1 Answer

Updating custom material properties for RawImage 2 Answers

One outline material for multiple objects? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges