none
C# SharpDX(directx) Direct3D11 HLSL difficulties

    Pertanyaan

  • 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; 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 {

    //I think I did this totaly wrong. I did not use this one. //float3 sampledNormal = (2*ShaderTextureNormal.Sample(Sampler,input.TextureUV).xyz) - 1.0f; //float3x3 tbn = float3x3(input.tangent, input.binormal, input.normal); //sampledNormal = mul(sampledNormal, tbn);

    //I use N - is this correct ? 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 ?


    • Diedit oleh gomili Senin, 09 Juli 2018 16.12
    • Dipindahkan oleh CoolDadTx Senin, 09 Juli 2018 17.40 Third party product
    Senin, 09 Juli 2018 15.25

Semua Balasan