我在c#-SharpDX中加载obj文件。一切正常,我得到了指定材质的网格,但网格不是很平滑:
就像我在主题中提到的那样,我不想在外部工具中编辑网格物体。 我想我应该编辑我的着色器,但我不确定。是不是在sharpdx中有一些选项可以使网格平滑或类似。 我也试过,像我已经说过的那样,编辑我的着色器,但它很轻松。 也许有人可以把我推向正确的方向。 这是具有法线贴图的着色器代码:
cbuffer data :register(b0)
{
float4x4 world;
float4x4 worldViewProj;
float4 lightDirection;
float4 viewDirection;
float bias;
};
struct VS_IN
{
float4 position : POSITION;
float3 normal : NORMAL;
float3 tangent: TANGENT;
float3 binormal: BINORMAL;
float2 texcoord : TEXCOORD;
};
struct PS_IN
{
float4 position : SV_POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD;
float3 lightDirection:LIGHT;
float3 viewDirection:VIEW;
};
//texture
Texture2D textureMap:register(t0);
Texture2D normalMap:register(t1);
SamplerState textureSampler;
PS_IN VS( VS_IN input)
{
PS_IN output = (PS_IN)0;
float3 B=mul(world,input.binormal);
float3 T=mul(world,input.tangent);
float3 N=mul(world,input.normal);
output.position = mul(worldViewProj,input.position);
output.normal=N;
output.texcoord=input.texcoord;
float3x3 Tangent={T,B,N};
output.lightDirection=mul(Tangent,lightDirection.xyz);
output.viewDirection= mul(Tangent,viewDirection.xyz);
return output;
}
float4 PS( PS_IN input ) : SV_Target
{
float2 parallax=input.viewDirection.xy * normalMap.Sample( textureSampler, input.texcoord).a*bias;
float4 D=textureMap.Sample( textureSampler, input.texcoord +parallax);
float4 N=normalMap.Sample( textureSampler, input.texcoord +parallax)*2.0f-1.0f;
return saturate(dot(N,input.lightDirection))*D+0.2F;
}