Jump to content

  • Log In with Google      Sign In   
  • Create Account


How much to tessellate?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
31 replies to this topic

#21 Jason Z   Crossbones+   -  Reputation: 3760

Like
1Likes
Like

Posted 25 April 2013 - 07:30 PM

I'm not sure how to get SharpDX to do it, but in general the first instance of a DLL that can be found either in the application's directory or the path will get loaded.  So I would start out with putting it into your executable directory and see if that works for you.

 

Even for the native C++ side I have to copy that DLL to the executable folder, so it isn't a problem limited to SharpDX.



Sponsor:

#22 MJP   Moderators   -  Reputation: 8741

Like
2Likes
Like

Posted 26 April 2013 - 12:02 AM

You might be able to just directly call D3DCompile from that DLL using p/invoke.



#23 unbird   Crossbones+   -  Reputation: 4007

Like
1Likes
Like

Posted 26 April 2013 - 03:00 AM

An alternative is to use the command line compiler (that's how I checked your shader), i.e. generate binaries offline and load them in your app.

fxc.exe /E HS /T hs_5_0 /Fo hs.fxo /Fx hs.asm hs.hlsl

Hmmm, can't seem to force SlimDX to load the newer DLL with that copy trick. I hope your thread in the SharpDX forum will reveal something.

#24 cephalo   Members   -  Reputation: 457

Like
0Likes
Like

Posted 26 April 2013 - 08:39 AM

Hmm, I'm not having much luck with the command line compiler. Here is my result.
 
C:\Users\rjm\Documents\Visual Studio 2012\Projects\HexMapDemo\HexMapDemo\bin\Deb
ug\Content\Effects\HexVertTri_HS.fx(1,1): error X3000: Illegal character in shad
er file
 
Here is the exact command I used:
C:\Users\rjm\Documents\Visual Studio 2012\Projects\HexMapDemo\HexMapDemo\bin\Deb
ug\Content\Effects>fxc /E HS /T hs_5_0 /Fo HexVertTri_HS.fxo /Fx HexVertTri_HS.a
sm HexVertTri_HS.fx
 
EDIT: Ooh, just got a reply from xoofx over at SharpDX. I'm going to try to change over my SharpDX build. Hopefully that will make everything as easy as before.

Edited by cephalo, 26 April 2013 - 08:49 AM.


#25 cephalo   Members   -  Reputation: 457

Like
1Likes
Like

Posted 26 April 2013 - 12:33 PM

Ok, I have that squared away and I'm back in business! My algorithm works great, I just have to tweak it so that both low detail and high detail aren't so quick to appear. I can handle that.

 

After this I'll need to see some performance info of some kind, so I need to print text. I'll open a new thread for that. My research on that topic has given me some conflicting info.



#26 unbird   Crossbones+   -  Reputation: 4007

Like
1Likes
Like

Posted 26 April 2013 - 01:54 PM

 HexVertTri_HS.fx(1,1): error X3000: Illegal character in shader file

Ah well, the compiler still can't cope with unicode source. At least it should give a more meaningful error. You need a file in pure ASCII/ANSI, e.g. a text file created in Visual Studio will be UTF-8 encoded, which starts with the so-called BOM-char, which in turn makes fxc hiccup. Use an alternative text editor (Notepad++) or copy a file that works and clear it (VS will usually not screw that at least).

 

Nice to hear it's working.



#27 Jason Z   Crossbones+   -  Reputation: 3760

Like
1Likes
Like

Posted 26 April 2013 - 03:48 PM

Ok, I have that squared away and I'm back in business! My algorithm works great, I just have to tweak it so that both low detail and high detail aren't so quick to appear. I can handle that.

 

After this I'll need to see some performance info of some kind, so I need to print text. I'll open a new thread for that. My research on that topic has given me some conflicting info.

Nice job sticking to it - so where is the obligatory screen shot showing us the low and high res triangles all at once???



#28 cephalo   Members   -  Reputation: 457

Like
1Likes
Like

Posted 26 April 2013 - 07:26 PM

 

Nice job sticking to it - so where is the obligatory screen shot showing us the low and high res triangles all at once???

 

Alrighty then. I'm actually still futzing with the LOD settings, but I do have an interesting discovery. Here is the new code, I tried to do some culling of the backward triangle patches, but in this case the surface can protrude too much and the gaps are visible. I also tried to greatly reduce the tessellation in that case, but the popping was very noticeable.

PatchConstants PatchHS(InputPatch<VertexOutput,10> cp, uint patchID : SV_PrimitiveID)
{
	PatchConstants pt;

	float4 corner0 = mul(float4(cp[0].PositionWorld,1.0f),ViewProjection);
	float4 corner1 = mul(float4(cp[1].PositionWorld,1.0f),ViewProjection);
	float4 corner2 = mul(float4(cp[2].PositionWorld,1.0f),ViewProjection);

	corner0 = corner0/(corner0.w + 0.00001f);
	corner1 = corner1/(corner1.w + 0.00001f);
	corner2 = corner2/(corner2.w + 0.00001f);

	static const float dMax = 1.5f;
	static const float dMin = 0.04f;

	float dist0 = distance(corner1.xy,corner2.xy);
	float dist1 = distance(corner2.xy,corner0.xy);
	float dist2 = distance(corner0.xy,corner1.xy);

	pt.EdgeTess[0] = 64.0f * saturate((dist0 + dMin)/(dMax + dMin));

	pt.EdgeTess[1] = 64.0f * saturate((dist1 + dMin)/(dMax + dMin));

	pt.EdgeTess[2] = 64.0f * saturate((dist2 + dMin)/(dMax + dMin));

	pt.InsideTess = min(pt.EdgeTess[0],min(pt.EdgeTess[1],pt.EdgeTess[2]));

	//corner0.z = 0.0f;
	//corner1.z = 0.0f;
	//corner2.z = 0.0f;

	//float3 winding = cross(corner1 - corner0,corner2 - corner0);
	//if(winding.z > 0)
	//{
	//	pt.InsideTess = 1.0f;
	//}

	return pt;
}

Here is the interesting part. I originally chose 'fractional_even' arbitrarily. Switching to 'fractional_odd' can completely change the look of the scene. First is the view from central Taffy Mountain looking west with fractional even partitioning:

CTLookingWestEven.jpg

 

Now the from the same vantage with fractional odd partitioning:

CTLookingWestOdd.jpg

 

At least in this particular case, I would say that fractional odd has far fewer undesireable artifacts! It's an interesting consequence.



#29 unbird   Crossbones+   -  Reputation: 4007

Like
1Likes
Like

Posted 27 April 2013 - 04:37 AM

Taffy Mountains. Sweet.biggrin.png

Interesting, now I finally get it with that odd/even difference. Seems like even always has some tesselation, since it "starts" at the edges center. See here.

fractional_even with 1.2 for all factors
6e3afa251180131.jpg

fractional_odd with 1.2 for all factors
28f657251180133.jpg
(Oops, should have used a lower resolution, the thumbnails came out black, sorry)

With even, the higher tesselation starts only with factors > 2 it seems. So for your plateaus a odd makes more sense. Shouldn't make a difference with very high tesselation, though.

Backface culling ? You need to give it some bias and you can actually eliminate the patch completely (so it doesn't get rasterized at all) by setting the factors to zero:
// view: view direction from camera to patch 
if(dot(view, faceNormal) < - BackfaceCullBias)
{
    pt.EdgeTess[0] = 0;
    pt.EdgeTess[1] = 0;
    pt.EdgeTess[2] = 0;
    pt.InsideTess  = 0;
    return pt;
}
Here I use a (experimental) bias of 0.3. See how the top of the "cube" still gets rasterized.
0f461e251180100.jpg

The same with a sphere:
8aed3f251180118.jpg

Not sure if this of use for your case, but this "Fresnel term" (dot(view, normal)) can also be used to adaptively tesselate a mesh's contour:
a89f1a251180127.jpg

PS: The distance based factors are deliberately exaggerated here, so I can check the behaviour better.

Edit: Pfff, I got the odd/even mixed up with the triangle. Corrected.

Edited by unbird, 27 April 2013 - 06:58 AM.


#30 Jason Z   Crossbones+   -  Reputation: 3760

Like
2Likes
Like

Posted 27 April 2013 - 06:31 AM

With even, the higher tesselation starts only with factors > 2 it seems. So for your plateaus a odd makes more sense. Shouldn't make a difference with very high tesselation, though.

That's actually the definition of the even/odd partitioning modes.  Even rounds to even factors while odd rounds to odd factors.  So for even, you end up with a factor in the 2, 4, 6, 8, ..., 64 range, while for odd you get 1, 3, 5, ..., 63.  If you take this into account when designing the algorithm that produces the tessellation factors, then you will be in good shape and can set the minimums accordingly to ensure you get at least a little bit of tessellation.

 

The same can be said for the other two types (integer and pow2) as they just define the "steps" in your tessellation factors.



#31 cephalo   Members   -  Reputation: 457

Like
0Likes
Like

Posted 27 April 2013 - 06:35 AM

The problem with fractional_even is that you get a very tight mass of triangles mid edge, and very large triangles in the corners. Obviously this has potential for artifacts. With fractional_odd this difference is much less pronounced. I'm not sure where anyone would ever want to use fractional_even unless you had very specific topology that benefitted from that imbalance somehow. Here are some wireframe results:

 

fractional_even:

PartitioningEven.jpg

 

fractional_odd:

PartitioningOdd.jpg



#32 cephalo   Members   -  Reputation: 457

Like
0Likes
Like

Posted 27 April 2013 - 07:33 AM

Backface culling ? You need to give it some bias and you can actually eliminate the patch completely (so it doesn't get rasterized at all) by setting the factors to zero:

 

This works great for me unbird. Thanks for the tip! I have to set my bias kinda high, but I'm still getting rid of enough patches for a noticible frame rate boost.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS