Normal Map Lighting - help

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Normal Map Lighting - help

Post by RyanN »

i've applied normal maps to a small test room with a detailed character inside, the room has a light source coming from the top yet the materials normal mappings only seem to light from the ambient setting. Why won't it light from the light source direction? the light source is being setup in a .scene file, is there a difference between using a .scene file and straight c++ code in the exe to initialise the light?

thanks in advance!
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

You probably haven't generated tangent vectors for your mesh. See the wiki here http://ogrewiki.digitalsentience.com/in ... umpMapping
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

tangent vectors have been generated using the latest exporter from Banania.
User avatar
semicolon
Halfling
Posts: 94
Joined: Sun Jul 04, 2004 4:42 pm
Location: Bangkok, Thailand
Contact:

Post by semicolon »

Hi all,

Is tangent vector and tangent edge the same? I don't know much about tangent edge but if I need to use normal map or bump map, I'll probably need to get around with this too.

Semicolon
"Nature is the mother of learning"
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

I'm not sure what a 'tangent edge' is :?

Did you check your log? There are a couple of possible things:

1. If it's additive shadows, OGRE has to partition up your material definition into ambient, per-light and decal sections. It's pretty good at this, but sometimes you have to give it a hint if you use multiple passes by being specific. We talk about this in the manual. If you used the materials which came with the OGRE demo it's not that.

2. I'm not sure what the .scene loader you're using is doing with the geometry. Normal mapping requires an 'object space light' position, which can be bound automatically (again, see the demos) but is derived based on the object origin. It's possible that the manipuation that your viewer is doing is throwing that off.

If in doubt, try a simple entity in the same scene with that material and see what it does, to derive whether it's material or geometry that's causing the problem.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

thanks for your help sinbad, i will test a few things and see what happens, however as a test peter seemed to get it working on a different scene but once we tried to 'copy' the technique across it didn't work and we can't figure out whats the difference between them. The problem seem to be that its not getting the lights world position; its basically a copy/paste of the 'advanced-material' code from the demos.

One other question: can the specular highlight be adjusted to have a smaller hightlight? what setting controls this function, is it the light source them selves or the shader code? also can current bumpmap shader support a black/white specular map to define the hightlight levels?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

It's the specular power function. This is represented as 'shininess' in the fixed function pipeline, in our specular normal mapping shaders we use a fixed power because we wanted the shaders to be compatible with ps_1_x, which does not support variable powers. If you use ps_2_0 or above you can use the pow() function to make it variable, otherwise just change these lines in the fragment program:

Code: Select all

	for (int i = 0; i < 3; ++i)
		specFactor *= specFactor;
Note that because the loop control variables are constant Cg expands that into a constant statement, it's not run like that on the GPU (and can't be in ps_1_x).
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

yes! awesome, finally got the normal maps to light, looking good 8),
only problem i have is can the normal map lighting be restricted to X amount of lights?

I guess that it would be a 'global' shininess for that particular shader, using a 'specular level' texture layer would proberly be better.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

only problem i have is can the normal map lighting be restricted to X amount of lights?
See the 'max_lights' pass option.
I guess that it would be a 'global' shininess for that particular shader, using a 'specular level' texture layer would proberly be better.
Commonly known as a 'gloss map', yes - all you need is a greyscale texture mapped with the same coordinates and modulate the specularity based on that.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

thanks sinbad, one other question which doesn't make much sense is that i have a scene that is using normal mapping perfectly fine however another scene very similar that has a flickering bug with the normal map layer depending on your position and view angle, whats up with that?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Make sure you don't combine fixed-function passes with vertex program based ones - most drivers I've seen result in bad depth fighting in that situation. All passes must be vertex programs or none - that's why there's the Example_Basic.cg programs.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

yep, it basically the same code throughout them and this one flickers for, it seems, no apparent reason.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

is there something wrong or is there something i need to do to see shader effects through a semi-transparent texture. Currently i have a plain non-shader, semi-transparent texture with a reflective texture combined to make a glass texture however when i look through the window any other texture that uses a shader doesn't show up, ie: just a plain colour on the mesh im looking at, any ideas?

also in regaurds to the 'limit amount of lights' thing, i tried it but it didn't seem to work, how is applied to the shader?

yet another question, how does the projective texture shader work? is the projected texture appiled to the mesh or the material thats applied to the object, how does it throw the texture/shadow? (the demos don't help too much on this effect so any help would be awesome!)
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

1. Use scene_blend <whatever> and depth_write off in your pass. This applies equally to shader materials

2. Limiting the number of lights only works if your pass iterates per light - please see the manual for details

3. It generates texture coordinates in the target object. The projection has to be linked with a frustum and is set on the texture unit, but only takes effect when you use that material when rendering a mesh.
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

thanks for the reply sinbad! One other thing i would like to add is that getting normal maps to work is really inconsistant, i've got the scene with the character working with normal maps, another scene with a house had normal maps applied yet they flickered depending on the angle i was looking but the normals did light from light source direction and another scene with only one normal map that does work but it won't light from the direction of light source.

The house scene was had to figure out but after cleaning out the material file of duplicated materials it stopped flickering however the normal map stopped lighting from the light source, what is going on? at least with the flickering it lit the normal map....... :roll:

3. is the fustrum the camera/spotlights view/spot cone? is the preojective texture shader only used for lights?, ie: Doom3 flashlight style or any light source with a detailed projection map. Could this shader be used for projected mesh shadows?, ie: HL2 objects or usually a masked texture had a projected shadow ie: OFP (the trees and shrubs). Peter could explain it better if don't understand what im going on about :wink:
User avatar
PeterNewman
Greenskin
Posts: 128
Joined: Mon Jun 21, 2004 2:34 am
Location: Victoria, Australia
Contact:

Post by PeterNewman »

Your saying I understand what your going on about? ;-)

I really have no idea what is happening with his models. It looks like he somehow has multiple materials applied to the same mesh, and depending on what angle you look at them, you get either the fixed-function material (plain textre) or a variant on the pixel shader material (sudden brightness changes etc).

I quickly checked his materials and it doesn't seem he ismixing fixed-function and shader passes. Ogre.log isnt reporting any errors about a material referrring to a program that isnt defined, and every pass has programs. (Is a vertex program alone enough to kick it into the other pipeline? From the examples, which work, I'd say yes.)

Unfortunately I haven't had time to take his scene and really dig in to it, I'm guessing from the sidelines here. Stupid deadlines. :cry:
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

dealines?!? damn it man, we need normal maps! :wink:
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

figured out the normal map; the exporter wasn't generating tangent vectors even though it said it was, once i generated them it worked! 8)
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Which exporter?
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

Banania's 0.15.1 version exporter for max, i selected 'generate trangent vectors' but with no luck, i had to manually use the 'ogrexmlconverter -t' to generate them, once i did that it worked.
User avatar
Banania
Gremlin
Posts: 150
Joined: Wed Oct 20, 2004 2:35 pm
Location: Paris, France
Contact:

Post by Banania »

strange. I'll check it. I am not sure anyone had really used it before though.

EDIT: should be working. I haven't tried but the command line seems to be generated just fine. Can you check your listener window ? The OgreXMLConverter command line is printed at the end.
Last edited by Banania on Wed Jan 19, 2005 11:20 pm, edited 1 time in total.
Banania
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

its an old version though isn't it?
User avatar
Banania
Gremlin
Posts: 150
Joined: Wed Oct 20, 2004 2:35 pm
Location: Paris, France
Contact:

Post by Banania »

RyanN wrote:its an old version though isn't it?
0.15.1 version ? yes, it is a bit old. but this should not cause this problem.
Banania
User avatar
RyanN
Halfling
Posts: 82
Joined: Thu Aug 19, 2004 6:41 am
Location: Victoria, Australia
Contact:

Post by RyanN »

hmmmm, sometimes i get the 'export material' box locked out even though theres materials on that object....while were on the subject :)
User avatar
Banania
Gremlin
Posts: 150
Joined: Wed Oct 20, 2004 2:35 pm
Location: Paris, France
Contact:

Post by Banania »

RyanN wrote:hmmmm, sometimes i get the 'export material' box locked out even though theres materials on that object....while were on the subject :)
I see what you mean.

Please, don't miss the EDIT I made on one of the previous post concerning tangents vectors.
Banania
Post Reply