Home Unreal Engine

Blended normals in UDK?

polycounter lvl 18
Offline / Send Message
kodde polycounter lvl 18
Hey guys.

I wanted to try to get blended normals in an UDK material and I don't know how to approach this or if it's even possible?

I know how blended normals work in theory and I've created this with other software, just not with udk... yet. In very few words, you need to do two diffuse calculations, one with normal map other just geometry normals, then you lerp between these with different weight values per channel.

First of all, is it possible to have to diffuse calculations in an UDK material? Is there some form of mult-material feature where you can combine two materials?


Thanks!

Replies

  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    Just use the Custom input slot, where you can do all your calculations from scratch.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Xoliul wrote: »
    Just use the Custom input slot, where you can do all your calculations from scratch.

    Ooo... thanks. Going to look into this.
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    I looked through the drakes fortune stuff and I don't know if you'd need to use the custom material slot. I'd try just using a lerp to blend between your normalmap node and a worldNormal node and plug that into the normalmap slot.

    http://udn.epicgames.com/Three/MaterialsCompendium.html#WorldNormal
  • Jonathan
    Options
    Offline / Send Message
    I'm not sure if we're on the same page, but if you're wanting to blend between a tangent space normal map and your vertex normals, just lerp between the normal map and a constant vector of 0.5, 0.5, 1 (in some engines) or in UDK it's 0,0,1 (thanks for the info, Jordan).
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    It won't let me use a worldNormal node in a pixelshader input.

    Either way, I'm quite certain that you have to do it with two diffuse calculations, otherwise you won't get the RGB channels to differ and get the desired effect. I mean, no matter how much you modify the normal input of one diffuse calculations you will only ever get B/W diffuse output right?

    I think I need to go with the approach Xoliul suggested. I just need to figure out what node gives me the geometry normals. Either that or use the Custom node and figure out how to write custom shader code for UDK.
  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    kodde wrote: »
    It won't let me use a worldNormal node in a pixelshader input.

    I think I need to go with the approach Xoliul suggested. I just need to figure out what node gives me the geometry normals. Either that or use the Custom node and figure out how to write custom shader code for UDK.

    Kodde, you're a bit confused here. Unreal's normals work in tangent space by default. That means whatever you input into the Normal slot, is transformed to world space behind the scenes before it is eventually applied in the diffuse calculations. I know this is kinda weird compared to how you're probably used to work, but it doesn't really limit you or anything.

    So as Jonathan says, if you want to access the geometry normals, you just use a constant vector of 0.5,0.5,1. Use a Transform node to transform it from tangent to world if you want. Just make sure your other vectors are in the same space before you start combining them.
    You don't need the WorldNormal node, that one's just for WorldPositionOffset input.

    If you use the custom input, you need to handle all your space for the vectors yourself, so that would be easier for you.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Ah thanks.

    Is it the CustomLighting or CustomLightingDiffuse I'm supposed to be using? Can't really seem to get either of these to work. Any secrets surrounding these?

    Right now I'm stuck on trying to reproduce Blinn-Phong diffuse shading using the CustomLighting/CustomLightingDiffuse as a first step.
  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    You use Customlighting. Make sure to set the material's lighting model to MLM_Custom or it does nothing.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Thanks Xoliul. Got the CustomLighting slot to produce some results now.

    Here's where I'm at now. At least I'm a bit closer but not there yet. I'm not at all certain of how to properly reproduce the phong shading since I'm not that experienced with the inner workings of the lighting calculations. But since the non-normal mapped and normal mapped solutions produce a different shade of neutral color I get the red shifted results.

    Oh and btw. Why is my 0.5 0.5 1.0 vector in the lower right part so pale? It's not at all close to your default normal color in say a normal map texture.

    wipblendednormals02.jpg
  • JordanW
    Options
    Offline / Send Message
    JordanW polycounter lvl 19
    0.5 0.5 1 should not be your "flat" normal, when normal maps get pulled onto a graphics card get get unpacked from "0 to 1" to "-1 to 1" so a flat normal in a material editor is actually 0,0,1

    Also you do not need to normalize your light vector it's already a normalized tangent space vector

    the way custom lighting should be used is like this if you're recreating basic diffuse.

    dot product of normal and light vector, constant clamped * Diffuse goes into custom ligthing, this handles any interactions with a direct light.

    your diffuse texture/material effects go into CustomLightingDiffuse, this handles your diffuse getting multiplied by any skylights or spherical harmonics.

    You should look at the package called malehead (I think) in udk, it shows an example of custom lighting and blended normals.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Aha, thanks Jordan.

    I couldn't find that malehead package you're referring to. Only a base material for Male Characters (i think) and lots of instanced materials.

    When using the MLM_Custom type material, does it get lit with anything else besides the CustomLighting slot? I tried to keep it basic just to create the diffuse lighting the way you described it. But it seems to get lit by some other source from above as well?

    Notice how my diffuse multiplier is at 0. It should be all black if that is the only light source right?

    wipblendednormals03.jpg
  • rebb
    Options
    Offline / Send Message
    rebb polycounter lvl 17
    I believe the CustomLightingDiffuse is used for when indirect light hits the mesh, the preview also shows this.

    If you break the connection to the CustomLightingDiffuse, it should be black.
  • rasmus
    Options
    Offline / Send Message
    This stuff is all really crucial interesting stuff that isn't really explained anywhere as far as I can tell - digging in and asking Jordan et al alot of questions on PC seems to be the way to go :) Adding the dot product of a light vector and the surface normals should give you a phong specular.

    There is basic skylight and SH bounceighting present at all times it seems - Jordan, is there anyway to control/turn this off on a material level? That way ambient light could be 100% controlled with CustomLightingDiffuse for those of us making more stylized stuff.

    Also Kodde, what exactly are you trying to achieve? :)
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Rasmus> I haven't had time to continue fiddeling with this UDK side project. I haven't given up on it though. Still want to get it right.

    I want to achieve similar results to the top row of images in this image:
    normalmapincreased.jpg
Sign In or Register to comment.