Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
specular shader; issues
Topic Started: Mar 31 2009, 04:46 AM (517 Views)
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
So its time to use this shader. Per pixel of course.
But I keep getting some crazy (and wrong) lighting when I use it. The map has highlights all over the place and they are bloody huge.

No idea what I'm doing wrong, but it could be hard for you guys to help, as I dont want to give away my model or normal map.

Taken from the tech demo:
Code:
 

LoadTexture("gfx/map3_normalmap.jpg",202)


// Set up the shader effect, which implements normal mapped (or per-vertex
// as fallback technique) specular lighting, for all materials that need to
// use it

AddInverseTangentSpaceMatrices();

// The second texture stage has to hold the height map of the material
SetMaterialStageTexture(4,1,202);



// The third and fourth stage have to hold the cubic vector
// normalization map, which always had the index 1009
SetMaterialStageTexture(4,2,1009);
SetMaterialStageTexture(4,3,1009);
// Load the shader effect and set up which light source is to be used
// for it
LoadMaterialEffect(4,"effects/NormalMappedSpecularLighting.ufx");

SetMaterialEffectLightSource(4,light_point);



Does anyone know what might cause a problem?


그대를 사랑해


Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
lol

Spoiler: click to toggle


You never know. It may be your last line that's causing it.
Edited by skarik, Mar 31 2009, 05:08 AM.
Blog|EHS
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Posted Image

LOL

I tried. :P

The left is without the shader, right side is with.

The little thingy on the wall is a light. Yes the light is there, I checked.
(this is inside a box btw)

As you can clearly see, because this picture is that clear, the secular highlights are in strange places.

And I added the code in your spoiler, it didn't help.
그대를 사랑해


Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Woah.
What the.

fail.

I was loading the wrong normal map.

LOL

I got it now.

그대를 사랑해


Offline Profile Quote Post Goto Top
 
Gandalf20000
Member Avatar
Geek
[ *  *  *  *  *  * ]
ashrat3000
Mar 31 2009, 08:49 AM
Woah.
What the.

fail.

I was loading the wrong normal map.

LOL

I got it now.

Gimme a 'D'! Gimme a 'U'! Gimme a 'H'! What's that spell? DUH! :P

We've all had our share of "duh" moments, I guess this is yours. :D
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Hmm.

If my texture is wrapped on my model, so it repeats like 20 times, can I use a normal map of the texture and repeat that as well?
Or do I have to unwrap it. Because I'm not getting the correct results.

I tried unwrapping it as well, and I think the nomals are facing the wrong way. Like 90o off or something. Tried to change it in photoshop, and it kinda worked.
Has anyone actually gotten a proper normal map from 3ds max into u3d?

Oh, and how do I change the color/lower the intensity of the highlight?

그대를 사랑해


Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
ashrat3000
Apr 1 2009, 03:43 AM
Hmm.

If my texture is wrapped on my model, so it repeats like 20 times, can I use a normal map of the texture and repeat that as well?
Or do I have to unwrap it. Because I'm not getting the correct results.

No.


Unwrap it. Also, realize that normal mapping does have a limit on some PC's for some reason. Try to keep UV's in the range of -8 to 8, and make sure THEY DO NOT OVERLAP ANYWHERE. Those texture coordinates MUST BE UNIQUE FOR EVERY TRIANGLE TO BE DRAWN.

Quote:
 
Oh, and how do I change the color/lower the intensity of the highlight?

Edit the shader. It's pretty obvious what part to change. Well, I think it is.
Blog|EHS
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Quote:
 
Unwrap it. Also, realize that normal mapping does have a limit on some PC's for some reason. Try to keep UV's in the range of -8 to 8, and make sure THEY DO NOT OVERLAP ANYWHERE. Those texture coordinates MUST BE UNIQUE FOR EVERY TRIANGLE TO BE DRAWN.
Uh, how do I check the uv coordinates?


Quote:
 

Edit the shader. It's pretty obvious what part to change. Well, I think it is.
Yes, for you maybe :P .
But not me.


그대를 사랑해


Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Check the UV coordinates in 3dsmax UV editor, of course. It displays the coordinates under the cursor. If you want, you can even go into W coordinates, for only 399.99!

Okay, just stay in UV. I don't think U3D ever will look at W unless a shader says so.

Oh, and I think it's pretty obvious.
Code:
 
// Take the product of the material color with the attenuation and the dot product
// and add the ambient lighting color...
mad_x2 r4.rgb, v0, r4, c0
// ...and square the specular lighting factor again (^4)
+mul r1.a, r1.a, r1.a
// Square the specular lighting factor again (^8)
mul r1.a, r1.a, r1.a
// Square the specular lighting factor again (^16)
mul r1.a, r1, r1




Blog|EHS
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
See, thats what I was looking at, but comment out one of those mul lines makes the highlight bigger.
For some reason.




oh. If I unwrap it, I need an image 4096x4096 to show just a little bit of detail. Not good.
Oh, and why is the highlight such bad quality? Looks like a very poorly compressed jpg image.
그대를 사랑해


Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
To fix the highlight, either blur your normal map a tiny bit or change the filtering of the stages U3D uses.


Don't comment out anything.
Just change this line to change the strength:
Code:
 
// Take the product of the material color with the attenuation and the dot product
// and add the ambient lighting color...
mad_x2 r4.rgb, v0, r4, c0
Blog|EHS
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply