Specular from normal map

Started by
0 comments, last by Christoph680 14 years ago
Hey there! Again, I've got some problems with my shader xD Maybe I'm just too stupid to do this.. After I finally managed to get the normal map working (or maybe not as I will explain later), here's the next issue. I implemented a specular component which results in some really weird values: (1: From the left, 2: Directly from the light's position, 3: From the right)
float4x4 matWorld                   : WORLD;
float4x4 matWorldViewProj           : WORLDVIEWPROJECTION;
float4x4 matWorldInverseTranspose   : WORLDINVERSETRANSPOSE;
float3 mViewPosition                : VIEWPOSITION;
float3 dirLightDir                  : LIGHTDIR0_DIRECTION;

struct VS_INPUT {
	float4 position : POSITION;
    float3 normal   : NORMAL;
    float3 binormal  : BINORMAL;
    float3 tangent  : TANGENT;
    float2 texCoord : TEXCOORD0;
};

struct VS_OUTPUT {
	float4 position : POSITION;
	float2 texCoord : TEXCOORD1;
	float3 view     : TEXCOORD2;
    float3 normal   : TEXCOORD3; 
    float4 pos3D    : TEXCOORD4;
    
    float3x3 tangentToWorld : TEXCOORD5;
};
 
VS_OUTPUT VS(VS_INPUT IN) {
	VS_OUTPUT OUT;
    
    float4 worldPos = mul(IN.position, matWorld);
    
    OUT.position = mul(worldPos, matWorldViewProj);
    OUT.pos3D = mul(worldPos, matWorld);
	OUT.texCoord = IN.texCoord;
    OUT.view = -(dirLightDir*50) - mul(IN.position, matWorld);
    OUT.normal = normalize(mul(float4(IN.normal,1.0f), matWorld));
    
    OUT.tangentToWorld[0] = mul(IN.tangent, matWorld);
    OUT.tangentToWorld[1] = mul(IN.binormal, matWorld);
    OUT.tangentToWorld[2] = mul(IN.normal, matWorld);
    
    //vsruntimecode
    
	return OUT;
}
 
texture TextureSample_0_base_texture;
sampler TextureSample_0_base_texture_sampler = sampler_state {
 Texture = (TextureSample_0_base_texture);
};


texture TextureSample_1_base_texture;
sampler TextureSample_1_base_texture_sampler = sampler_state {
 Texture = (TextureSample_1_base_texture);
};



texture TextureSample_2_base_texture;
sampler TextureSample_2_base_texture_sampler = sampler_state {
 Texture = (TextureSample_2_base_texture);
};





 
float4 PS(VS_OUTPUT IN) : COLOR {
    float4 output = float4(1, 1, 1, 1);
    float3 mEyeVector = normalize(mViewPosition - IN.pos3D);
    
    IN.view = normalize(IN.view);
    
      float4 local0 = tex2D(TextureSample_0_base_texture_sampler, IN.texCoord);
  float2 local1 = float2(15, 15) * IN.texCoord;
  float4 local2 = tex2D(TextureSample_1_base_texture_sampler, local1);
  float4 local3 = float4(0.5, 0.5, 0, 1);
  float4 local4 = local2 * local3;
  float4 local5 = tex2D(TextureSample_2_base_texture_sampler, IN.texCoord);
  float4 local6 = float4(1, 1, 0.7, 1);
  float4 local7 = local5 * local6;
  float4 local8 = local4 + local7;
float3 local9 = (2 * (local8-0.5f)).rgb;
float3 local10 = normalize(mul(local9,IN.tangentToWorld));
float4 local11 = (dot(local10, IN.view)) * 1.0;
float4 local12 = saturate(local11 + 1);
float3 Half = normalize(dirLightDir + mEyeVector);
float4 specular = pow(saturate(dot(local12,Half)),256);
    output = local0 * local12 + specular;
    
	return output;
}
 
technique SM3 {
    pass Pass0 {
        VertexShader = compile vs_3_0 VS();
        PixelShader  = compile ps_3_0 PS();
    }
}


(The specular part consists of the half and specular floats) As you can see, it's not quite working yet.. (note: it's kind of working with the meshe's normals..). I also think that there's still something wrong with the normal mapping since there's no normal detail visible where the light shines upon. Normal detail is only visible in the areas between light and no light Maybe someone could have a look and see if they find something ;) Greets, Philipp
http://www.philippchristoph.de
Advertisement
Really no one?
If you need some additional info, I'd be grateful to provide it :D

Greets,
Philipp
http://www.philippchristoph.de

This topic is closed to new replies.

Advertisement