Skip to main content
GameDev.net gamedev.net
🔒 Locked

[Effect, HLSL] Lightmapping

Started by benryves Aug 7, 2007 at 11:44 AM 4 replies 3.3k views
Original Post
benryves
benryves
I've written a short pixel shader that combines the diffuse and lightmap texture colour values with a simple multiplication. That works well. However, not all surfaces have a lightmap, and in those circumstances I'd need to multiply the diffuse texture colour by a constant instead. The effect has two texture parameters. I set the lightmap texture to null if there is no lightmap for the surface, which results in pitch-black surfaces where the tex2D function is returning zero. How can I detect if a texture parameter is set to null? Or is that the wrong idea entirely?
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
ViLiO
ViLiO
One way would be to use a small texture (say 1x1) which is the constant colour you want to multiply by in the absence of a lightmap.

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Zipster
Zipster
I second that, the standard approach would be to just plug in a default white texture. But just be careful with your sampler states and borders, since the default texture will likely be pretty small and you're going to be sampling on the edges a lot.
benryves
benryves
Thanks, I'll do that then. [smile]
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
generaleskimo
generaleskimo
However, there is a BIG problem with that idea. In that case, you are using up an extra texture sampling slot regardless of whether or not you are using a texture.

I recommend creating a second technique (so that you don't have to deal with any branching), which calls the same PS function, and adding a bool parameter to said PS function which tells whether or not a texture is present. This way, it remains very speedy, and you can decide whether or not there is a lightmap (or whether or not you want to USE that lightmap) inside the C++ code. This keeps it speedy, while relatively simple.
===========================";" is the best key ever; you can use it to end lines when you are too lazy to use ENTER;
Zipster
Zipster
Quote:
Original post by generaleskimo
However, there is a BIG problem with that idea. In that case, you are using up an extra texture sampling slot regardless of whether or not you are using a texture.

I recommend creating a second technique (so that you don't have to deal with any branching), which calls the same PS function, and adding a bool parameter to said PS function which tells whether or not a texture is present. This way, it remains very speedy, and you can decide whether or not there is a lightmap (or whether or not you want to USE that lightmap) inside the C++ code. This keeps it speedy, while relatively simple.

That's another approach. The only reason I didn't mention it was because it's a bit more work than just setting a white texture. It requires an additional code path for every shader that has a toggle-able lightmap, and you have to batch your geometry by primitives that do and don't have lightmaps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.