0
\$\begingroup\$

I want to apply kind of noise/dust texture to objects so it would look good, and make it without having UV mapping in models. This is because I want to have a possibility to apply this to any objects, despite them having some other textures already. Just to have a way to make anything look little dirty.

It doesn't have to seam well between faces as this is noise type texture. The priority is that the texture scale is preserved.

In the vertex shader I have vertex coordinates as well as normal, binormal and tangent. I thought about projecting 3d vertex coordinates onto a plane defined by the normal and getting 2d coordinates from there, then use them as UV. But either I can't get the equations right, or it's not going to work. I check results on a sphere and I always get places where texture is stretching.

Is there any way to achieve good results?

I'm using XNA/Monogame, C#, HLSL if this matters.

UPDATE: I have found this:

Calculate Rotation Matrix to align Vector A to Vector B in 3d? https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/897677#897677

And I thought this could work:

  1. Find rotation matrix which would rotate plane normal to (0, 1, 0)
  2. Use this matrix to rotate current vertex position.
  3. Take (x, z) from the rotated position as (u, v).

However my math skills are not enough to make algorithms out if these equations. Would this work at all?

\$\endgroup\$
  • \$\begingroup\$ Have you considered volume texturing? \$\endgroup\$ – DMGregory Jan 1 '16 at 14:07
  • \$\begingroup\$ As I wrote below, need to have some real image, maybe even a photo. Can I build a 3D texture fro image? \$\endgroup\$ – Arek Jan 1 '16 at 19:37
1
\$\begingroup\$

You can use a small 3D texture for the noise and just use the model's vertex coordinates as texture coordinates.

https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture3d.aspx

\$\endgroup\$
  • \$\begingroup\$ Can I build such a 3D texture from 2D image? My noise is going to be some dirt, so it is somewhat random but it's not generated. I might even have to get a real photo of it. \$\endgroup\$ – Arek Jan 1 '16 at 19:36
  • \$\begingroup\$ It's extremely difficult to generate such 3D texture by hand. You're better off writing a procedural generator. The solution generally used in the industry (which was rejected in your question) is to pre-UV map the models with multiple texture layers: use a 2D dirt texture layer made by the artist and use a 3rd texture as an alpha mask to "apply" the dirt making it visible procedurally. It's also used for blood splatters and other similar effects. \$\endgroup\$ – Stephane Hockenhull Jan 2 '16 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.