Normal Map Help

Started by
7 comments, last by Super Llama 15 years, 5 months ago
Ok basically, I want to know how to display a normal map without HLSL that works for several lights. How is this done? It needs to be able to: calculate for more than one light blend with the regular texture render several normal mapped objects at once A simple explanation would be greatly appreciated. [smile] EDIT: Oh and I'm using DirectX 9 with Unmanaged C++
It's a sofa! It's a camel! No! It's Super Llama!
Advertisement
Do you have normal mapping working for a single light? Extending it from there isn't very hard. You basically have two approaches:

-Multi-pass lighting. For each light source, draw the whole model using additive blending to sum the contribution of each light source. Pro's: simple to implement, keeps shader instruction count low. Con's: bad performance due to the need to draw a model multiple times, and also due to extra bandwidth needed for blending.
-Single-pass lighting. Sum the contributions of multiple light sources in the shader by looping through them. Pro's: better performance. Con's: more complex to implement in both the shader and application code.

Well I'm not using .fx files, so my "vertex shaders" (they're actually just code like everything else) are basically hard-coded using functions like:

d3ddev->SetTexture
d3ddev->SetMaterial
d3ddev->SetTextureState

etc.

I sort of have it working for one light - it draws the normal map but it doesn't change when the light source changes. I'm not sure how to link the two.

I'm thinking about using single-pass because it seems like it would be better to draw it once than to draw it 5 times with alpha blending.

EDIT:

Is there a way to use HLSL without .fx files? I hate fx files... I always use my own file types, with the exception of bmp and jpg and png

or is fx compiled like source code, so it won't be there in the finished project?

[Edited by - Super Llama on November 13, 2008 10:06:23 AM]
It's a sofa! It's a camel! No! It's Super Llama!
Oh I'm sorry, I read that as "with HLSL".

Well I don't think there's any way to do single-pass with fixed-function...but I don't know for sure since I haven't used that stuff in years. You could definitely do multi-pass though.

As for .fx files...yes you can use vertex and pixel shaders without the Effects framework. There's even a sample in the SDK that demonstrates it. However I'd strongly recommend using Effects...they have a lot of great functionality that you'd probably just end up implementing yourself.

Also if you'd like, .fx files can be pre-compiled in advance using fxc.exe. You can even configure Visual Studio to do this for you as a post-build step, if you'd like. Or they can be compiled at runtime as well.
So are they compiled into the exe, or as compiled forms of fx files?

HLSL is looking a little more appealing now :P

The thing is, I'm trying to write a moddable game renderer/engine, and I'd like to implement my own file types (it already uses a custom mesh format) that people can write. Is there a way to use a different type of file in place of an fx file, and load them into an ID3DXEffect with code?
It's a sofa! It's a camel! No! It's Super Llama!
Quote:Original post by Super Llama
So are they compiled into the exe, or as compiled forms of fx files?

HLSL is looking a little more appealing now :P

The thing is, I'm trying to write a moddable game renderer/engine, and I'd like to implement my own file types (it already uses a custom mesh format) that people can write. Is there a way to use a different type of file in place of an fx file, and load them into an ID3DXEffect with code?


If you compile them with fxc, they get output as another file with whatever extension you'd like.

You can use whatever file type you'd like for compiling effects in your code...you can simply use a string of text if you'd like and D3DX will compile it. It can also compile effects from resources, if you want them embedded in the EXE.
That's strange, how can it compile a string? Is it just converting it to binary? I think a coded loader for a custom effect type would work better for me, since I already did that with models. I load the file into a storage class, then a function will convert it into a ModelRender class which, when created, generates a VertexBuffer from the storage class and can render it on command. I'd like to do something similar with effects, maybe having some preset variables (much like materials on a model) that can be tweaked to generate a vertex shader. I'll have a look at that NoEffect sample :)
It's a sofa! It's a camel! No! It's Super Llama!
The string would just contain all of your HLSL source code, in text form. So if you can construct a string containing HLSL source, you can use whatever file format you'd like.

A lot of engines will generate their shaders by assembling fragments of HLSL source based on a script file or a material file...that sounds like what you want to do. You might want to check out this article.
Can D3DX compile a shader from a variable? Like, not from a file? If so that would be perfect; I could use the fragment approach in that article and have a simple mechanism to combine the fragments depending on the variables given, then generate the effect file from a variable.

btw, thanks for all the help [smile]
It's a sofa! It's a camel! No! It's Super Llama!

This topic is closed to new replies.

Advertisement