Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Normal Map Shader - Help!

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Nov 2012 18:06
All I need is a simple normal mapping shader which only needs a diffuse and a normal map texture.

Evolved's normal map shaders aren't what I need because:

1) They have specular, which I don't want.
2) They need some other special volume texture for normalization

I've found some code which does exactly what I want, but I can't for the love of anything get a light to work with it. Any help is greatly appreciated!



TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Nov 2012 19:39
Try the attached complete demo. The code might need cleaning up here and there. If it's what you want I can tidy it up a bit.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 01:36
Thanks GG, that helped a lot!

I gave your shader a spin and I'm starting to wonder if it's really what I want or not... Here's what it looks like:

http://0xff.avxc.net/stuff/screeny1.png
http://0xff.avxc.net/stuff/screeny2.png

And this is what I want it to look like : http://gameachiever.com/images/starcraft-2/exploration/challenges/infestation/2.jpg

Would you have any suggestions on how to achieve sand that looks like that?

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2012 02:00 Edited at: 3rd Nov 2012 02:22
It helps to compare them side by side:



It looks like a combination of three things:

1. the light colour is different

2. the light is at a shallower angle in the left hand image (2a) or the normal map is sharper (2b)

3. the sand in the left hand image has more detail - either a higher resolution image was used or a blended version of two images at different scales (as in Advanced Terrain but applied to normal maps as well as to the main texture).

Issue 1 is easy to fix, as is 2a. Issues 2b and 3 can be fixed in the shader by adding extra tweaks and or textures plus a bit of blending code for issue 3.

If you're interested I can knock up a demo for issues 2b and 3.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 02:22 Edited at: 3rd Nov 2012 02:23
GG, I would greatly appreciate any help I can get. I'm kind of under some time pressure, I need to get a working demo out in just 9 days for a real-life convention I'm going to, and there's so much other stuff I need to attend to in the game.

EDIT : If you need media/code/whatever for your demo, just ask.

Cheers,

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2012 02:33
Quote: "If you need media/code/whatever for your demo, just ask."


The sand texture and normal map would be helpful. I can probably concoct the rest myself if necessary. I'll look at this over the weekend - it's half past midnight here so I won't risk trying to do anything sensible now.

There is one other possibility that would be much harder to fix - it's possible they've used some kind of self-shadowing on the ripples in the sand so that if the light direction is at a shallow enough angle the ripples actually cast shadows on areas that are angled towards the light. That would be overkill in my opinion but it would extra realism to the scene.

Anyway, let's try simple things first.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 02:48 Edited at: 3rd Nov 2012 02:49
Upon looking at the screen shot again, I'm beginning to wonder whether they are pre-baked shadows? If that were the case though, the unit's shadows wouldn't be merging with the terrain's shadows, but a pre-baked solution might be preferable.

In any case, they still need to be normal mapped.

The textures are attached, thanks for the help!

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2012 15:11
Quote: "Upon looking at the screen shot again, I'm beginning to wonder whether they are pre-baked shadows?"


Actually your texture looks like it has diffuse pre-baked into it and I wonder whether the normal map was calculated from that rather than from a heightmap.

I've played around a bit with your images and my shader. I suspect part of your problem is that the normal map corresponds to a very flat surface. One consequence of that is there's a loss of available precision since your normal map contains relatively few different values. I tried creating a second, sharper, normal map using your initial texture but that still isn't quite right.

Have a look at the attached demo. The shader now contains an additional "flatness" constant which enables you to flatten or sharpen the bump effect - that's "ggbump4f.fx". I've also included a sample screenshot and a revised normal map.

You can improve things a bit by experimenting with the values (you could also try increasing the light colour and reducing the ambient - not directly adjustable from the demo yet) but I suspect your best bet is to think carefully how you created your initial normal map.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 17:05 Edited at: 3rd Nov 2012 17:05
Thanks a ton GG, I think the problem is the normal map for the sand texture. The other models look fantastic:



TheComet

- The codebase
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 17:08 Edited at: 3rd Nov 2012 17:10
I have another, unrelated problem with your heat haze shader.

The shader:



Why is it when I try to darken the overall colour, these horrible seams appear on the edge of every polygon?



TheComet

- The codebase
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 17:11
The model is attached.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2012 20:19
Quote: "Why is it when I try to darken the overall colour, these horrible seams appear on the edge of every polygon?"


I have no idea at the moment. How are you darkening the overall colour? And the overall colour of what exactly?

I'll see if I can locate the original demo. Must be on my other machine.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 20:21
In the "tweaks" section of the shader file I change the variable "colour" to something darker than {1.0f, 1.0f, 1.0f, 1.0f}:



Whenever I do that, the seams appear for some reason... It doesn't make sense to me though, you're computing the output colour correctly on this line:



Also, nice to see someone spell that word correctly for once.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2012 21:45
Could you provide a complete small demo which shows the effect (I don't need the exe of course). It'll help me identify the cause and save me a lot of blind experimenting while trying to reproduce the symptoms.

Can you recall exactly which version of the shader that was? Several versions were discussed on the original thread thread. Was it my original "HeatHaze3.fx" file or one of the later revisions?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2012 23:08
Sure, demo attached.

Sorry for the messy code, I just copied it across from my project in a hurry.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 00:59
Thanks. Just downloaded your demo and checked it works. I can also see the symptoms you've described. I'll look at it more closely tomorrow.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Nov 2012 01:29
Fantastic.

Quote: "Can you recall exactly which version of the shader that was? Several versions were discussed on the original thread thread. Was it my original "HeatHaze3.fx" file or one of the later revisions?"


I believe it was the latest version, but it was quite a while ago, so I'm not entirely sure.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 13:21
I'm still puzzled by this.

I've had various ideas but none seem to be relevant. I'm now trying to reduce your code to the bare essentials - it seems to contain a lot of irrelevant code (as far as the present problem is concerned).

I've deleted some stuff but I'm a bit baffled by your distortion function. If I remove it then the program fails completely - but if I move it out of the main loop then everything seems to run as before. Is it possible to prune that function down to the absolute minimum to allow the effect to be shown? It'll take me a while to work out what it's doing - and I'd rather spend my time isolating the problem rather than struggling to understand your code.

At the moment I'm not sure which part of your project is causing the problem.

Incidentally, you get the opposite problem if you brighten the colour beyond 1.00 - you get bright lines instead of darker ones.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Nov 2012 14:22
Of course, sorry about the mess. I was in a hurry when I wrote that.

This is the updated code, it should be much easier to understand:



Camera 0 is rendered to an image, and that image is textured to a plain object which is positioned in front of camera 1.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 15:18 Edited at: 4th Nov 2012 15:39
Thanks! That makes it much easier to focus on the essentials.

It is a rather baffling problem. I've already ruled out a few things:

1. mipmapping - I thought automatic mipmapping might be triggering the wrong mipmap (apparently not)
2. normal map - odd feature of force-field normal map perhaps (no, any normal map has same effect)
3. force-field object itself (no, DBPro spheres have the same problem)
4. all sorts of things which you've now removed

I'm sure I've overlooked something very simple, but this new demo should help enormously.

Edit It's beginning to look like a z-fighting issue - but at the moment I can't see what's causing the conflict.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 16:13
I suspect you'd got your camera rendering order a bit muddled and that may have caused some z-fighting between your screen quad and one that DBPro uses behind the scenes. Anyway, working from that assumption I've separated your two camera renders into two explicit steps and removed the distortion object and the problem has disappeared. I've modified the camera numbering and positions but you should be able to swap those back again.

I realise you probably need to add the distortion object back in for other reasons but again I think you need to think carefully about what does and what doesn't need to be rendered at each step. You may need to use a third camera to achieve what you want.

Anyway, try this and if it works we can proceed to the next step.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Nov 2012 17:00
Hi GG,

Yes, that fixed it on this end.

It is now however 2 times slower because you're refreshing twice every loop, I hope that this won't be the case with the final version.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 18:56
Let's get the whole thing working - then make it faster.

This version includes a simple distortion object for an additional final render. If that's the sort of overall set-up you had in mind perhaps you could replace my distortion object with yours and see if it works as you require. Then we can try to speed it up.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Nov 2012 19:30
That's exactly what I want to achieve.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2012 20:58
Good.

I'll tinker with the code to see if I can speed it up then leave the rest to you.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Nov 2012 21:05
Alright, looking forward to it! And thanks again GG.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2012 12:10
Try this. The main change is that I've now used set object mask to combine the three renders into a single sync. I'm not sure what the overall significance of this is on performance but it certainly simplifies the code and the main loop does seem to run faster. It might be possible to reduce this still further to just two cameras but I'm not convinced.

Login to post a reply

Server time is: 2026-07-10 09:46:55
Your offset time is: 2026-07-10 09:46:55