Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 moosefetcher · Jul 24, 2016 at 07:35 PM · normalsurface shadernormal mapbumpmapbump map

Dynamically generated bump map for Surface Shader?

The planet surfaces in my space game are generated by a surface shader which gets fed a number of randomly chosen textures. The shader is working really well, with uv coordinates offset by random amounts and city light textures scaled and thresholded depending on the population and size of the planet. This means I get a lot of variation with a lot less textures.

But I'd like to add bump mapping, if possible. I THINK a bump map uses the 3 coordinates (colours) to describe the direction of the normal at that UV coordinate. Id like to be able to affect the normal from within the shader (not by passing a pre-generated bump map), instead using the overall resultant brightness of the current pixel to describe if that pixel is receded slightly toward the centre of the planet sphere, or raised and prominent.

At the moment I'm using the following rough and experimental lines at the end of my 'surf' function to affect the normal of the current pixel (where _surface colour is the final _float4 colour of that pixel), but it's just turning the surface black:

         fixed3 adjustedNormal = o.Normal;
         adjustedNormal.x = adjustedNormal.x * _surfaceColour.r;
         adjustedNormal.y = adjustedNormal.y * _surfaceColour.r;
         adjustedNormal.z = adjustedNormal.z * _surfaceColour.r;
         o.Normal = adjustedNormal;

My question is, how should I affect the normal of a sphere, to simulate the slight variations in height of mountains and valleys on a planet surface without passing in a pre-calculated bump map?

Any help, much appreciated, thanks.

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 Glurth · Jul 24, 2016 at 09:58 PM 0
Share

That code wont actually change the direction of the normal. It will,however, make it have a magnitude that is NOT 1.0f, (which is usually what defines a normal vector).
If you were to do that same operation to a vertex on a sphere,centered at (0,0,0), the normals of triangles that USE this vertex WOULD be effected (assu$$anonymous$$g you recompute them).

avatar image moosefetcher · Jul 29, 2016 at 06:46 PM 0
Share

I found THIS question.. http://answers.unity3d.com/questions/561900/get-local-position-in-surface-shader.html ...but adding in the suggested code and changing the final line to o.localPos = adjustedNormal; doesn't work. Can I re-calculate the vertex position from inside my 'surf' function?

avatar image Glurth moosefetcher · Jul 31, 2016 at 10:07 PM 0
Share

That sounds like a job for a vertex shader, so I thought the answer was "NO". But, double checking found this: http://forum.unity3d.com/threads/u-3-0-surface-shader-vertex-shader-mixing.54264/

0 Replies

· Add your reply
  • Sort: 

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

52 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

Related Questions

How can I fix a normalmap procedurally generated? 2 Answers

How to add Bump/Normal Map to surface shader? (CG) 0 Answers

Problem with Normal Maps 1 Answer

What makes the Normal Map messed up behind the object?(solved) 1 Answer

How do I get Normal Maps to align with Tile Maps? 0 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