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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by cobertos · Apr 06, 2013 at 09:46 PM · c#shadermaterial

Special shader question. How to draw half an object with one shader and the other half with another?

I think this is the right question? Here's the back story: I was playing a mod for a game called Garry's Mod. One of the game mechanics involved producing resources such as oil. To produce the oil you'd put down an oil derrick and let it produce the oil. Your oil barrel spawns in front of the derrick and starts out in wireframe. As it gets produces it slowly fills with the actual real texture of the model. For example, if you're oil barrel was 50% done producing, the top half would be wireframe and the bottom half would be the actual oil barrel texture.

How exactly would you do something like this in unity. I'm not sure how they did it in the source engine but if they did it with lua in there, I'm guessing there's some way that its possible to do in unity.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Owen-Reynolds · Apr 07, 2013 at 02:08 AM

You'd draw it twice, using different shaders. Probably just draw a different "wireframe" model for one of them, then a "bottom half" for the real, which covers the wireframe.

For the "real" part, skip the top using a shader parameter, maybe HT. The program would set it and the shader would say something like if(o.vert.y>HT) discard;. Since the shader can't normally access the model coords, you'd have to copy it like in the "Custom data computed per-vertex" surf shader example. It's not super-easy -- you have to type some shader lines -- but dosn't use advanced math or anything.

You could also just use one shader, and the if(y>HT) test would put a grey texture on the unbuilt part (but would obviously be the same model.)

Comment
Add comment · Show 4 · 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 cobertos · Apr 07, 2013 at 05:51 AM 0
Share

I'm unfamiliar with HT? Is it something I can set per mesh or object? I can't be changing a shader parameter directly because then it would change it on all objects that might be using this shader (so the shader would have to take in some sort of per object data).

The other thing, I'm not sure if I can do this with discarding a vertex? Consider I have a barrel with a circle of vertices at the top and the bottom, discarding vertices would always end up in the bottom ring being the vertices that pass the y height test. The effect as I recall was also very smooth as in it scrolled up the height of the barrel. I looked for a video but sadly could not find any.

avatar image Owen-Reynolds · Apr 07, 2013 at 02:53 PM 1
Share

Sorry, HT would be a uniform shader parameter you make up, like _Color is now. That's what I meant by you have to set it in the vertex program, since it's made-up. Shader parms are on the material instance, so, (again like _Color,) are set for that one gameObject (`material.setFloat("HT",2.3f);`)

Discard is a pixel command. Right, you can't discard a vertex. And a line like if(IN.vert.y>3) IN.vert.y=3; usually gives terrible-looking results.

avatar image cobertos · Apr 08, 2013 at 02:01 AM 0
Share

You're saying that it's set on the material instance, wont it change the value in the material directly (so any object with that material will have it changed)? I didnt think it created a copy of the material for each object.

avatar image Owen-Reynolds · Apr 08, 2013 at 02:48 AM 1
Share

http://docs.unity3d.com/Documentation/ScriptReference/Renderer-material.html

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

11 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

Related Questions

Is it possible to modify a material/shader in code? 1 Answer

How to create light like in minecraft? 1 Answer

How to render black borders around texture of simple 3D quad in c#? 0 Answers

How to get the spriterender default material in the code 1 Answer

Material doesn't have a color property '_Color' 4 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