Nomal Mapping For TA
This commit is contained in:
parent
e6316f3239
commit
da5b9c7306
|
@ -1,9 +1,50 @@
|
||||||
#include "Header.hlsli"
|
#include "Header.hlsli"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float3x3 cotangent_frame( float3 N, float3 p, float2 uv )
|
||||||
|
{
|
||||||
|
// get edge vectors of the pixel triangle
|
||||||
|
float3 dp1 = ddx( p );
|
||||||
|
float3 dp2 = ddy( p );
|
||||||
|
float2 duv1 = ddx( uv );
|
||||||
|
float2 duv2 = ddy( uv );
|
||||||
|
|
||||||
|
// solve the linear system
|
||||||
|
float3 dp2perp = cross( dp2, N );
|
||||||
|
float3 dp1perp = cross( N, dp1 );
|
||||||
|
float3 T = dp2perp * duv1.x + dp1perp * duv2.x;
|
||||||
|
float3 B = dp2perp * duv1.y + dp1perp * duv2.y;
|
||||||
|
|
||||||
|
// construct a scale-invariant frame
|
||||||
|
float invmax = 1/sqrt( max( dot(T,T), dot(B,B) ) );
|
||||||
|
return float3x3( T * invmax, B * invmax, N );
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 perturb_normal( float3 N, float3 V, float2 texcoord )
|
||||||
|
{
|
||||||
|
// assume N, the interpolated vertex normal and
|
||||||
|
// V, the view vector (vertex to eye)
|
||||||
|
float3 map = Normal.Sample(S1,texcoord).xyz;
|
||||||
|
map = map * 255./127. - 128./127.;
|
||||||
|
#ifdef WITH_NORMALMAP_2CHANNEL
|
||||||
|
map.z = sqrt( 1. - dot( map.xy, map.xy ) );
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_NORMALMAP_GREEN_UP
|
||||||
|
map.y = -map.y;
|
||||||
|
#endif
|
||||||
|
float3x3 TBN = cotangent_frame( N, -V, texcoord );
|
||||||
|
return normalize( mul(transpose(TBN), map) );
|
||||||
|
}
|
||||||
|
|
||||||
PixelOut main(VertexOut input)
|
PixelOut main(VertexOut input)
|
||||||
{
|
{
|
||||||
PixelOut output;
|
PixelOut output;
|
||||||
output.DiffuseGlow = Diffuse.Sample(S1, input.UV);
|
output.DiffuseGlow = Diffuse.Sample(S1, input.UV);
|
||||||
output.NormalSpec = float4(normalize(input.normal), Normal.Sample(S1,input.UV).w);
|
float3 normal = normalize(input.normal);
|
||||||
|
|
||||||
|
normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV );
|
||||||
|
|
||||||
|
output.NormalSpec = float4(normal, Normal.Sample(S1,input.UV).w);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ VertexOut main( VertexIn input )
|
||||||
input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated);
|
input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated);
|
||||||
|
|
||||||
output.pos = mul(WVP, float4(input.pos,1));
|
output.pos = mul(WVP, float4(input.pos,1));
|
||||||
|
output.ViewPos = mul(WV, float4(input.pos,1));
|
||||||
output.normal = mul(WV, float4(input.normal,0)).xyz;
|
output.normal = mul(WV, float4(input.normal,0)).xyz;
|
||||||
output.UV = input.UV;
|
output.UV = input.UV;
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct VertexIn
|
||||||
struct VertexOut
|
struct VertexOut
|
||||||
{
|
{
|
||||||
float4 pos : SV_POSITION;
|
float4 pos : SV_POSITION;
|
||||||
//float4 ViewPos : POSITION;
|
float4 ViewPos : POSITION;
|
||||||
float2 UV : TEXCOORD;
|
float2 UV : TEXCOORD;
|
||||||
float3 normal : NORMAL;
|
float3 normal : NORMAL;
|
||||||
//float3 tangent : TANGENT;
|
//float3 tangent : TANGENT;
|
||||||
|
|
|
@ -17,7 +17,7 @@ void main( uint3 DTid : SV_DispatchThreadID )
|
||||||
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
|
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
|
||||||
float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0);
|
float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0);
|
||||||
float4 GUI;
|
float4 GUI;
|
||||||
uint2 index = DTid.xy/2 + uint2(Pixels.x/2,0);
|
uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0);
|
||||||
float3 PostLight = Amb.xyz * AmbFactor;
|
float3 PostLight = Amb.xyz * AmbFactor;
|
||||||
PostLight = PostLight + Light.xyz;
|
PostLight = PostLight + Light.xyz;
|
||||||
GUI = float4(Ambient[index]);
|
GUI = float4(Ambient[index]);
|
||||||
|
|
|
@ -176,7 +176,7 @@ HRESULT InitDirect3D()
|
||||||
m->WorldMatrix.m[2][2] = 0.00000005f;
|
m->WorldMatrix.m[2][2] = 0.00000005f;
|
||||||
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
|
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
|
||||||
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
|
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
|
||||||
Oyster::Graphics::API::PlayAnimation(m2, L"movement",false);
|
Oyster::Graphics::API::PlayAnimation(m2, L"movement");
|
||||||
|
|
||||||
t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png");
|
t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png");
|
||||||
t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");
|
t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");
|
||||||
|
@ -233,7 +233,7 @@ HRESULT Render(float deltaTime)
|
||||||
Oyster::Graphics::API::RenderModel(m2);
|
Oyster::Graphics::API::RenderModel(m2);
|
||||||
Oyster::Graphics::API::StartGuiRender();
|
Oyster::Graphics::API::StartGuiRender();
|
||||||
Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1));
|
Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1));
|
||||||
//Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0));
|
Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0));
|
||||||
Oyster::Graphics::API::StartTextRender();
|
Oyster::Graphics::API::StartTextRender();
|
||||||
std::wstring fps;
|
std::wstring fps;
|
||||||
float f = 1/deltaTime;
|
float f = 1/deltaTime;
|
||||||
|
|
Loading…
Reference in New Issue