G
gomili
Guest
Texture2D ShaderTexture : register(t0);
Texture2D ShaderTextureNormal : register(t1);
SamplerState Sampler : register(s0);
struct VS_IN
{
float4 pos : POSITION;
float3 normal : NORMAL; // Normal - for lighting
float4 col : COLOR;
float2 TextureUV: TEXCOORD; // Texture UV coordinate
};
struct VS_OUTPUT
{
float4 pos : POSITION0;
float2 TextureUV: TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 TextureUV: TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
float3 lightDirection:LIGHT;
};
float4x4 worldViewProj;
float4x4 world;
float4 lightDirection;
float3 CalculateTangent(float3 normal){
float3 tangent;
float3 c1 = cross(normal, float3 (0.0, 0.0, 1.0));
float3 c2 = cross(normal, float3 (0.0, 1.0, 0.0));
return tangent;
}
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
output.pos = mul(input.pos, worldViewProj);
input.pos.z= input.pos.z - 0.1f;
input.pos.z *= 10.0f;
output.col = 1.0f-((input.pos.w /* * input.col*/) / (input.pos.z /* *input.col*/));
output.TextureUV = input.TextureUV;
output.normal = input.normal;
output.tangent = CalculateTangent(input.normal);
output.lightDirection=1;
return output;
}
float4 PS( PS_IN input ) : SV_Target
{
//float3 sampledNormal = (2*ShaderTextureNormal.Sample(Sampler,input.TextureUV).xyz) - 1.0f;
//float3x3 tbn = float3x3(input.tangent, input.binormal, input.normal);
//sampledNormal = mul(sampledNormal, tbn);
float4 N = ShaderTextureNormal.Sample(Sampler, input.TextureUV)*2.0f-1.0f;
float4 D = ShaderTexture.Sample(Sampler, input.TextureUV);
float4 result;
if( N.x == -1 && N.y == -1 && N.z == -1 && N.w == -1)
{
//Everything is zero so NORMAL map is not set.
result = D;
}
else
{
//We display the default diffuse map.
result = saturate(dot(N,input.lightDirection))*D;
}
return result;
}
Here I get a result which looks like I successfully applied normal map. I do not know if I did it wrong way. I want to add specular and directional light over this. However, I do not know how to do it. Lets say I will make a darker environment with red light and what should I do then ?
Continue reading...
Texture2D ShaderTextureNormal : register(t1);
SamplerState Sampler : register(s0);
struct VS_IN
{
float4 pos : POSITION;
float3 normal : NORMAL; // Normal - for lighting
float4 col : COLOR;
float2 TextureUV: TEXCOORD; // Texture UV coordinate
};
struct VS_OUTPUT
{
float4 pos : POSITION0;
float2 TextureUV: TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 TextureUV: TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
float3 lightDirection:LIGHT;
};
float4x4 worldViewProj;
float4x4 world;
float4 lightDirection;
float3 CalculateTangent(float3 normal){
float3 tangent;
float3 c1 = cross(normal, float3 (0.0, 0.0, 1.0));
float3 c2 = cross(normal, float3 (0.0, 1.0, 0.0));
return tangent;
}
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
output.pos = mul(input.pos, worldViewProj);
input.pos.z= input.pos.z - 0.1f;
input.pos.z *= 10.0f;
output.col = 1.0f-((input.pos.w /* * input.col*/) / (input.pos.z /* *input.col*/));
output.TextureUV = input.TextureUV;
output.normal = input.normal;
output.tangent = CalculateTangent(input.normal);
output.lightDirection=1;
return output;
}
float4 PS( PS_IN input ) : SV_Target
{
//float3 sampledNormal = (2*ShaderTextureNormal.Sample(Sampler,input.TextureUV).xyz) - 1.0f;
//float3x3 tbn = float3x3(input.tangent, input.binormal, input.normal);
//sampledNormal = mul(sampledNormal, tbn);
float4 N = ShaderTextureNormal.Sample(Sampler, input.TextureUV)*2.0f-1.0f;
float4 D = ShaderTexture.Sample(Sampler, input.TextureUV);
float4 result;
if( N.x == -1 && N.y == -1 && N.z == -1 && N.w == -1)
{
//Everything is zero so NORMAL map is not set.
result = D;
}
else
{
//We display the default diffuse map.
result = saturate(dot(N,input.lightDirection))*D;
}
return result;
}
Here I get a result which looks like I successfully applied normal map. I do not know if I did it wrong way. I want to add specular and directional light over this. However, I do not know how to do it. Lets say I will make a darker environment with red light and what should I do then ?
Continue reading...