[Tutorial]Using HLSLshaders for bumpmapping + lighting (WIP)
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
Tanks for the turorial it finaly alowed me to use texture atlasses because my previous normal maping technique was nnot working when i was atlassing normal map and this one works
the only bad side is that i don't yet understand the principle behind normal maping
the only bad side is that i don't yet understand the principle behind normal maping
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
The normal mapping is like the regular lighting, but instead of calculating the normal, you read it from a texture, then you transform the normalized light vector to the tangent space for the light equation and perform the NdL product as always.
That is why the tangent space vectors are needed for.
That is why the tangent space vectors are needed for.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
yup the only thing is that in this shader the normal is put to tangent space not the light vector.....
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
There are many ways of doing lighting. Normal texture and simple light attenuation is quickest way of making little highlights, and specular lighting is the best way of making things a little "shinier". This shader is kinda crappy because it doesn't do things in the "best, most correct way" but it's a good starting point. Also, per pixel lighting, in every case I've found so far, looks better than irrlicht's lights.
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
Not exactly, What the shader is doing is to convert the normals to worldSpace, so, light direction and normals are expressed in this case in world space, and the calculation can be done the same, although that is slower because it moves the normal calculation to the pixel shader instead of transforming the light vector in the vertex shader, but in exchange it may perform per pixel look ups on 3D textures for environmental calculations using the normals in world space.Granyte wrote:yup the only thing is that in this shader the normal is put to tangent space not the light vector.....
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
i"m trying to use this shader with the following code to generate a normal froma height map but some how it won't work.
i have been so far totaly unable to get it to work any sugestion?
Code: Select all
float3 norm =normalize(float3(0,0,1));//= normal;
float me = tex2D(tex0,TexCoord).r;
float n = tex2D(tex0,saturate(float2(TexCoord.x,TexCoord.y+1.0/texsize))).r/2.0f;
float s = tex2D(tex0,saturate(float2(TexCoord.x,TexCoord.y-1.0/texsize))).r/2.0f;
float e = tex2D(tex0,saturate(float2(TexCoord.x+1.0/texsize,TexCoord.y))).r/2.0f;
float w = tex2D(tex0,saturate(float2(TexCoord.x-1.0/texsize,TexCoord.y))).r/2.0f;
float ne = tex2D(tex0,saturate(float2(TexCoord.x+1.0/texsize,TexCoord.y+1.0/texsize))).r/6.0f;
float sw = tex2D(tex0,saturate(float2(TexCoord.x-1.0/texsize,TexCoord.y-1.0/texsize))).r/6.0f;
float se = tex2D(tex0,saturate(float2(TexCoord.x+1.0/texsize,TexCoord.y-1.0/texsize))).r/6.0f;
float nw = tex2D(tex0,saturate(float2(TexCoord.x-1.0/texsize,TexCoord.y+1.0/texsize))).r/6.0f;
n += tex2D(tex0,saturate(float2(TexCoord.x,TexCoord.y+2.0/texsize))).r/6.0f;
s += tex2D(tex0,saturate(float2(TexCoord.x,TexCoord.y-2.0/texsize))).r/6.0f;
e += tex2D(tex0,saturate(float2(TexCoord.x+2.0/texsize,TexCoord.y))).r/6.0f;
w += tex2D(tex0,saturate(float2(TexCoord.x-2.0/texsize,TexCoord.y))).r/6.0f;
n += ne;
n += nw;
s += se;
s += sw;
e += ne;
e += se;
w += nw;
w += sw;
//find perpendicular vector to norm:
float3 temp = norm; //a temporary vector that is not parallel to norm
if(norm.x==1)
temp.y+=0.5;
else
temp.x+=0.5;
//form a basis with norm being one of the axes:
float3 perp1 = normalize(cross(norm,temp));
float3 perp2 = normalize(cross(norm,perp1));
//use the basis to move the normal in its own space by the offset
float3 normalOffset = -0.1*(((n-me)-(s-me))*perp1 + ((e-me)-(w-me))*perp2);
norm +=normalOffset;
norm = normalize(norm);
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
Just use the height2normal program or any other heightmap to normal converter. You might as well begin your program with everything precalculated no?
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
that is impossible in my case since everything is generated on the fly using procedural algorythm
and just because i see it comming no i cannot use the built in make normal map function because my height map can be 16 or 32 bit precision if the user want it (standar 8bit color return crappy result over a complete planet)
and just because i see it comming no i cannot use the built in make normal map function because my height map can be 16 or 32 bit precision if the user want it (standar 8bit color return crappy result over a complete planet)
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
I pointed out the paper to do that in another topic; search for "tangentless normal mapping".
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
i had a tengent less normal maping implemented befor only at planetary scale it was giving horrible arifacts when people were getting to close to the groundyuiiii
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
I would like to use this but Im not sure how,do all the code above go in the d3d9.hlsl or is it all suppose to be setup in your main programs code?
I would like to make some shaders,I'm able to make them in fx composer easily,I just dont understand what irrlicht needs it in.fx composer has alot of extra of extra code,but none of it is like irrlichts example.
I would like to make some shaders,I'm able to make them in fx composer easily,I just dont understand what irrlicht needs it in.fx composer has alot of extra of extra code,but none of it is like irrlichts example.
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
Only the shader part goes in the hlsl file. You need to start the engine in directx9 mode, load the shader and set the call back, and then set the material type like in the example.
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
Well Abraxas I wasnt able to get the code snippet on the first page to work,Theres some missing code that is from his project.
Think you can post it working or any suggestions.
Im working on a 3d screensaver,and Id like to use normal mapping on animated objects,is the code snippet above only for static objects?
Think you can post it working or any suggestions.
Im working on a 3d screensaver,and Id like to use normal mapping on animated objects,is the code snippet above only for static objects?
Re: [Tutorial]Using HLSLshaders for bumpmapping + lighting (
hmmm.. if you begin with the shader example and use this code, combined with a bumpmap, you shouldn't be missing anything.