Home Technical Talk

Photoshop Normal map rotation tool?

Hey guys,

Been curious about this for a while, maybe someone here will know :

Over at Ubisoft, we have a Photoshop plug-in that does a few things with normal maps, I think it dates back to before Nvidia's plug-in. Anyway at home i often miss a particular feature this tool has. You could have it rotate a normal map at any custom angle, and it would somehow adjust all the channels for you so lighting wouldn't react wrong. This is an internal application and we can't transfer it out of the building.

The closest i can manage finding on the internet is actions that rotate at 90degree intervals. Anyone know of a custom rotation plug-in for normal maps in photoshop?

ps: I dream of one day being able to "free transform" any normal map element and have it automatically adjust the channels for you. *drool*.

Replies

  • mLichy
    Options
    Offline / Send Message
    Hmm, that sounds pretty awesome, I wish we had that at work... Although we have some other awesome stuff for Max I wish I had at home... but that's how it goes..

    Not sure about any kind of normal map rotation stuff, I'm also interested now.
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Ooops nevermind I misread your post
  • Snight
    Options
    Offline / Send Message
    Snight polycounter lvl 16
    THAT would be so awesome.
  • eld
    Options
    Offline / Send Message
    eld polycounter lvl 18
    I had dreams about such a thing for photoshop, working as the rotation tool, but since each resulting pixel is essentially just a vector, it should be easy to calculate the new colour for them.
  • vik
    Options
    Offline / Send Message
    vik polycounter lvl 13
    now, a tool like that would be cool indeed :>
  • oXYnary
    Options
    Offline / Send Message
    oXYnary polycounter lvl 18
    talk to Jogshy?
  • HarlequiN
    Options
    Offline / Send Message
    HarlequiN polycounter lvl 18
    That's a bloody good idea. Might be possible to do through just through scripting. Something like rotate the image, swap some channels, maybe invert them... do some clever blending. Maybe doable. I'll do some research, and write it up if I get a chance.

    Just tested it - Swapping the Red and Green Channels and inverting the new red channel appears to do the trick when rotating 90 degrees (CCW). It's easier said then done (and might vary based on the type of normal map), and it's a long way off from what you're suggesting, but it's a starting point.
  • crazyfingers
    Options
    Offline / Send Message
    crazyfingers polycounter lvl 10
    woops, should read replies before i post, harlequin is pretty much on with the red and green channels being the main targets for adjustment.

    All theory aside, if it were easy there would be a tutorial out there.

    But where do normal maps come from? A hieght-to-normal black and white image or a bake from 3d geometry. Both methods are easily rotated making this not too terribly important, though i do agree it would be really nice to easily rotated normals in photoshop for speed's sake.
  • Zack Fowler
    Options
    Offline / Send Message
    Zack Fowler polycounter lvl 11
    Art-Machine is talking about rotating to arbitrary angles. You would need to convert the RGB values to vectors, rotate the vectors around Z according to the desired rotation, convert those back to RGB, and then rotate the actual selection in Photoshop as if it were a standard rotation operation for an arbitrary angle.
  • JohnnyRaptor
    Options
    Offline / Send Message
    JohnnyRaptor polycounter lvl 15
    yeah but how would you adjust the colours ? as the angles change, the colours change, but you have no way of calculating that unless you have some hokus pokus formula for hue shifting

    edit, ps this would be a pretty awesome tool tho :poly142:
  • Zack Fowler
    Options
    Offline / Send Message
    Zack Fowler polycounter lvl 11
    The colors change because they represent vectors and the vectors change. You can't create a tool to rotate normal map images without converting the color data to vector data and then back. Basically each channel represents an axis in 3D space, R G B corresponding to X Y Z. The vector is like the line from the 3D point in space from RGB to the origin. No hokus pokus necessary.
  • Neox
    Options
    Offline / Send Message
    Neox veteran polycounter
    didn't brice recently did such a thing for maya?
  • Brice Vandemoortele
    Options
    Offline / Send Message
    Brice Vandemoortele polycounter lvl 19
    hello :)
    I guess we could do that with javascript in photoshop, with a popup asking for the angle. It will probably be more complicated to have a visual feedback while editing (like it would with the transform tool).
    In the meantime i wrote something you can use in maya. It has the advantage of taking the tangent space of your object into account, but using maya for this is really not the fastest.
    I've seen that photoshop now support some sort of gpu accelerated filters, maybe there's something there :)

    edit: Neox you've been faster there :)
  • Neox
    Options
    Offline / Send Message
    Neox veteran polycounter
    when you talk about the devil.... and there he is :)
  • SHEPEIRO
    Options
    Offline / Send Message
    SHEPEIRO polycounter lvl 17
    personally i dont need to see the trnsform in realtime, just transform the normal colours as is and re-vectorise when commiting
  • Neox
    Options
    Offline / Send Message
    Neox veteran polycounter
    yep i agree, no realtime transforms needed, but anyways would that really work? isn't there always some loss when you rotate it by any angle but 90°?
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    yeah you'd have to resample as well as re-normalise. It generally sounds like a bad idea.
    I'd just re-bake at the correct rotation, if it's from 3D source.
    Or as someone else said, if it's from heightmap data, rotate the heightmap then just run NVidia filter on it.

    I don't know why you'd ever want to rotate existing normal data to arbitrary angles... if you're doing that then it sounds like something is wrong with your workflow?
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    Mop I think it really is a tool for tiling env stuff, or overlaid layers for damage textures - in that case the underlying geo is just flat so no problems.
    Agreed, on character stuff it makes not much sense and can only cause a mess (would only work with Brice's tool, since it also updates the UVs...)
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Well, like I say, even for tiling env stuff, you still have the "source" art, right? whatever was used to generate the normal maps in the first place, whether it's 3D geometry, or a painted / photosourced heightmap.
    It's guaranteed to lose quality if you rotate normalmaps to arbitrary angles because of the resampling involved. Re-baking from source geometry ensures highest quality.
    Rotating the heightmap will lose a bit of quality from the resampling too, but probably not as much as actually rotating the end-result normal map. It's an extra step but it doesn't require any plugins or scripts...
  • divi
    Options
    Offline / Send Message
    divi polycounter lvl 12
    i'd rather have a tool that let's me rearrange UVs and moves all corresponding "finished" textureisles accordingly with it!
    *hopes for someone to call me stupid and post a link to it since it might just aswell have been done already*
  • Brice Vandemoortele
    Options
    Offline / Send Message
    Brice Vandemoortele polycounter lvl 19
    divi, you should have a look at the Warp Image tool in maya (UV Texture Editor>Polygons> Warp Image). You can use it to transfer color maps from one UV set to another. If you need to transfer normals than you should have a look at the link i gave above. You can transfer color maps in max using a rtt from one mesh to its duplicate with the new UVs, I don't really know about normals. Anyway this is far beyond the photoshop script subject ^^
  • e-freak
    Options
    Offline / Send Message
    it's pretty easy to code this with tangent-space normal maps. basic concept:

    save every pixel in to a 2D Array with it's current R and G (and B) Value (B will not change).
    R and G convert to a vector of 3 dimensions (while only 2 have a value, which is x for red and y for green and z is defined as following) with angle in dependence of theyr greyscale value that is alpha = (Greyscalevalue(of R or G)-128)*(90/128).
    So your pixel array now saves two vectors for R and G there one points left and up and one points towards the top (of the image boundaries) and up.
    These two vectors define a plane from which you extract the normal vector.

    Now you turn the image by a given angle. All Normalvectors created as previous described shall be turned around the absolute Z-Axis and you do the steps described above backwards (create a plane, extract two directional vectors one on the horizontal line and one on the vertical line which now differ from the image boundaries and reconvert the steepnes with tangens to an angle which will then be converted to a greyscale value). Just let your application of choice create the image out of the now modified array (use pushMatrix and rotate or equivalent of your coding language) and you have a turned tangent space normal map.

    going to code something like this but i'm in my exams phase at university for the next two weeks. if someone knows how to implent a processing written program (java) into photoshop this is an easy addon.
  • Funky Bunnies
    Options
    Offline / Send Message
    Funky Bunnies polycounter lvl 17
    I was going to try and give this a shot a couple months ago but I coulda sworn I read someone already did it at some point. But I guess not?

    I think one lingering obstacle is you'd have to know what pixels of the rotated and bilinear interpolated version correspond to the original pixels of the layer - unless you handle it within the code - as well as the issue of speed for photoshop scripting. But it seems like the people who know the photoshop sdk are few and far between :poly124:
    I'm curious though, since it's already been done by ubisoft. Three cheers for anyone who does it :D

    I agree with Brice and MoP though, probably for now the best option is to go the rtt approach. if you apply your normal map into a normal map bump slot you can transfer recalculated normals onto another object's uvs pretty quickly
  • Ryan Clark
    Options
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    Give this a shot. Not a plugin, but it might serve well enough:

    www.crazybump.com/NormalsTransformer.zip


    Illustrative Screenshot:

    normalstransformer.png
  • e-freak
    Options
    Offline / Send Message
    awesome :D

    may i ask what has been your approach on this?
  • divi
    Options
    Offline / Send Message
    divi polycounter lvl 12
    divi, you should have a look at the Warp Image tool in maya (UV Texture Editor>Polygons> Warp Image). You can use it to transfer color maps from one UV set to another. If you need to transfer normals than you should have a look at the link i gave above. You can transfer color maps in max using a rtt from one mesh to its duplicate with the new UVs, I don't really know about normals. Anyway this is far beyond the photoshop script subject ^^

    too bad im using max =(. totally slipped my mind that you can transfer maps with rtt, so thanks for reminding me :).
    would have been sweet though to just check a box in the UV editor that attaches the different maps to the isles and moves them with the UV isles. well, gotta do it the "long" way then :D.
  • Ryan Clark
    Options
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    @e-freak:

    Sure!

    I first used windows GDI+ to rotate the image.

    Then, for every pixel:
    translate components -127.5
    newX = x * Cos(angle) - y * Sin(angle);
    newY = x * Sin(angle) + y * Cos(angle);
    normalize to length 127.5
    translate components +127.5
  • Ryan Clark
    Options
    Offline / Send Message
    Ryan Clark polycounter lvl 18
    Just posted a version with better (less lossy) image quality:

    www.crazybump.com/NormalsTransformer.zip
  • Kessler
    Options
    Offline / Send Message
    Kessler polycounter lvl 17
    RYAN CLark is TURBO! Crazy bump changed my life. I used to be overweight and down in the dumps and now I have rock hard tangent space abs and and brighter outlook on life. Thanks Crazy Bump.
  • mLichy
    Options
    Offline / Send Message
    Hey, how does that rotate tool work? I tried running the exe on windows 64bit and it didnt work?

    Edit: NEVERMIND, lol
  • metalliandy
    Options
    Offline / Send Message
    metalliandy interpolator
    @Ryan Nice work mate!

    Please make a photoshop plugin version of CB with this but linked directly somehow to the transform tool...i could die a happy man then :P
  • Art-Machine
    Options
    Offline / Send Message
    OMG i never imagined i would stir up such a productive discussion! You guys are awesome, soon we'll have it linked to free transform, or the prompt asking for angle is fine too (that's how the Ubisoft one works).

    As for people questioning the usefulness of this, hard to describe examples in text... All i can say is not having that kind of option has caused me to NOT do things that could have added to a piece. Having it available at work has saved my butt a couple times. It's not every day workflow use but it has its occasions.

    I'll keep an eye here for more progress on the photoshop integration!
  • Art-Machine
    Options
    Offline / Send Message
    Lol what gives, All this cool discussion while im gone and when i come back everything stops! :P

    Some cool programmer out there still trying for a solution inside PS?
  • HarlequiN
    Options
    Offline / Send Message
    HarlequiN polycounter lvl 18
    Mmmm, I've pondered it a little, but haven't had time to do any more than that.

    Scripting wise I think it would go down something like working out the maximum angle before the Red and green fully swap or invert (I'm guessing 90 degrees), then taking the users chosen rotation and blending/inverting the channels by a percentage based on the percentage the rotation angle is of the maximum. If the required angle is past the maximum (90 degrees), and onto the next swap/invert blend (180 degrees) then it ets a little more complicated, but I think it could be done.

    If I ever get time I'll look into it more, but don't hold your breath, it'll b a while if it can be done at all. A Plugin using similar code to Ryans would be the better option, but I don't do grown up code :)
  • pixaeiro
    Options
    Offline / Send Message
    pixaeiro polycounter lvl 8
    Hello. 
    A few weeks ago we introduced a new Normal image mode in PixaFlux, and fixed almost all nodes to understand the concept of normals:
    The Transform node rotates the normals of the normal images.
    This tutorial shows how to use this new feature in PixaFlux:
    https://youtu.be/_iRX2g5YgrM
    Please let me know if you have any suggestions about normal images.
    Thank you
  • mirohristov
    Options
    Offline / Send Message
    A few years late but for anyone seeing this, I've put together this Normal Map rotation tool using three.js:
    Normal map rotation tool (online)


Sign In or Register to comment.