Hi all, I managed to create a texture paint script, but I encounterd a problem modifying the pixels of the texture with a AnimationCurve :
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
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)?
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.