Jump to content

  • Log In with Google      Sign In   
  • Create Account

tapinkaR

Member Since 15 Jul 2012
Offline Last Active Jul 17 2012 04:27 AM

Posts I've Made

In Topic: Using normal mapping with triplanar texture projection

16 July 2012 - 12:24 AM

Hello,
I have similar issue. I made HLSL effect for my XNA game. I am using triplanar texture for my terrain. But result is moving with my model. There is probably some issue in position but I don't know how to fix it. Please help me with this issue. I went from many blogs and forums but I didn't find the solution.

here is my HLSL code:
[source lang="cpp"]// -------------------------------------------------// Matrices// -------------------------------------------------float4x4 matW : World;float4x4 matVI : ViewInverse;float4x4 matWVP : WorldViewProjection;// Lights// -------------------------------------------------float ambientLightColor;float3 light1Position;float3 light1Color;float3 light2Position;float3 light2Color;float3 lightDirection;// UV Tiles: 0-4 Diffuse texturesfloat2 uv1Tile;float2 uv2Tile;float2 uv3Tile;float2 uv4Tile;// Textures// -------------------------------------------------texture diffuseTexture1;texture diffuseTexture2;texture diffuseTexture3;texture diffuseTexture4;sampler2D diffuseSampler1 = sampler_state { texture = <diffuseTexture1>; MagFilter = Linear; MinFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap;};sampler2D diffuseSampler2 = sampler_state { texture = <diffuseTexture2>; MagFilter = Linear; MinFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap;};sampler2D diffuseSampler3 = sampler_state { texture = <diffuseTexture3>; MagFilter = Linear; MinFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap;};sampler2D diffuseSampler4 = sampler_state { texture = <diffuseTexture4>; MagFilter = Linear; MinFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap;};struct a2v{ float4 position : POSITION0; float2 uv0 : TEXCOORD0; float3 normal : NORMAL;float4 inTexWeights : TEXCOORD1;};struct v2f{ float4 hposition : POSITION; float3 lightVec1 : TEXCOORD0; float3 xlightDirection : TEXCOORD1;float4 TextureWeights : TEXCOORD2;float3 Normal : TEXCOORD3;float3 blendFactor : TEXCOORD4;float2 coord1 : TEXCOORD5;float2 coord2 : TEXCOORD6;float2 coord3 : TEXCOORD7;};float DotProduct(float3 lightPos, float3 pos3D, float3 normal){ float3 lightDir = normalize(pos3D - lightPos); return dot(-lightDir, normal); }v2f TerrainVS(a2v IN){v2f OUT; OUT.hposition = mul(IN.position, matWVP); OUT.Normal = normalize(mul(IN.normal, matW)); OUT.blendFactor = abs( OUT.Normal.xyz ); OUT.blendFactor = (OUT.blendFactor - 0.2) * 7; OUT.blendFactor = max(OUT.blendFactor, 1); OUT.blendFactor /= (OUT.blendFactor.x + OUT.blendFactor.y + OUT.blendFactor.z ).xxx; OUT.coord1 = OUT.hposition.yz * 0.01 ;//* tex_scale; mXY;OUT.coord2 = OUT.hposition.zx * 0.01;//* tex_scale; mXZ;OUT.coord3 = OUT.hposition.xy * 0.01;//* tex_scale; mYZ; // Light vectors float3 worldPosition = mul(IN.position, matW).xyz; OUT.lightVec1 = light1Position - worldPosition; OUT.xlightDirection.xyz = lightDirection; OUT.TextureWeights = IN.inTexWeights; return OUT;}float4 MultiTexturedPS(v2f IN) : COLOR0{float4 finalColor; float4 tempColor; float lightingFactor1 = DotProduct(light1Position,IN.lightVec1,IN.Normal); float lightingFactor = saturate(lightingFactor1); lightingFactor *= light1Color;tempColor = tex2D(diffuseSampler1, IN.coord1.xy)* IN.blendFactor.z; tempColor += tex2D(diffuseSampler1, IN.coord2.xy)* IN.blendFactor.x; tempColor += tex2D(diffuseSampler1, IN.coord3.xy)* IN.blendFactor.y;finalColor = tempColor * IN.TextureWeights.x;tempColor = tex2D(diffuseSampler2, IN.coord1.xy)* IN.blendFactor.z; tempColor += tex2D(diffuseSampler2, IN.coord2.xy)* IN.blendFactor.x; tempColor += tex2D(diffuseSampler2, IN.coord3.xy)* IN.blendFactor.y;finalColor += tempColor * IN.TextureWeights.y; tempColor = tex2D(diffuseSampler3, IN.coord1.xy)* IN.blendFactor.z; tempColor += tex2D(diffuseSampler3, IN.coord2.xy)* IN.blendFactor.x; tempColor += tex2D(diffuseSampler3, IN.coord3.xy)* IN.blendFactor.y;finalColor += tempColor * IN.TextureWeights.z; tempColor = tex2D(diffuseSampler4, IN.coord1.xy)* IN.blendFactor.z; tempColor += tex2D(diffuseSampler4, IN.coord2.xy)* IN.blendFactor.x; tempColor += tex2D(diffuseSampler4, IN.coord3.xy)* IN.blendFactor.y;finalColor += tempColor * IN.TextureWeights.w; finalColor *= lightingFactor + ambientLightColor; return finalColor;}technique Terrain{ pass p0{ VertexShader = compile vs_2_0 TerrainVS(); PixelShader = compile ps_2_0 MultiTexturedPS();}}[/source]

Here is stored the result.
http://www.uloz.to/xeP8UdE/triplanar-avi

PARTNERS