Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Help with normalmap and Blender  (Read 949 times)
tedlin01
Customers
Community Member
*****
Posts: 140


WWW
« on: January 25, 2010, 10:15:13 AM »

Hello!

I was using meshes exported with 3Ds max and created shaders for diffuse and normalmap textures. Worked fine!

Then I exported some meshes with Blender since its free and I noticed that I had to flip the Y-coordinate of the texture in the shader for it to work.

Also when I load the normalmap it seems pretty f***ed up. Got to have something to do with the exporter for blender. What can I possible try?

Btw: I have made sure that the normalmap texture is correct and that the code worked for 3ds max models.

Printscreen:


Structure
Code:
struct SSceneVertexToPixel
{
    float4 Position              : POSITION;

    float4 RealDistance          : TEXCOORD1;
    float2 TexCoords             : TEXCOORD2;
float3 Light : TEXCOORD3;
float4 ShadowMapSamplingPos : TEXCOORD4;
float2 ProjectedTexCoords : TEXCOORD5;
};

struct SScenePixelToFrame
{
    float4 Color : COLOR0;
};

Texture Sample
Code:
texture BumpMap01 : TEXTURE1;
sampler BumpMapSampler01 = sampler_state { texture = <BumpMap01> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};

Vertexshader:
Code:
SSceneVertexToPixel Scene_BumpVS( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal: NORMAL0, float3 inTangent : TANGENT)
{
     SSceneVertexToPixel Output = (SSceneVertexToPixel)0;

float3x3 worldToTangentSpace;
     worldToTangentSpace[0] = mul(inTangent,mWorld);
     worldToTangentSpace[1] = mul(cross(inTangent,inNormal),mWorld);
     worldToTangentSpace[2] = mul(inNormal,mWorld);

     Output.Light = normalize(mul(worldToTangentSpace,vLightDir));   
     Output.Position = mul(inPos, mWorldViewProjection);
     Output.TexCoords = inTexCoords;
     Output.TexCoords.y = 1.0 - inTexCoords.y;

     return Output;   
}
PixelShader
Code:
// Get the colors of the texture, normal and diffuse
float4 texCol = tex2D(ColoredTextureSampler, PSIn.TexCoords);
float3 vNormal = (2 * (tex2D(BumpMapSampler01, PSIn.TexCoords))) - 1.0;
float  Diffuse = saturate(dot(PSIn.Light,vNormal)) + fAmbient + (vMaterial - 1.0f);

// Mix the colors
Output.Color = Diffuse * texCol;
Output.Color.rgb *= vLightColor;
Output.Color += ( vMaterial - 1.0f );

Output.Color = saturate(dot(PSIn.Light,vNormal));
return Output;
Logged

tedlin01
Customers
Community Member
*****
Posts: 140


WWW
« Reply #1 on: January 26, 2010, 07:10:12 AM »

btw, it works with TV3D internal shaders so I guess it must be some solution.
Logged

Lenn
Customers
Community Member
*****
Posts: 876

+/-


« Reply #2 on: January 26, 2010, 08:00:21 AM »

Without looking at the shader much, if it works in 3ds max and not in blender, then the main suspect is that blender is exporting the secondary uv coords wrongly, or mixing up the uv channels or that it only exports one uv set in the first place (most likely?). It really takes more testing than that to figure it out completely.
Logged

TV3D 6.5 Community Docs - Read, use and please contribute!
tedlin01
Customers
Community Member
*****
Posts: 140


WWW
« Reply #3 on: January 26, 2010, 08:34:10 AM »

SOLVER!
Worked when changing the texturefilter AdressU and AdressV to wrap.
Logged

Lenn
Customers
Community Member
*****
Posts: 876

+/-


« Reply #4 on: January 26, 2010, 09:23:37 AM »

 Tongue
Logged

TV3D 6.5 Community Docs - Read, use and please contribute!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks