Home Technical Talk

UDK LitSpheres, world space and camera space

dralex789
polycounter lvl 7
Offline / Send Message
dralex789 polycounter lvl 7
Hey folks, so I've been wanting to do this for a while but I finally got lit spheres working in the UDK. Below are 3 screens (including the shader).

I also figured out a hacked way to get the lit spheres working in world space instead of camera space (the material has a switch built in). It involves stretching the image so it wont look nearly as nice as the camera space, but it could be used to apply "gradient lighting" (new term, just made it up) to a scene instead of a costly high memory budget cube map. Think a tiny image that helps tell your shader colors to add to the top or bottom of the image :)

Credits: For the vector rotation code go check out CommanderKeen's work over here: http://www.polycount.com/forum/showthread.php?t=97779

The model and normal map belong to Epic, and the lit spheres I use to test were from this post by Peppi here: http://www.polycount.com/forum/showthread.php?t=68125

Hope this is useful to someone! Cool for environment unify work, or for testing details on your model!

2qnzh.jpg

6qr0G.jpg

dv5CT.jpg

Replies

  • Ged
    Offline / Send Message
    Ged interpolator
    very nice, is there a visual difference between camera space and world space?
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 7
    Camera space is like ZBrush spheres, World Space is more like a cubemap.
  • Joopson
    Offline / Send Message
    Joopson Polycount Sponsor
    Looks awesome! Forgive my lack of understanding, but where precisely does the lit-sphere go in the material?
  • Gestalt
    Really cool! I actually wanted to do something like this but I never got around to it.

    I don't like custom nodes and inverse trig functions so I came up with an alternative method that seems to work. If anyone's interested here's the setup:

    QCjUQ.jpg?1

    I should probably go through it and double check the semantics of things, but it looked right and I'm impatient :P

    Edit: the blue color input would be where you'd have your normal map.

    Here's an example of it on the rock:

    U7l31.jpg?1
  • dralex789
    Offline / Send Message
    dralex789 polycounter lvl 7
    @Gestalt: Thats pretty cool man! Your method is actually identical to mine :) The +1/2 is what the ConstantBiasScale node does.

    @Joopson: The litsphere would go in both the texture slots at the far left of the chain (the Tex2Dparameters).

    @Ged: The camera space one always applies the lighting based off of your camera, so if you looked at the top and the bottom, the mesh would be lit in 2 completely different ways. The world space one does suffer from quality, but stays constant independant of your model.
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 14
    One of the coders back at 38 helped us come up with this exact same series of nodes. He called it 'sphere mapping' though. Dunno if that's some official technie-graphics-programmer term or not. Pretty cool stuff though!
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 14
    btw those chrome ones are REALLY cool looking!
  • dralex789
    Offline / Send Message
    dralex789 polycounter lvl 7
    One of the coders back at 38 helped us come up with this exact same series of nodes. He called it 'sphere mapping' though. Dunno if that's some official technie-graphics-programmer term or not. Pretty cool stuff though!

    It is :) Check out it's uses here: http://www.ozone3d.net/tutorials/glsl_texturing_p04.php
  • Gestalt
    Ok that makes more sense! I wasn't quite sure what your approach was with the custom nodes in there, but it looks like the CommanderKeen stuff is for the world space. Very cool and useful.
  • dralex789
    Offline / Send Message
    dralex789 polycounter lvl 7
    Gestalt wrote: »
    Ok that makes more sense! I wasn't quite sure what your approach was with the custom nodes in there, but it looks like the CommanderKeen stuff is for the world space. Very cool and useful.

    The custom node at the top was just multiplying the UV's by 1,-1 (idk why I used a custom node heh)

    The custom node using Keen's work was used to rotate the normal vector used by 180 so that the gradient created by projecting the image across the normals faces the right direction :)
  • Gestalt
    Just out of curiosity what are you going for with the world space version? The texture doesn't give you a sphere, just a hemisphere. I set up a version that reuses the same hemisphere on the back as the front and just maps the color to the directions, so not environment reflections but still cool.

    You can do that pretty much the same way the first part is done but instead mask R and B and switch the transform to world. As you've said there's stretching, but if that's what you're going for this way doesn't require the custom nodes and trig. I don't think that's what you're going for though haha.

    I'm guessing you're treating the hemisphere like a chrome sphere, so something that describes the light all the way around the sphere from lightsources infinitely far away (like the very edges of the hemisphere would describe a light source from directly behind). That'd make more sense if you're trying to do environment mapping, but yeah there'd be a lot of stretching.
  • arrangemonk
    Offline / Send Message
    arrangemonk polycounter lvl 12
    would be interesting to have a 2:1 texture with 2 spheres for covering the backside too, that would emulate a complete cubemap and would only take a third of the texture space
  • JamesWild
    Offline / Send Message
    JamesWild polycounter lvl 8
    That'd be a dual parabolic map.
  • Norman3D
    Offline / Send Message
    Norman3D polygon
    One of the coders back at 38 helped us come up with this exact same series of nodes. He called it 'sphere mapping' though. Dunno if that's some official technie-graphics-programmer term or not. Pretty cool stuff though!

    Yep, the technical term is Spherical Environment Mapping. More info here:
    http://wiki.polycount.com/SphericalEnvironmentMap
Sign In or Register to comment.