Normalmapping (in development)
Posted By: MaxF
Normalmapping (in development) - 03/13/07 13:47
Hi
Is this coming out soon, I've tried 2 shaders from the forum and all I get is a black (very dark) model.
In this day and age it should be already a basic thing and specially for people like me who can't work out what I'm doing wrong
Posted By: Mondivirtuali
Re: Normalmapping (in development) - 03/13/07 13:58
Agree...a normal map template would be an excellent and very useful tool
Posted By: jcl
Re: Normalmapping (in development) - 03/13/07 14:13
Well, you don't need to wait for the templates, normalmapping is simple:
Code:
MATERIAL mtl_bump
{
//Normal Map must be on Skin2
effect=
"
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
float4 vecSunDir;
float4 vecColor;
texture entSkin1; // texture
texture entSkin2; // normal map
sampler sBaseTex = sampler_state { Texture = <entSkin1>; };
sampler sBump = sampler_state { Texture = <entSkin2>; };
struct out_bump
{
float4 Pos: POSITION;
float Fog: FOG;
float4 Color: COLOR;
float2 Tex: TEXCOORD0;
float2 Bump: TEXCOORD1;
float3 Normal: TEXCOORD2;
float3 Light: TEXCOORD3;
};
out_bump vs_bump(
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float2 inTex: TEXCOORD0,
in float3 inTangent: TEXCOORD2)
{
out_bump Out;
Out.Pos = DoTransform(inPos);
Out.Tex = inTex;
Out.Bump = inTex; // different coordinates required for ps_1_1
Out.Color = float4(1.0,1.0,1.0,1.0);
Out.Fog = DoFog(inPos);
CreateTangents(inNormal,inTangent);
float3 N = matTangent[2];
// transform the output values into the 0..1 range
Out.Light = DoTangent(-vecSunDir) * 0.5 + 0.5;
Out.Normal = DoTangent(N) * 0.5 + 0.5;
return Out;
}
float4 ps_bump(out_bump In): COLOR
{
float4 base = tex2D(sBaseTex,In.Tex);
float3 bumpNormal = tex2D(sBump,In.Bump);
float diffuse = saturate(dot(In.Light*2 - 1,bumpNormal*2 - 1));
#ifdef SHADOW
diffuse *= saturate(4 * dot(In.Light*2 - 1,In.Normal*2 - 1));
#endif
return base * diffuse;
}
technique bump
{
pass One
{
VertexShader = compile vs_1_1 vs_bump();
PixelShader = compile ps_1_1 ps_bump();
}
}
";
}
You need 6.50, the template6 file "default.fx" must be in the path, and the model must have a normal map on its second skin. You can also save the effect to an .fx file and assign it to the model directly in MED.
Posted By: DWilki
Re: Normalmapping (in development) - 03/13/07 14:38
Fantastic! Thanks for this.
Anyone know how to make this work with dynamic lights? Also, how would this blend the shadow map in with the effect?
Posted By: MaxF
Re: Normalmapping (in development) - 03/13/07 15:40
Hi JCL
Easy for a guy like you
![](/ubbthreads/images/graemlins/smile.gif)
Thanks for the code will play with it, so you must use templates!
Posted By: lostclimate
Re: Normalmapping (in development) - 03/13/07 16:01
whats hard about it? you store it in an fx file, make a material with effect="file.fx"; and make your second skin in the model a normal map
Posted By: MaxF
Re: Normalmapping (in development) - 03/13/07 18:52
I was talking about the shader code
Posted By: Mondivirtuali
Re: Normalmapping (in development) - 03/13/07 21:01
How to make an fx files?
Posted By: TWO
Re: Normalmapping (in development) - 03/13/07 21:27
Rightclick, new, Text. Then rename new document.txt to normalmapping.fx, open it with the standart editor and copy&past the shader code.
Posted By: Mondivirtuali
Re: Normalmapping (in development) - 03/13/07 22:10
Okay, shader code done. It called mt_material1.fx
Then I try this:
I put two skins in the same (static model)(from Med), one is the normal map (obteined with Gimp from the first skin) .
Then I include the nm.fx in the try.wdl , include material.wdl in the project and assign the mt_material1 at the model.
It appairs the same (?), perhaps the two skins should named "entskin"? I should miss some passages here.
Posted By: Mondivirtuali
Re: Normalmapping (in development) - 03/14/07 00:04
Something happened to my models: a sort of shadows? . Perhaps, even if the code is wrong, there is some effects.
Posted By: Mondivirtuali
Re: Normalmapping (in development) - 03/14/07 20:46
The test model is bumpy as the reference model ( bump with Blender and NM with Melody)!
![](http://img513.imageshack.us/img513/4486/shot0qw7.jpg)
The thing works!
Posted By: MaxF
Re: Normalmapping (in development) - 03/15/07 00:27
Hi
I'm getting this script error
Posted By: D3D
Re: Normalmapping (in development) - 03/15/07 05:31
Guess it would be to easy to think its just a syntax error:
MATERIAL mtl_bump, can't try the fx right now because I just woke up and turn on the laptop its 6:30 in the morning
Posted By: jcl
Re: Normalmapping (in development) - 03/15/07 08:04
Don't worry if not anyone can get it to run at a first attempt - I'll put the shader in the MtlFX file, and will provide step by step instructions of what normalmapping does and how to use it.
Posted By: RobH
Re: Normalmapping (in development) - 03/15/07 09:24
@ JCL!
Please, make more shaders like the NM. It works for me perfect.
I think to a post in the beta forum from me about an AUM specular shader. There were some errors and i doesn´t get an real answer. But if Conitec will work on more shaders for easy to use it will be a great help for the users.
Posted By: Machinery_Frank
Re: Normalmapping (in development) - 03/15/07 09:34
I am also very happy to see new results in this manner.
I would also like to politely ask for an improved 2.0 version with specularity and affected by a few dynamic lights. This 1.1 version could be the fallback for the more powerful version.
I would instantly start to create a new techdemo level with my sci-fi texture set then. When I can use shaders and static shadows on static meshes, then I see no barriers anymore to create very eye-candy demo-levels. I am sure I can do something similar to my rendered Lightwave scenes in real-time then:
![](http://www.dexsoft-games.com/images/previews/scifi/rr1s.jpg)
Frank
Posted By: broozar
Re: Normalmapping (in development) - 03/15/07 09:41
Quote:
I am sure I can do something similar to my rendered Lightwave scenes in real-time then
if you had a shadow system as in lw, probably. but without soft/dynamic shadows it would look quite different, very much less natural.
Posted By: Machinery_Frank
Re: Normalmapping (in development) - 03/15/07 09:45
no, no. A static shadow can be made like a soft shadow with more than one light source. There is no problem. I made a few levels before with the current static lighting system and I like it so far. Only blocks are not flexible enough. Static meshes solve this issue.
Posted By: MaxF
Re: Normalmapping (in development) - 03/15/07 13:18
Please do, this would help so much.
Posted By: MaxF
Re: Normalmapping (in development) - 03/15/07 14:00
Hi JCL
This is what I did:
1) Copied the shader code and save it as normalmap.fx
2) In Med the textured skin is set to Skin0 and the normal map is set to Skin1, attached the normalmap.fx file using the Med’s Skin settings.
3) Load the model in to WED.
4) Include default.fx into the project.
I have the latest version.
What’s going wrong
Posted By: RobH
Re: Normalmapping (in development) - 03/15/07 14:10
Test it this way:
Copy the full text into SED and save it as mat_bumb.WDL for example. Then include it in your main wdl and add it by material in the model properties in WED. Compile your level and then it must work.
Posted By: MaxF
Re: Normalmapping (in development) - 03/15/07 14:15
Thanks RobH, Will try this
![](/ubbthreads/images/graemlins/smile.gif)
I see now, this is not shader code right?
Quote:
MATERIAL mtl_bump
{
//Normal Map must be on Skin2
effect=
"
";
}
and should go in WDL.
Posted By: RobH
Re: Normalmapping (in development) - 03/15/07 15:38
I´m not a shader specialist but i think you can save it too in a fx file, but then you have to script a material in SED and load from there the fx. I must test it myself, i have it made like i said and was happy that it works!!
Posted By: jcl
Re: Normalmapping (in development) - 03/15/07 16:27
A MATERIAL and a shader are two different things. Materials can contain effects and effects can contain shaders, but not vice versa.
The .fx format was defined by Microsoft for effect files. Microsoft does not know about Acknex Materials. So if you want to create an .fx file, you need to copy the effect out of the material (between but not including the "" quotes).
Posted By: MaxF
Re: Normalmapping (in development) - 03/15/07 16:51
Got'ya
![](/ubbthreads/images/graemlins/smile.gif)
--------------------
Plus :
I know that I ask a lot
![](/ubbthreads/images/graemlins/smile.gif)
Could you add Frank_G stuff -
Quote:
improved 2.0 version with specularity and affected by a few dynamic lights. This 1.1 version could be the fallback for the more powerful version.
This would be ACE ![](/ubbthreads/images/graemlins/smile.gif)
Posted By: fogman
Re: Normalmapping (in development) - 03/15/07 18:40
Quote:
Could you add Frank_G stuff
Yes, that would be extremely nice. ![](/ubbthreads/images/graemlins/smile.gif)
Posted By: jcl
Re: Normalmapping (in development) - 03/16/07 07:17
I do not want to add 2.0 shaders to A6. A6 was intended to run on 1.0 hardware completely - 2.0, 3.0 and above are for A7 only.
However, maybe I'll attempt to implement specularity and dynamic lights also for 1.0. This is a little challenging, like a puzzle, but I think its doable.
Posted By: MaxF
Re: Normalmapping (in development) - 03/16/07 13:07
You are the best ever
![](/ubbthreads/images/graemlins/smile.gif)
This engine would be so kool, if you add specularity and dynamic lights for 1.0, 2.0, 3.0 with fall back
![](/ubbthreads/images/graemlins/smile.gif)
I think this is a big selling feature if you add shaders like the one above and make it easy to add to projects.
Quote:
I do not want to add 2.0 shaders to A6. A6 was intended to run on 1.0 hardware completely
i dont really understand this..why not have alternative shader code? And who has a pixel shader 1.0 only card? that's ONLY geForce 3 ( all other shader-capable cards supported higher versions like 1.3, 1.4 etc).
Posted By: William
Re: Normalmapping (in development) - 03/17/07 10:30
Yeah, alternative shader code would solve this, at least, that's how I set up my game. Water for example, starts at 2.0, then goes to 1.1. The 2.0 takes more resources, but you can change quality settings in the menus if you need.
But I guess A7 will be released this year, and possibly the 2.0 version of this code as well. I'm looking forward to this shader code; JCL's past shaders worked great.
@Frank - I don't see any reason why that scene wont eventually be possible with the new FBX importer. Basically you'd just save your lightwave scene as FBX, import that scene in WED, and put your lights in. Hopefully though, the importer will also import omni lights from such programs as Max and Lightwave, then you can set your lights in your modeling program and just use WED for building and setting paths.
Posted By: jcl
Re: Normalmapping (in development) - 03/19/07 15:27
Quote:
And who has a pixel shader 1.0 only card? that's ONLY geForce 3 ( all other shader-capable cards supported higher versions like 1.3, 1.4 etc).
Yes, I meant 1.3/1.4 of course. A lot of systems are still below 2.0.
Posted By: jcl
Re: Normalmapping (in development) - 03/21/07 10:50
This is the promised specular bumpmapping:
Code:
MATERIAL mtl_bumpspecular
{
effect=
"
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
float4 vecSunDir;
float4 vecColor;
texture entSkin1; // texture
texture entSkin2; // normal map
sampler sBaseTex = sampler_state { Texture = <entSkin1>; };
sampler sBump = sampler_state { Texture = <entSkin2>; };
struct out_specular
{
float4 Pos: POSITION;
float Fog: FOG;
float4 Color: COLOR;
float2 Tex: TEXCOORD0;
float2 Bump: TEXCOORD1;
float3 Normal: TEXCOORD2;
float3 Halfway:TEXCOORD3;
};
out_specular vs_specular(
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float2 inTex: TEXCOORD0,
in float3 inTangent: TEXCOORD2)
{
out_specular Out;
Out.Pos = DoTransform(inPos);
Out.Tex = inTex;
Out.Bump = inTex; // different coordinates required for ps_1_1
Out.Color = float4(1.0,1.0,1.0,1.0);
Out.Fog = DoFog(inPos);
CreateTangents(inNormal,inTangent);
float3 N = matTangent[2];
Out.Normal = DoTangent(N) * 0.5 + 0.5;
float3 P = DoPos(inPos);
float3 EyeDir = normalize(vecViewPos - P) - vecSunDir;
Out.Halfway = DoTangent(EyeDir) * 0.5 + 0.5;
return Out;
}
float4 ps_specular(out_specular In): COLOR
{
float4 base = tex2D(sBaseTex,In.Tex);
float3 bumpNormal = tex2D(sBump,In.Bump);
float light = saturate(dot(In.Halfway*2 - 1,bumpNormal*2 - 1));
light *= light;
light *= light;
light *= light;
light *= light;
return base *2*light;
}
technique specular
{
pass One
{
VertexShader = compile vs_1_1 vs_specular();
PixelShader = compile ps_1_1 ps_specular();
}
}
";
}
However, here's indeed the shader 2.0 model a better solution - either that, or two passes. Due to the limitation to 4 texture coordinate sets under 1.1, I can not transfer the light coordinates to the pixel shader, which limits the specular shading to a "metal" effect.
You can play with the "2" factor in the pixel shader, or return base + (0.1 + 2*light) for brightening the dark parts of the model.
Posted By: Machinery_Frank
Re: Normalmapping (in development) - 03/21/07 11:16
Thank you very much. I appreciate that.
Posted By: RobH
Re: Normalmapping (in development) - 03/21/07 11:43
Thanks for 1000 times JCL. That all makes GS better and better. Everything works great!
Posted By: MaxF
Re: Normalmapping (in development) - 03/21/07 14:17
Thanks VERY much JCL, you are the best
Posted By: MaxF
Re: Normalmapping (in development) - 03/22/07 18:16
Thanks JCL it looks and works so GOOD
Posted By: PHeMoX
Re: Normalmapping (in development) - 03/24/07 02:25
Sweet thanks!
![](/ubbthreads/images/graemlins/smile.gif)
Cheers
Posted By: Ghost
Re: Normalmapping (in development) - 03/24/07 11:40
Thank you.
Posted By: MaxF
Re: Normalmapping (in development) - 03/24/07 15:40
Well after more testing the shader does not react to any lights. Can you change it so it does, if my level is blue and the model with the shader is white just looks wrong.
Posted By: PHeMoX
Re: Normalmapping (in development) - 03/25/07 19:51
There's a 'CreateTangents' function missing, or is that one of those things that can be found inside default.fx ? I could be doing all sorts of things wrong, however, I've got default.fx included, but this shader doesn't work here 'out of the box' I think,
Cheers
Posted By: jcl
Re: Normalmapping (in development) - 03/26/07 04:27
Phemox: You need the current Gamestudio version for this shader.
MaxF: Here's an indoor version that supports the static environment light and one dynamic light:
Code:
MATERIAL mtl_bumpspecular
{
effect=
"
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
#define INDOOR
#ifdef INDOOR
#include <light>
#else
float4 vecSunDir;
float4 vecSunColor;
#endif
float4 vecLight;
texture entSkin1; // texture
texture entSkin2; // normal map
const float facAmbient = 0.2; // factors to play with
const float facBump = 0.5;
const float facSpecular = 2.0;
sampler sBaseTex = sampler_state { Texture = <entSkin1>; };
sampler sBump = sampler_state { Texture = <entSkin2>; };
struct out_specular
{
float4 Pos: POSITION;
float Fog: FOG;
float4 Color: COLOR0;
float4 Ambient: COLOR1;
float2 Tex: TEXCOORD0;
float2 Bump: TEXCOORD1;
float3 Light: TEXCOORD2;
float3 Halfway:TEXCOORD3;
};
out_specular vs_specular(
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float2 inTex: TEXCOORD0,
in float3 inTangent: TEXCOORD2)
{
out_specular Out;
Out.Pos = DoTransform(inPos);
Out.Tex = inTex;
Out.Bump = inTex; // different coordinate sets required for ps_1_1
Out.Ambient = facAmbient*vecLight;
Out.Fog = DoFog(inPos);
float3 P = DoPos(inPos);
#ifdef INDOOR
float3 LDir = normalize(vecLightPos[0].xyz - P);
float fDist = length(vecLightPos[0].xyz - P)/vecLightPos[0].w;
if (fDist < 1.f)
fDist = 1.f - fDist;
else
fDist = 0.f;
Out.Color = facSpecular*fDist*vecLightColor[0];
#else
float3 LDir = -vecSunDir;
Out.Color = facSpecular*vecSunColor;
#endif
CreateTangents(inNormal,inTangent);
// transform the output values into the 0..1 range
Out.Light = facBump*DoTangent(LDir) * 0.5 + 0.5;
float3 EyeDir = normalize(vecViewPos - P) + LDir;
Out.Halfway = DoTangent(EyeDir) * 0.5 + 0.5;
return Out;
}
float4 ps_specular(out_specular In): COLOR
{
float4 base = tex2D(sBaseTex,In.Tex);
float3 bumpNormal = tex2D(sBump,In.Bump);
float light = saturate(dot(In.Halfway*2 - 1,bumpNormal*2 - 1));
light *= light;
light *= light;
light *= light;
light *= light;
light += saturate(dot(In.Light*2 - 1,bumpNormal*2 - 1));
return base * (In.Ambient + light*In.Color);
}
technique specular
{
pass One
{
VertexShader = compile vs_1_1 vs_specular();
PixelShader = compile ps_1_1 ps_specular();
}
}
";
}
Posted By: MaxF
Re: Normalmapping (in development) - 03/26/07 14:29
WOW JCL you are ACE, so I'll just use the other one for outdoor (works with the sun then) and this for indoor.
![](/ubbthreads/images/graemlins/cool.gif)
So kool will test it later
Posted By: PHeMoX
Re: Normalmapping (in development) - 03/26/07 14:55
Quote:
Phemox: You need the current Gamestudio version for this shader.
Mmm, current version, which one would that be? A6.50.6? Because I thought I had installed that one, anyways I'll re-update then, thanks! ![](/ubbthreads/images/graemlins/smile.gif)
Cheers
Posted By: MaxF
Re: Normalmapping (in development) - 03/27/07 04:10
Hi JCL
![](http://img98.imageshack.us/img98/4053/shadersmv8.jpg)
On the left the old outside code, looks ok does not react to lights
On the right the new one you just posted, it does not matter how many times I play with the following:
const float facAmbient = 0.8; // factors to play with
const float facBump = 0.8;
const float facSpecular = 0.8;
Does not change anything, I would like it to look like the one on the left but work with (I like the specular highlights) with color level / dynamic lights.
I must be doing something wrong
Posted By: jcl
Re: Normalmapping (in development) - 03/27/07 08:43
If "#define INDOOR" is outcommented, the shader reacts on the sun, otherwise on dynamic lights. So the object must be in the range of at least one active dynamic light with CAST flag, or else you'll see no reflection.
If you have only static lights in your indoor level, outcomment the "#define INDOOR" line, and set the sun color to the color of your static lights.
Posted By: MaxF
Re: Normalmapping (in development) - 03/27/07 13:55
Hi JCL
My lights are dynamic and are sat right next to the boxes the CAST flag is on and I get what you see in the picture.
Posted By: jcl
Re: Normalmapping (in development) - 03/27/07 14:51
Then I have to look into this. The shader works in my test level, but there could be something else I haven't thought about. If you upload your level, I'll check why the shader doesn't work.
Posted By: MaxF
Re: Normalmapping (in development) - 03/27/07 16:16
Thanks JCL will upload it tonight
Posted By: MaxF
Re: Normalmapping (in development) - 03/28/07 00:35
OK I sent you the level by email. to jcl conitec
Posted By: Machinery_Frank
Re: Normalmapping (in development) - 03/31/07 09:45
Hi,
I rendered a texture for you to play around with normal-mapping shaders with and without specularity. You can add the spec-map into the alpha channel if you need it.
Download:
http://www.dexsoft-games.com/freebies/textures/freecrate.zipPreview:
![](http://www.dexsoft-games.com/freebies/textures/crate4in1.jpg)
This is a gift for you. Use it!
![](/ubbthreads/images/graemlins/smile.gif)
Maybe it is a good idea to put the finished version of the JCL-shader into the WIKI as an alternative to the 2.0 shader from Matt.
Best regards,
Frank
Posted By: MaxF
Re: Normalmapping (in development) - 04/01/07 01:54
Hi Frank_G
Thanks so much
Posted By: MaxF
Re: Normalmapping (in development) - 04/03/07 14:55
Hi JCL
Can you post your screenshot so I know what it looks like, I still can't get this shader to work. Plus I can't get the other 3light shader by xXxGuitar511, the objects just look black and it does not matter how many time I change any of the variables nothing makes them lighter.
Posted By: xXxGuitar511
Re: Normalmapping (in development) - 04/04/07 16:47
@MaxF: I can send you the environment I used for testing the shader if you want. Also, Are you sure you have a grafix card that supports VSPS 2.0?
Posted By: MaxF
Re: Normalmapping (in development) - 04/04/07 22:15
Hi xXxGuitar511
That would be GREAT
![](/ubbthreads/images/graemlins/smile.gif)
My card supports VSPS 3.00, its probably me doing something wrong.
Send me a PM for my email address
Posted By: vlau
Re: Normalmapping (in development) - 05/03/07 14:36
Sorry to bring up this old thread. I run into problem when apply
this shader to my model :
Malfunction W1550
-----------------
normalMapping(4): error X3000: syntax error: unexptected token 'mtl_bump'
(15):error X1005: string continues past end of line
(16):error X1507: failed to open source file: 'fog'
>MATERIAL mtl_bump<
Any ideas?
Posted By: jcl
Re: Normalmapping (in development) - 05/04/07 08:50
That's just a syntax error. Maybe you attempted to put a material into a .fx file. Material definitions belong into script files (.wdl), .fx is for the bare effects only.
Posted By: vlau
Re: Normalmapping (in development) - 05/04/07 09:18
Ah yes, that's my fault, it works great now.
Thank you.
Posted By: Frederick_Lim
Re: Normalmapping (in development) - 05/09/07 05:32
Can someone send a test level to me to learn how to use it?
Posted By: foodstamp
Re: Normalmapping (in development) - 05/21/07 19:45
Yes is there a test level for this ? I learn more by a example then looking at the stuff on a forum or site