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 cod · Sep 12, 2015 at 01:37 PM · errortexturepaint

Artifacts in custom texture painter

Hi all, I managed to create a texture paint script, but I encounterd a problem modifying the pixels of the texture with a AnimationCurve : alt text

Its seems like there's a problem with depth precision, altough I think the error is related to this piece of code :

 currHeight += brushHeight * speed;

where I modify the current pixel color adding brushHeight, which is just the evaluation of the AnimationCurve at a given distance from the hit pixel

PS : Note that I am using a 32 bit texture

brusherror.png (169.5 kB)
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
1

Answer by Bunny83 · Sep 16, 2015 at 09:44 AM

If by artefacts you refer are those rings within each circle, it looks like you somehow round or trucate your "distance" value. This can happen when you store the distance in an int variable. You have to provide more information to get a more precise answer.

  • How does your animation curve look like? maybe a screenshot?

  • What does your exact code look like?

  • You said that you "modify the current pixel color". How do you modify the color? Do you work with SetPixel or with an array and SetPixels?

  • You talked about a "hit point", so i guess you use some sort of raycasting. Physics Raycast, Collider.Raycast or Plane.Raycast? Are you sure you do the coordinate conversion right? Again, code would help to understand.

  • Is this a runtime script or an editor script? If it's an editor script, do you use a custom EditorWindow or have you implemented it in the sceneview (like the terrain editor)?

edit
From the code in your comment below it seems you get / set each pixel seperately each step. The problem here is that each color component is stored internally in a byte, not a float.

So by reading, modifing and writing it again the actual value get clamped to the nearest byte value. When you use a temp "Color[]" which you only read once in the beginning the problem should go away.

Comment
Add comment · Show 2 · 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 cod · Sep 20, 2015 at 08:08 AM 0
Share

@Bunny83 Thanks for the reply, I'm sorry for not being clear on the issue. However here're the answer to your points :

  1. $$anonymous$$y animationCurve is one of the presets, except for the fact that it is decreasing. However I noticed that this problem persists even if I change the curve

  2. I am working with setpixel right now, even if I plan to change the code to setpixels for better performance

  3. I perform a raycast form my mouse coordinates on the screen, then I store all data about the hit, I get the texture coordinates from the uv coordinates of the hit renderer by multiplying it by my texture size (I am sure about this part)

  4. It is a editor script

  5. For all pixels near the hit point I eveluate the distance with Vector2.distance, then I get the brush height by using AnimationCurve.evaluate.

Here's a sample of the code

 //Calculate distance from hit point and current point
 dist = Vector2.Distance(new Vector2(pixelUV.x - i, pixelUV.y - j), pixelUV);

 //Evaluate brushHeight
 brushHeight = brushFalloff.Evaluate(dist / brushSize);

 //If we press shift decrease, otherwise increase
 if (Event.current.shift)
     currHeight -= brushHeight * brushSpeed;
 else
     currHeight += brushHeight * brushSpeed;

 //Set pixel in our texture
 heightmap.SetPixel((int)pixelUV.x + i, (int)pixelUV.y + j, new Color(currHeight, currHeight, currHeight));

I noticed this problem occours when my brushSpeed is pretty low (about 0.01). According to me this seems to be caused by the summation of the small errors of the brush height float

avatar image Bunny83 cod · Sep 23, 2015 at 03:06 PM 0
Share

Sorry for the late response, i was sick...

So are your variables "dist" and "brushSize" also float variables ?

What's the range of your for loop variables? It should be "-brushSize" to "brushSize".

I guess i know what the problem is. I'll edit my answer

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

29 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

Related Questions

Wearied Error 1 Answer

Assigning UV Map to model at runtime 0 Answers

How to see which material is using a texure as normal map? 1 Answer

Paint a texture dynamically? 0 Answers

Prefabs made in Unity are insanely slow, and don't show textures. 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