Home Technical Talk

Angle maps

Gestalt
polycounter lvl 11
Offline / Send Message
Gestalt polycounter lvl 11
I posted this in the other thread, but I would like to make a knew one that is specifically for the topic. I've been thinking of using spherical coordinates to describe my normalized bump maps. I believe you could do this practically by rotating a spherical coordinate system around the Y axis and adjust you angle values to give you the proper range(add pi/2 to theta and -pi/2 to phi).

So your theta-hat to Cartesian would look like this:
x=sin(theta+pi)
y=cos(theta+pi)sin(phi)
z=cos(theta+pi)cos(phi)

which simplifies to:
x = -sin(theta)
y = -cos(theta)sin(phi)
z = -cos(theta)cos(phi)


If I mixed up my math at some point please let me know.

I used to think you could maybe store these values in the map itself from -1 to 1, but that would destroy much of the benefits of working this way. What you could do is store 2theta/pi (divide by pi/2) in one channel and 2phi/pi in the other (values from -1 to 1), and when you import multiply by pi/2 (only about 1.5ish so you aren't making up too much info, and the falloff is smoother).

Starting with the pure, basic angle values rather than calculated values has many other benefits as well. No matter what it's normalized, vector distance r will always be 1 in this sphere, you can combine maps with ease and without breaking anything since they're just angles, the B channel would be freed up inherently (you could use it for something actually useful like having a height map in each bump texture), you would have angles already computed to use for all types of fun shader math.

Replies

  • arrangemonk
    Options
    Offline / Send Message
    arrangemonk polycounter lvl 15
    whats the point in saving angles, since you still need tangent base as reference.

    i prefer not having to deal with quaternions for light calculation
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    They would probably be converted into Cartesian space before using them with other vectors or else you're going to have to go in and make some fundamental changes. If my math is correct you would use
    x = -sin(theta)
    y = -cos(theta)sin(phi)
    z = -cos(theta)cos(phi)
    on your final, combined angle map to get normalized Cartesian vectors

    The benefit to starting with angles is you only need two channels to describe them, they are very easy to combine, they will always give you something that is normalized, and they are more elegant and direct than storing vectors in Cartesian space. I'm sure there are many other positives that I don't have listed at the moment; I'd imagine it be useful to at least have the information when pursuing more complex shader setups.
  • equil
    Options
    Offline / Send Message
    reconstructing 2-component normals is cheaper and spherical coordinates don't interpolate linearly (imagine having 1 pixel with φ=π, with a neighboring pixel being φ=-π).
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    reconstructing 2-component normals is cheaper and spherical coordinates don't interpolate linearly (imagine having 1 pixel with φ=pi, with a neighboring pixel being φ=-pi).

    I should correct one thing I think is misleading, the theta and phi here are transformed when they are actually applied, they are not really spherical coordinates in the vanilla sense. The idea is actually similar to derivatives and the range is -pi/2 to pi/2. I think I need to go back in and make sure my math above is correct, but beyond that the concepts should still be sound.

    Edit: yeah I believe theta needs to be adjusted by pi and not pi/2, so I'll go back and change that.
Sign In or Register to comment.