Sign in to follow this  
Slaaitjuh

Sampler addressU wrap

Recommended Posts

Hey guys, i am having a problem that i am banging my head over. I hoped you guys might know something about this. I have an offsetMap for a sort of displacement mapping of a terrain. The terrain offsetMap's pixels present the position of the vertex. This is created in photoshop as a A32B32G32R32F dds file without mipmapping. I found a code in ShaderX 3 about these kind of 'problems'. What i want to do is load three vertices from this map and calculate the face normal and write that to a renderTarget, so i can do the same per vertex to interpolate a vertex normal. All not to exiting, but the problem is that while i set addressU from the offsetMap to Wrap, it remains to clamp (at least, i think). The return values stuck after reading the first 'row' of the texture, and after that it keeps reading the last pixels from the rows (that is what i concluded from analyzing the results in the renderTarget). The shader code:
//--------------------------------------------------------------------------------------
// File: GenFaceNormalTopoMap.fx
//
//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------

float2	g_vertexMapAddrConsts : VertexMapAddressConstants;
texture g_positionVertexMap : OffsetMap;
sampler2D g_positionSampler = sampler_state
{
    Texture = <g_positionVertexMap>;
    MinFilter = Point;
    MagFilter = Point;
    MipFilter = Point;
    AddressU = Wrap;	// required for fast 1D to 2D conversion
    AddressV = Clamp;
};


texture g_faceTopoMap : FaceTopologyMap;
sampler2D g_topoMapSampler = sampler_state
{
	Texture = <g_faceTopoMap>;
    MinFilter = Point;
    MagFilter = Point;
    MipFilter = Point;
    AddressU = Wrap;	// required for fast 1D to 2D conversion
    AddressV = Clamp;	
};

// texConsts.x = 1.f/TexWidth
// texConsts.y = (1.f/TexWidth)*(1.f/TexHeight);
float2 GPUConvert1DAddressTo2D( float oneD, float2 texConsts )
{
	return( float2(oneD, oneD) *  texConsts );
}

struct sTriangleFace
{
	float3 vertexIndex;
};

float3 CalcFaceNormal( sTriangleFace face )
{
   float3 p0 = tex2D( g_positionSampler, GPUConvert1DAddressTo2D(face.vertexIndex.x, g_vertexMapAddrConsts).xy ).xyz;
   float3 p1 = tex2D( g_positionSampler, GPUConvert1DAddressTo2D(face.vertexIndex.y, g_vertexMapAddrConsts).xy ).xyz;
   float3 p2 = tex2D( g_positionSampler, GPUConvert1DAddressTo2D(face.vertexIndex.z, g_vertexMapAddrConsts).xy ).xyz;
   
   // calc face normal
   float3 v0 = p1 - p0;
   float3 v1 = p2 - p0;
   float3 n = cross( v0, v1 );
   return( normalize(n) ); 
   //return (face.vertexIndex);
   //return (float3(p0.x, p1.x, p2.x));
   //return (float3(face.vertexIndex.x, face.vertexIndex.x, 0) *  float3(g_vertexMapAddrConsts.xy, 0));

}

float4 GenFaceNormalTopoMap( in float2 inUV : TEXCOORD0 ) : COLOR0
{
	sTriangleFace data;
	float4 tmp = tex2D( g_topoMapSampler, inUV ).xyzw;

	data.vertexIndex = tmp.xyz;
	return float4( CalcFaceNormal( data ),1 );
}

//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique RenderScene
{
    pass P0
    {          
		PixelShader = compile ps_3_0 GenFaceNormalTopoMap();
    }
}



does anyone have a clue why this is not working properly? [Edited by - Slaaitjuh on May 8, 2008 2:37:24 AM]

Share this post


Link to post
Share on other sites
i read about problems around texture sizes beeing a multiply by two, but i don't think this is the problem. The rendertarget is 128x64 and the map where it should read from is 64x64.

Share this post


Link to post
Share on other sites
i just copied the original map to a rendertarget of the same size and same format and then the wrapping and stuff works great. This is confusing to me, sincei just load the texture by Texture.Load(device,byte[]); This is the offsetmap, which contains all positions for the actual vertices.

does anyone know how this can be working but not directly from that map?

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

Sign in to follow this