Generating a Normal Map
Changing to 0.6 fixes it a little bit, but it still looks pretty funky. And how would insert that you just said into the pixel shader. How am I mean to actually incorporate it?
Thanks for your patience and your help man :) I really appreciate it :)
Thanks for your patience and your help man :) I really appreciate it :)
I want to see you nail this!
And on second thoughts, lower xyzdist.z even more, like to .1f or maybe even .025f somewhere between them two.
And on second thoughts, lower xyzdist.z even more, like to .1f or maybe even .025f somewhere between them two.
TexPixelToFrame GDPS(TexVertexToPixel PSIn) { TexPixelToFrame Output = (TexPixelToFrame)0; //float4x4 TangentMatrix; TangentMatrix[0].x=PSIn.RIGHT.x; TangentMatrix[0].y=PSIn.RIGHT.y; TangentMatrix[0].z=PSIn.RIGHT.z; TangentMatrix[0].w=0; TangentMatrix[1].x=PSIn.UP.x; TangentMatrix[1].y=PSIn.UP.y; TangentMatrix[1].z=PSIn.UP.z; TangentMatrix[1].w=0; TangentMatrix[2].x=PSIn.NORMAL.x; TangentMatrix[2].y=PSIn.NORMAL.y; TangentMatrix[2].z=PSIn.NORMAL.z; TangentMatrix[2].w=0; TangentMatrix[3].x=0; TangentMatrix[3].y=0; TangentMatrix[3].z=0; TangentMatrix[3].w=1; float3 lightdir_in_tangent_space = mul(xLightDirection, TangentMatrix); float3 nor=tex2D(NormalSampler1, float2(PSIn.TextureCoords)).rgb*2-1; float pixel_light=dot(lightdir_in_tangent_space, -nor); //DONT FORGET THE MODIFICATIONS ON THIS LINE Output.Color = tex2D(DiffuseSampler1; //HERE SIMPLY SAMPLE THE DIFFUSE Output.Color*=pixel_light; //MODULATE IT WITH THE LIGHT (sorry i made a mistake before, you only need "white" light Output.Color.a=1.0f; return Output;}
By doing that I still get the same sort of outcome. This also still has the 0.6 for the distxyz
Try different kinds of cross products when you make the tangent space, maybe a fork is going in the wrong direction.
Remember, keep the xyzdist.x and xyzdist.y to 1 still, just shrink xyzdist.z till it looks more appropriately scaled (like there isnt black all over it)
Remember, keep the xyzdist.x and xyzdist.y to 1 still, just shrink xyzdist.z till it looks more appropriately scaled (like there isnt black all over it)
//try thisfor (int i = 0; i < vertex; i++) { Vector3.Normalize(ref vpnt.Position, out vpnt.Normal ); vpnt.Up = new Vector3(0, 1, 0); Vector3 cross = Vector3.Cross(vpnt.Up, vpnt.Normal); Vector3.Normalize(ref cross, out vpnt.Right); vpnt.Up = Vector3.Cross(vpnt.Normal, vpnt.Right); }//also try thisfor (int i = 0; i < vertex; i++) { Vector3.Normalize(ref vpnt.Position, out vpnt.Normal ); vpnt.Up = new Vector3(0, 1, 0); Vector3 cross = Vector3.Cross(vpnt.Up, vpnt.Normal); Vector3.Normalize(ref cross, out vpnt.Right); vpnt.Up = Vector3.Cross(vpnt.Right, vpnt.Normal); }//also try thisfor (int i = 0; i < vertex; i++) { Vector3.Normalize(ref vpnt.Position, out vpnt.Normal ); vpnt.Up = new Vector3(0, 1, 0); Vector3 cross = Vector3.Cross(vpnt.Normal, vpnt.Up); Vector3.Normalize(ref cross, out vpnt.Right); vpnt.Up = Vector3.Cross(vpnt.Right, vpnt.Normal); }//also try thisfor (int i = 0; i < vertex; i++) { Vector3.Normalize(ref vpnt.Position, out vpnt.Normal ); vpnt.Up = new Vector3(0, 1, 0); Vector3 cross = Vector3.Cross(vpnt.Normal, vpnt.Up); Vector3.Normalize(ref cross, out vpnt.Right); vpnt.Up = Vector3.Cross(vpnt.Normal, vpnt.Right); }
Alright much better now, i changed that xyzdist.z to 0.01 and it looks a lot nicer. I didn't change the way the UP, RIGHT and NORMAL is generated though. But theres still a slight problem. The shadow spins around with the planet as is like, kind of S shaped on the planet in a way.
You'll see what I mean, but yeah the shadow spins with the planet? :
Pretty awesome results though. I'm really happen with how this has turned out with the help you've given me. Almost kicking for goal now :)
You'll see what I mean, but yeah the shadow spins with the planet? :
Pretty awesome results though. I'm really happen with how this has turned out with the help you've given me. Almost kicking for goal now :)
Hey man pst... thats some nice-o bump mapping you have there, (remember it was 2 generations ago it was next gen, remember when doom3 came out?) now you just gotta get rid of the bugs...
Does the planet spin? If it does you have to normal transform the tangent space and normal by the world matrix with the translation part docked out of it.
Congrats on the nice screen shot tho, see bump mappings a nice technique isnt it...
Just chop .14 .24 .34 to 0 and .44 to 1 out of the world matrix and then multiply the tangent vectors and normal by this chopped world matrix.
Does the planet spin? If it does you have to normal transform the tangent space and normal by the world matrix with the translation part docked out of it.
Congrats on the nice screen shot tho, see bump mappings a nice technique isnt it...
Just chop .14 .24 .34 to 0 and .44 to 1 out of the world matrix and then multiply the tangent vectors and normal by this chopped world matrix.
It does look pretty awesome doesn't it :) Thanks a heap man. Although I'm really clueless with a lot of this tangent stuff, it's a jump for me at the moment I'm new with it but learning. To make the shadow follow previously I was doing this in the vertex shader:
float3 Normal = normalize(mul(normalize(inNormal), xWorld));
Output.LightingFactor = 1;
if (xEnableLighting)
Output.LightingFactor = saturate(dot(Normal, xLightDirection));
And then this in the pixel shader:
Output.Color.rgb *= saturate(PSIn.LightingFactor);
I've not a clue how to do what your talking about with normal transforming the tangent space? And the other thing thats confused me is why I have the black circle at the poles I would gather they are, of the planet. I never had those there before, my texture was wrapping perfectly?
Thank you so much though, the results now are starting to look pretty amazing.
float3 Normal = normalize(mul(normalize(inNormal), xWorld));
Output.LightingFactor = 1;
if (xEnableLighting)
Output.LightingFactor = saturate(dot(Normal, xLightDirection));
And then this in the pixel shader:
Output.Color.rgb *= saturate(PSIn.LightingFactor);
I've not a clue how to do what your talking about with normal transforming the tangent space? And the other thing thats confused me is why I have the black circle at the poles I would gather they are, of the planet. I never had those there before, my texture was wrapping perfectly?
Thank you so much though, the results now are starting to look pretty amazing.
Just world transform the tangent vectors including the normal, but dont translate them, only orientate them.
Show me a copy of your new pixel and vertex shader, then ill rewrite it for you.
Hey dont worry about tangent space confusing you, i bet 100% of programmers have a little difficulty with it first time, it gets complex and goes straight to unstanding mathematical singularites, but they are advanced calculus.
Show me a copy of your new pixel and vertex shader, then ill rewrite it for you.
Hey dont worry about tangent space confusing you, i bet 100% of programmers have a little difficulty with it first time, it gets complex and goes straight to unstanding mathematical singularites, but they are advanced calculus.
My current shader:
How weird does this look what happens to the poles:
//------- Constants --------float4x4 xView;float4x4 xProjection;float4x4 xWorld;float4x4 TangentMatrix;float3 xLightDirection;float xAmbient;bool xEnableLighting;float4 lightColor = float4(1,1,1,1);float3 ambientColor = float3(1,1,1);//------- Texture Samplers --------Texture xTexture1;sampler TextureSampler1 = sampler_state { texture = <xTexture1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};Texture xNormal1;sampler NormalSampler1 = sampler_state { texture = <xNormal1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};//------- Technique: Textured --------struct TexVertexToPixel{ float4 Position : POSITION0; float4 Color : COLOR0; float LightingFactor: TEXCOORD0; float2 TextureCoords: TEXCOORD1; float3 vView : TEXCOORD2; float3 UP : POSITION1; float3 RIGHT : POSITION2; float3 NORMAL : NORMAL0;};struct TexPixelToFrame{ float4 Color : COLOR0;};TexVertexToPixel TexturedVS( float4 inPos : POSITION0, float3 inNormal: NORMAL0, float4 inUp : POSITION1, float4 inRight : POSITION2 ,float2 inTexCoords: TEXCOORD0){ TexVertexToPixel Output = (TexVertexToPixel)0; float4x4 preViewProjection = mul (xView, xProjection); float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); Output.Position = mul(inPos, preWorldViewProjection); Output.TextureCoords = inTexCoords; //enable for better light... float3 Normal = normalize(mul(normalize(inNormal), xWorld)); Output.LightingFactor = 1; if (xEnableLighting) Output.LightingFactor = saturate(dot(Normal, xLightDirection)); Output.Color = float4(1.0f, 0.0f, 0.0f, 1.0f); Output.vView = -xView[3].xyz - Output.Position; Output.UP = inUp; Output.RIGHT = inRight; Output.NORMAL = inNormal; return Output; }TexPixelToFrame GDPS(TexVertexToPixel PSIn) { TexPixelToFrame Output = (TexPixelToFrame)0; //float4x4 TangentMatrix; TangentMatrix[0].x=PSIn.RIGHT.x; TangentMatrix[0].y=PSIn.RIGHT.y; TangentMatrix[0].z=PSIn.RIGHT.z; TangentMatrix[0].w=0; TangentMatrix[1].x=PSIn.UP.x; TangentMatrix[1].y=PSIn.UP.y; TangentMatrix[1].z=PSIn.UP.z; TangentMatrix[1].w=0; TangentMatrix[2].x=PSIn.NORMAL.x; TangentMatrix[2].y=PSIn.NORMAL.y; TangentMatrix[2].z=PSIn.NORMAL.z; TangentMatrix[2].w=0; TangentMatrix[3].x=0; TangentMatrix[3].y=0; TangentMatrix[3].z=0; TangentMatrix[3].w=1; float3 lightdir_in_tangent_space = mul(xLightDirection, TangentMatrix); float3 nor=tex2D(NormalSampler1, float2(PSIn.TextureCoords)).rgb*2-1; float pixel_light=dot(lightdir_in_tangent_space, nor); Output.Color.rgb = tex2D(TextureSampler1, float2(PSIn.TextureCoords)).rgb; //Output.Color *= float4(pixel_light.r,pixel_light.g,pixel_light.b, 1); Output.Color *= pixel_light; //Output.Color.rgb *= saturate(PSIn.LightingFactor); Output.Color.a = 1; return Output;}technique Textured{ pass Pass0 { VertexShader = compile vs_3_0 TexturedVS(); PixelShader = compile ps_3_0 GDPS(); }}
How weird does this look what happens to the poles:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement