Home Unreal Engine

Normal shader

polycounter lvl 10
Offline / Send Message
tuxmask75 polycounter lvl 10
Hey guys, Ive been working on creating a model based normal effect shader,,, (and Marjory failing)
on setting up 3colors (5 total RGB and negative RGB colors so that that they are located at the same area of the model related to the camera view, so if the camera rotates than the colors also always face the same way.
( i didn't attempt the negative colors in the shader yet)


This is what i have,,,
capture3qhg.png
Uploaded with ImageShack.us

and heres a sort of visual representation of what I'm trying to accomplish
using lights in 3d studio max to pull off the Goal effect.

There is an article on how to set up the lights and colors here:
http://udkc.info/index.php?title=Tutorials:Normal_Mapping_for_Games
captureiwk.png
Uploaded with ImageShack.us

Replies

  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    I believe if you take a 0,0,1 scalar and put it into a vector transform, tangent to view, it will do that. From my basic test the blue is negative though.
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Gestalt wrote: »
    I believe if you take a 0,0,1 scalar and put it into a vector transform, tangent to view, it will do that. From my basic test the blue is negative though.

    Hnmm a better result than what i had above
    but still not quite there yet.
    capturemtj.png
    Uploaded with ImageShack.us
  • cw
    Options
    Offline / Send Message
    cw polycounter lvl 17
    are you accounting for gamma correction?
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    cw wrote: »
    are you accounting for gamma correction?
    would that need to be done ?
    Sorry, silly question as im still new to udk and shaders.
  • cw
    Options
    Offline / Send Message
    cw polycounter lvl 17
    not sure hmm, let me have a quick noodle
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    From what I understand, what you see in the display is rendered with gamma correction at the end, but the data you're using there should be linear. When you go to use your normal values everything should be ok, even though when you plug it into the diffuse the falloff seems off.

    When you set up shaders in UDK everything is pretty much going to be assumed to be in linear space (when you import a diffuse texture for example there's an option checked by default that brings it into linear space).

    Edit: Just to make sure what I said is clear. The gamma correction is applied to the render, the data itself should be linear and should work fine; it's the fact that you are visualizing the normal values through the rendered diffuse that makes the falloff seem off. Also -1 to 1 is the range you want, when you import a normal map as a normal map it is multiplied by 2 and subtracted by 1 (so that it is -1 to 1).
  • cw
    Options
    Offline / Send Message
    cw polycounter lvl 17
    no its not gamma, but you are showing -1 to 1 ranges I think - It might be best to use a custom node to figure out the maths you need. Good luck!
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    thank for the help guys,,,, i dont think i can pull it off.
  • cw
    Options
    Offline / Send Message
    cw polycounter lvl 17
    I bet you can pull it off! If not solo we can team up, amirite?

    For this example, it looks like you want to display a tangent space looking effect on your material, am I right? In this case you will want 0-1 for r and g channel and 0.5-1 for the b channel in order for your sphere in game to resemble the tangent space looking example you posted.

    @Gestalt - do you concur with my assertion? We must interpret world space as the tangent space, and convert world space normals of the object in UDK to mock-TS values.

    I am not familiar with the custom nodes in UDK, but there may be a neat way to do this - oh hang on I just did something!

    shadery.jpg

    It's still not quite right, but maybe you can figure out what to do next. :)
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    UDK is in tangent space by default. If you want normals based on the view you can do that with the vector transform node (as was done previously). If you want values in the range 0 to 1 instead of -1 to 1, add 1 divide by 2. That should give you something that looks more like the example (minus the fact that some may be flipped differently).

    Just a note of warning though, normal maps are meant to be in -1 to 1 when they're actually used because the values represent vectors. The shading is usually done from a dot product of vectors so if you plan to use your normal info for a custom shader you probably don't want to change the range. For visualization purposes 0 to 1 is fine but I'm assuming you would want them to be -1 to 1 for actual application. If you want to be able to see the negative values, plug into an abs value node first.
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Gestalt wrote: »
    UDK is in tangent space by default. If you want normals based on the view you can do that with the vector transform node (as was done previously). If you want values in the range 0 to 1 instead of -1 to 1, add 1 divide by 2. That should give you something that looks more like the example (minus the fact that some may be flipped differently).

    Just a note of warning though, normal maps are meant to be in -1 to 1 when they're actually used because the values represent vectors. The shading is usually done from a dot product of vectors so if you plan to use your normal info for a custom shader you probably don't want to change the range. For visualization purposes 0 to 1 is fine but I'm assuming you would want them to be -1 to 1 for actual application. If you want to be able to see the negative values, plug into an abs value node first.


    hnmm.. ya I'm looking to get them -1 to 1 for application, the end goal would be to use them together with a distortion map to create better reflections on mesh.
    I've constructed a few nod webs based on your description to see if i can break this shit wide open,
    came across some interesting results , just not what I'm looking for.
    perhaps i didn't quite do it correct to your explanation.
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    Well if you need any help/clarification just ask! If you explain what the result you'd like is and how you've been going about it, I or someone else may be able to help more.
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Gestalt wrote: »
    Well if you need any help/clarification just ask! If you explain what the result you'd like is and how you've been going about it, I or someone else may be able to help more.

    yeah that'd be great !
    I have some time to attempt the reflection refraction shader idea today,
    will get back with some results.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Custom Node

    return refract(E, N, IOR);

    E = Camera Vector (invert or transform this pending on needs).
    N = Normal (same as above).
    IOR = Index of Refraction (plug in a constant check up a IOR table).

    Stick this either in the Distortion slot or use a Cubemap.

    Note, you cannot use a 2DSceneTexture since UDK reads them as 2D information from the screen, so refraction wouldn't work for that, and masking RG will only create black holes on your mesh.

    Next easiest solution is to stick a Normal Map sphere in SphereMap setup, and have that act out as your Refraction. It won't be accurate because it will always be facing towards the camera and you won't have access directly to changing the color values and strength, but hey then again, what is accurate in games...
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    hnmm ,, what about box projected cube mapping ? if we had that than this other stuff wouldn't be necessary,
    http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/

    Anyone interested in porting it over to UDK ? The reflections look so nice...
    The above link Even has some code demonstrated there.

    float3 dir = WrlPos - CamPos;
    float3 rdir = reflect(dir, WrlTexNorm);

    //BPCEM
    float3 nrdir = normalize(rdir);
    float3 rbmax = (EnvBoxMax - WrlPos)/nrdir;
    float3 rbmin = (EnvBoxMin - WrlPos)/nrdir;

    float3 rbminmax = (nrdir>0.0f)?rbmax:rbmin;
    float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);

    float3 posonbox = WrlPos + nrdir*fa;
    rdir = posonbox - EnvBoxPos;
    //PBCEM end

    float3 env = texCUBE(envMap, rdir);
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Isn't that a common Cubemap method, unless I missed something based upon the nVidia Reflection?

    Here is how far I got before my brain exploded...anyone wanna pick it up?

    sdsdup.jpg
Sign In or Register to comment.