Jump to content
  • Advertisement

DX11 Is this texture seaming caused by sample type?

Recommended Posts

Hi, so I imported some new models into my engine, and some of them show up with ugly seams or dark patches, while others look perfect (see pictures)

I'm using the same shader for all of them, and all of these models have had custom UV mapped textures created for them, which should wrap fully around them,

instead of using tiled textures. I have no idea why the custom UV mapped textures are mapping correctly on some, but not others.

Possible causes are

1. Am I using the wrong SamplerState to sample the textures? (Im using SampleTypeClamp )

2. The original models had quads, and were UV mapped by an artist in that state, then I reimported them into 3DS Max and reexported them as all triangles 

(my engine object loader only accepts triangles).

3. Could the original model UVs just be wrong?

Please let me know if somebody can help identify this problem, I'm completely baffled. Thanks.

For reference, here's a link to the shader being used to draw the problematic models and the shader code below.


#define NUM_LIGHTS 3

// texture resource that will be used for rendering the texture on the model
Texture2D shaderTextures[7];// NOTE - we only use one render target for drawing all the shadows here!
// allows modifying how pixels are written to the polygon face, for example choosing which to draw. 
SamplerState SampleType;

SamplerState SampleTypeClamp : register(s0);
SamplerState SampleTypeWrap  : register(s1);


// This structure is used to describe the lights properties
struct LightTemplate_PS
    int type;
    float3 padding;
    float4 diffuseColor;
    float3 lightDirection; //(lookat?) //@TODO pass from VS BUFFER?
    float specularPower;
    float4 specularColor;

cbuffer SceneLightBuffer:register(b0)
    float4 cb_ambientColor;
    LightTemplate_PS cb_lights[NUM_LIGHTS];

// value set here will be between 0 and 1.
cbuffer TranslationBuffer:register(b1)
    float textureTranslation; //@NOTE = hlsl automatically pads floats for you

// for alpha blending textures
cbuffer TransparentBuffer:register(b2)
    float blendAmount;

struct PixelInputType
    float4 vertex_ModelSpace : SV_POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
    float3 tangent : TANGENT;
    float3 binormal : BINORMAL;
    float3 viewDirection : TEXCOORD1;
    float3 lightPos_LS[NUM_LIGHTS] : TEXCOORD2;
    float4 vertex_ScrnSpace : TEXCOORD5;

float4 main(PixelInputType input) : SV_TARGET
    bool bInsideSpotlight = true;
    float2 projectTexCoord;
    float depthValue;
    float lightDepthValue;
    float4 textureColor;
    float gamma = 7.f;

    /////////////////// NORMAL MAPPING //////////////////
    float4 bumpMap = shaderTextures[4].Sample(SampleType, input.tex);

    // Sample the shadow value from the shadow texture using the sampler at the projected texture coordinate location.
    projectTexCoord.x =  input.vertex_ScrnSpace.x / input.vertex_ScrnSpace.w / 2.0f + 0.5f;
    projectTexCoord.y = -input.vertex_ScrnSpace.y / input.vertex_ScrnSpace.w / 2.0f + 0.5f;
    float shadowValue = shaderTextures[6].Sample(SampleTypeClamp, projectTexCoord).r;

    // Expand the range of the normal value from (0, +1) to (-1, +1).
    bumpMap = (bumpMap * 2.0f) - 1.0f;

    // Change the COORDINATE BASIS of the normal into the space represented by basis vectors tangent, binormal, and normal!
    float3 bumpNormal = normalize((bumpMap.x * input.tangent) + (bumpMap.y * input.binormal) + (bumpMap.z * input.normal));

    //////////////// AMBIENT BASE COLOR ////////////////
    // Set the default output color to the ambient light value for all pixels.
    float4 lightColor = cb_ambientColor * saturate(dot(bumpNormal, input.normal) + .2);

    // Calculate the amount of light on this pixel.
    for(int i = 0; i < NUM_LIGHTS; ++i)
        float lightIntensity = saturate(dot(bumpNormal, normalize(input.lightPos_LS[i])));
        if(lightIntensity > 0.0f)
        lightColor += (cb_lights[i].diffuseColor * lightIntensity) * 0.3;

    // Saturate the final light color.
    lightColor = saturate(lightColor);

    // TEXTURE ANIMATION -  Sample pixel color from texture at this texture coordinate location.
    input.tex.x += textureTranslation;

    float4 color1 = shaderTextures[0].Sample(SampleTypeWrap, input.tex);
    float4 color2 = shaderTextures[1].Sample(SampleTypeWrap, input.tex);
    float4 alphaValue = shaderTextures[3].Sample(SampleTypeWrap, input.tex);
    //textureColor = saturate((alphaValue * color1) + ((1.0f - alphaValue) * color2));
    textureColor = color1;

    // Combine the light and texture color.
    float4 finalColor = lightColor * textureColor * shadowValue * gamma;

    //if(lightColor.x == 0)
    //    finalColor =  cb_ambientColor * saturate(dot(bumpNormal, input.normal) + .2) * textureColor;

    return finalColor;





Share this post

Link to post
Share on other sites

Those look like flipped normals. Could also be a normal map that doesn't support mirroring well, like a object normal map.

It could be that you have been mirroring your mesh to save time but did not correct the normals before export. Try the texture on a sphere and see if the same thing happens.


After reading your post I will say it's the mesh. Recalculate your normals in your 3D software.

Edited by Scouting Ninja

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!