Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by DayyanSisson · Aug 10, 2012 at 05:40 AM · texturetriggertexture2druntimepixel

Changing Part Of Texture/Material

I'm wondering if I can change the texture of part of an object if it enters a trigger? For example, I have a flat plane, and I put a trigger behind it. The plane has a metal texture on it. If I push part of the plane into the trigger, I want only that part of the texture that has entered the trigger to change to a water texture. Just that part only, the rest of the plane still has its metal texture. Is this even possible? If so, is it too intensive on the computer to work en masse?

I've looked into using:

Texture2D.GetPixels
Texture2D.SetPixels
Texture2D.ReadPixels
Texture2D.LoadImage

But I don't know how to use them to perform what I need. I was thinking if I can find whether or not the individual pixels have entered the bounds of the triggers, change them using LoadImage on those specific pixels. I'm not sure how that would translate into code. Can anyone put me on the right track?

Comment
Add comment · Show 3
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 tomekkie2 · Aug 10, 2012 at 07:11 AM 0
Share

I would try to get the positions of individual pixels, which depend on the mesh faces vertex positions, then, uv mapping, textureoffset and texturescale and loop through those pixels if they are contained within the trigger collider bounds. Possibly you could also play with create a special shader for that. Or you could setup two overlapping objects with the cutout shaders on them with inverse transparency maps - one with base metal texture and other with base water texture and then manipulate with textureoffset following the trigger position

avatar image DayyanSisson · Aug 10, 2012 at 05:43 PM 0
Share

Yeah that was what I was thinking, but I can't seem to find how to find the positions of individual pixels.

avatar image tomekkie2 · Aug 10, 2012 at 05:49 PM 0
Share

T think it might be easier and more efficient to do with shaders.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ScroodgeM · Aug 10, 2012 at 06:21 PM

sol 1

use paint mask to cover the object with textures. similar to terrain in unity. mask can be stored in other texture or vertex colors. need simple shader for it.

sol 2

use projectors to draw another texture on top of your metal

shader for sol 2

Shader "Projector/Unlit" {
  Properties {
        _Color ("Main Color", Color) = (1,1,1,1)       
     _ShadowTex ("Cookie", 2D) = "" { TexGen ObjectLinear }
     _FalloffTex ("FallOff", 2D) = "" { TexGen ObjectLinear }
  }
  Subshader {
     Pass {
        ZWrite off
        Fog { Color (0, 0, 0) }
        Color [_Color]
        ColorMask RGB
        Blend One OneMinusSrcAlpha
        Offset -1, -1
        SetTexture [_ShadowTex] {
           combine texture * primary, texture
           Matrix [_Projector]
        }
        SetTexture [_FalloffTex] {
           constantColor (0,0,0,1)
           combine previous lerp (texture) constant
           Matrix [_ProjectorClip]
        }
     }
  }
}

sol 3

use two materials on one mesh to draw opaque metal first, and transparent other texture on top. changing transparency will show other texture on top of opaque

sol 4

redraw textures. get a raycasthit for point of object, this gives you object's coords and texture's coords of hit. then get-set pixels. not recommended caused by performance reason
Comment
Add comment · Show 13 · 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 DayyanSisson · Aug 10, 2012 at 06:54 PM 0
Share

I tried using Solution 2 which makes perfect sense and actually gives me a lot of extra functionality, but what happens is that when part of it moves into the effect of the projector, the whole plane turns to that texture.

avatar image ScroodgeM · Aug 10, 2012 at 07:13 PM 0
Share

move plane with projectors to make projected image 'sticked' to plane. when whole plane turns to texture - you can replace plane's material's texture to this texture and remove all projectors

avatar image DayyanSisson · Aug 10, 2012 at 07:25 PM 0
Share

But that still doesn't solve the problem of making only part of the plane turn to that texture. As long as any part of the plane moves into the area of the projector, the whole plane is projected on, even parts that aren't in the projector's AO$$anonymous$$

avatar image ScroodgeM · Aug 10, 2012 at 08:14 PM 0
Share

but you can project only a small area on whole plane. just project a new texture on small part and you'll see only small part is changed

avatar image DayyanSisson · Aug 10, 2012 at 08:32 PM 0
Share

Its probably the shader I'm using. If I used a normal diffuse material on the projector it projects the whole plane, and the only one that works is Projector/$$anonymous$$ultiply but what I apply my own textures it doesn't even project since it deals with light/shadows and only takes black and white. What should I use?

Show more comments

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

9 People are following this question.

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

Related Questions

Create a custom texture from code? 1 Answer

How to create an own Texture i.e. how to dye pixels? 0 Answers

Raycast project to texture at runtime 1 Answer

Texture2D: pixel Specific alpha not working? 4 Answers

How to fill texture that would be avaliable to ither shaders? 1 Answer


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