directx - Texture Lookup in Vertex Shader -


i'm trying create vertex shader loads texture , uses distort sphere. though texture seamless when put on sphere, distortion has gaps between triangles. seen in image below.

image

i think somthing going wrong when sampling texture, i'm not sure. here code i'm using vertex shader:

cbuffer matrixbuffer { matrix worldmatrix; matrix viewmatrix; matrix projectionmatrix; };  cbuffer explosionbuffer { float3 distortion; float time; };  texture2d shadertexture; samplerstate sampletype;   //structs  struct vertexinputtype { float4 position : position; float2 tex : texcoord0; float3 normal : normal; };  struct pixelinputtype { float4 position : sv_position; float2 tex : texcoord0; float3 normal : normal; float4 deltap : deltapos; };  //vertex shader  pixelinputtype explosionvertexshader(vertexinputtype input) { pixelinputtype output;   //sample noise texture uint3 samplecoord = uint3(512*input.tex.x, 512*input.tex.y, 0); float4 distex = shadertexture.load(samplecoord);   //calculate displacement based on noise tex , distortion buffer float displacement; displacement = distortion.x * distex.r + distortion.y * distex.g + distortion.z * distex.b; displacement = displacement * 2; displacement = distex.r + distex.g + distex.b; input.position = input.position * (1 + displacement);  //set w 1 proper matrix calculations. input.position.w = 1.0f;  // calculate position of vertex against world, view, , projection matrices. output.position = mul(input.position, worldmatrix); output.position = mul(output.position, viewmatrix); output.position = mul(output.position, projectionmatrix);  // store input color pixel shader use. output.tex = input.tex;  output.normal = input.normal;  output.deltap.x = displacement;  return output; } 

i think problem is, you're sampling texels out of range.

the lines

//sample noise texture uint3 samplecoord = uint3(512*input.tex.x, 512*input.tex.y, 0); float4 distex = shadertexture.load(samplecoord); 

are sampling coordinates in [0,512] range, goes out of bounds (assuming you're using 512² texture). load method expects input coordinates in [0,texturedimension-1].

therefore crack in model can explained note documentation:

note when 1 or more of coordinates in location exceed u, v, or w mipmap level dimensions of texture, load returns 0 in components. direct3d guarantees return 0 resource accessed out of bounds.

so effected vertices displaced zero.


Comments