Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

geoclipmaps, morph cracks

This topic is 3860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to implement geoclipmaps.. and everything works fine.. except i get small cracks between levels... i think it has something do with i get wrong cz/morph height values... but i dont knwo why... the morphing seems to work fine otherwise (when not at the edges)... but maybe thats cuzz the small difference which is causing the cracks at the edges... im even suspecting that maybe somthing goes wring when packing and unpacking the heightvalues... dont know what though...
//heightmap update shader

OutputVS GeoVS(float3 posL : POSITION0, float2 CurTex : TEXCOORD0)
{
	OutputVS outVS = (OutputVS)0;	

	outVS.posH = float4(posL, 1.0f);
	
        // Get texture coordinates for getting data from baseheightmap
	float2 ClipPos =( (posL.xy+1.0)*0.5-float2(0.5,0.5));	
	
	float ratio = ClipSize/(Scale.x);
	ClipPos.x = (ClipPos.x+Update.x) * ratio;
	ClipPos.y = (ClipPos.y+Update.y) * ratio;	
	
	outVS.CurTex = ClipPos.xy;

    return outVS;
}

float4 GeoPS(float2 CurTex : TEXCOORD0) : COLOR
{

	float yf = floor(tex2D(BaseMapSampler, CurTex).r*65535); // current level
	float yc = yf; // previous level (coraser)
	
	
        float2 odd = ceil(CurTex*4096.0f)/Scale.y % 2;	// check if vertex is odd				
			
	if (any(odd)) // if odd then pick the right values
	{
		float2 t1 = float2(odd)*float2(1.0f, -1.0f);
		float2 t2 = float2(-odd)*float2(1.0f, -1.0f);
	
		float xz1 = tex2D(BaseMapSampler, CurTex+(t1*Scale.y)/4096.0f).r;
		float xz2 = tex2D(BaseMapSampler, CurTex+(t2*Scale.y)/4096.0f).r;
		yc = floor(0.5f*(xz1+xz2)*65535);				
	}
  
	double yf_yd = (yf)*65535+(yc); // pack values into 32 bit

	return yf_yd.rrrr;
}


// geoclipmap shader

OutputVS BaseVS(float3 posL : POSITION0, float2 tex0: TEXCOORD0)
{
	OutputVS outVS; 		

	float3 Pos = posL;
	
	float BlockSize = MeshSize*Scale.x*4+2;
	
	float3 WorldPos = Pos*Scale.x+MeshPos;
	
	float2 alpha = clamp(( abs(WorldPos.xz - floor(EyePos.xz)) - ((BlockSize-1)*0.5f-BlockSize*0.1f-1.0f) )/(BlockSize*0.1f), 0.0, 1.0);		
	alpha.x = max(alpha.x, alpha.y);	
	
	float2 uv = WorldPos.xz/(ClipSize*Scale.x)-float2(0.5,0.5f);
	uv.y = 1.0f - uv.y;

	double yf_zd = tex2Dlod(HeightMap, float4(uv, 0.0, 0.0)).r;
    
    double yf   = floor(yf_zd/65535.0);
    double yd   = frac(yf_zd/65535.0)*65535;

	float y = yf*(1.0f-alpha.x) + alpha.x * yd;		
			
	WorldPos.y = y/150.0f;
		
	outVS.posH = mul(float4(WorldPos,1.0f), gWVP);
	
	outVS.tex0 = WorldPos.xz/4096.0f;
	return outVS;
}

float4 BasePS(float2 tex0 : TEXCOORD0) : COLOR
{
	float3 color = tex2D(Tex, tex0).rgb;//tex0.rrr/100.0f;
	
	return float4(color,0.0f);//float4(texColor,1.0f);
}





Free Image Hosting at www.ImageShack.us EDIT:: after some debugging ive found that something is wrong with packing the values... using the following code i get cracks even where there shouldnt (at even vertices...) float4 GeoPS(float2 CurTex : TEXCOORD0) : COLOR { float yf = floor(tex2D(BaseMapSampler, CurTex).r*65535); // current level float yc = yf; // previous level (coraser) double yf_yd = (yf)*65535+(yc); // pack values into 32 bit return yf_yd.rrrr; } whats causing this? [Edited by - Dragon_Strike on October 30, 2007 4:02:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
if you store the heights of the next layer per vertex then you can set the vertices at the edge to the proper height to match up. this is what the original algorithm does. you could also stitch together the seams with additional triangles.

Share this post


Link to post
Share on other sites
Quote:
Original post by yahastu
if you store the heights of the next layer per vertex then you can set the vertices at the edge to the proper height to match up. this is what the original algorithm does. y


thats what im tryin to do...

double yf_yd = (yf)*65535+(yc);

where yf is the current height and yc is hte previous levels' height at that point... however for some reason yc becomes wrong when i unpack the value again... or was before?

Share this post


Link to post
Share on other sites
This is what I do to pack the two values together (floats fData is the current level and fNextData is the coarser level):

fNextData = fNextData - fData ; // Convert to height difference
fNextData = (fNextData + 32768.0f) / 65536.0f;
fData = fData + fNextData;

Then in the vertex shader I have:

float yf = floor(inVS.heightshadow.x);
float yd = frac(inVS.heightshadow.x)*65536-32768;
float2 alpha = (abs(inVS.gridPos - ViewerPos.xz) - AlphaOffset) * OneOverWidth;
alpha = clamp( alpha, 0, 1);
alpha.x = max(alpha.x, alpha.y);
// Note yd is the difference from the current level and the next coarser one
float y = yf + alpha.x * yd;
y = y * YScaleFactor;

where yf is the current level and yd is the coarser level. This is pretty much a rip from the GPU Gems 2 chapter, although I put the heights into a vertex stream rather than a texture as I'm working in Shader 2.0 (old ATI Radeom Mobility 9700 video chip)

Formski

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!