Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 24 Jul 2013
Offline Last Active Apr 24 2015 12:19 PM

Topics I've Started

Bezier Teapot Tessellation

07 April 2015 - 10:29 AM



I've been messing around with the tessellation pipeline and Bezier surfaces and I seem to have run into a strange artefact that I just can't figure out: it only seems to appear for the teapot model (from here) but surely this widely used model isn't broken? Here's what happens when I'm tessellating it. My method is similar to the one presented here slides 23-25, except it seems that the Bezier evaluation function given on those slides is summing u and v basis functions backwards, hence my version evaluates the control points as follows:

int ptIndex = 0;
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 4; ++j) {
position += patch[ptIndex].position * bu[i] * bv[j];
du += patch[ptIndex].position * dbu[i] * bv[j];
dv += patch[ptIndex].position * bu[i] * dbv[j];
Here bu/bv and dbu/dbv are the Bernstein polynomials/derivatives of Bernstein polynomials for the tessellated uv parameter coordinates. If I swap the polynomial multiplication order, e.g. for the position set multiplication to bv[i] * bu[j], then I get the exact same, inside-out model as with the copy-paste code from the given slides (the artefact is still there, just need to move the camera inside of the model to see it). After debugging this for the entire day I'm beginning to think it might be a problem with the model but like I said - seems unlikely considering the popularity of the model. Does anyone have any experience with Bezier teapot tessellation and could chip in? I've tried the other models from Newell's teaset, i.e. the spoon and the cup, and neither seemed to have any similar artefacts. If anyone could recommend any (advanced) test Bezier models, I'd be grateful!
Thanks in advance!

Heightfield Normals

13 February 2015 - 12:59 PM



I've implemented a SW equation solver and everything seems to be working OK, except for the normals. Here's what I mean: http://postimg.org/image/d3kah7ow5/


Here's how I'm calculating the normals in the vertex shader:

float3 tangent = float3(1.0f, (r - l) / (2.0f * dx), 0.0f);
float3 bitangent = float3(0.0f, (t - b) / (2.0f * dx), 1.0f);
float3 normal = cross(bitangent, tangent);
normal = normalize(normal);

r/l/t/b are left/right/top/bottom neighbours.

I can fake the normal upwards by scaling the xz components but that doesn't seem like the most optimum way of doing it. Surely there's a better way?


Thanks in advance!

Shallow Water

16 January 2015 - 11:04 AM



I've been experimenting with the shallow water equations but I can't seem to get my implementation correct. I'm following this except I'm doing everything on the GPU. I'm not sure where I keep going wrong: see here. From my experimentations with the full Navier-Stokes equations, this makes sense: I remember getting visually similar results (in 2D) where the circle forms into a square-like corner (plotted a circle with velocity (1,1) at every pixel). But this only happened when I stopped the simulation after the advection step ("skipped" projection). Not sure what is happening here. I've tried changing the signs when sampling data as well as switching the order of operations around but nothing seems to work. At one point I ended up with this, which is obviously not correct.


Here are my simulation kernels (I won't post my advection kernel as it is the same one I used for my full NS solver; also note that using a staggered grid whereby a single pixel represents left-bottom pair of velocities for velocity kernels (boundaries are set appropriately to account for the array size differences)):


UpdateHeight kernel

float4 PSMain(PSInput input) : SV_TARGET {
float2 texCoord = input.position.xy * recTexDimensions.xy;
float vL = velocity.Sample(pointSampler, texCoord).x;
float vR = velocity.Sample(pointSampler, texCoord + float2(recTexDimensions.x, 0.0f)).x;
float vT = velocity.Sample(pointSampler, texCoord + float2(0.0f, recTexDimensions.y)).y;
float vB = velocity.Sample(pointSampler, texCoord).y;
float h = height.Sample(pointSampler, texCoord).x;
float newH = h - h * ((vR - vL) * recTexDimensions.x + (vT - vB) * recTexDimensions.y) * dt;
return float4(newH, 0.0f, 0.0f, 0.0f);
float4 PSMain(PSInput input) : SV_TARGET {
float2 texCoord = input.position.xy * recTexDimensions.xy;
float u = velocity.Sample(pointSampler, texCoord).x;
float hL = height.Sample(pointSampler, texCoord - float2(recTexDimensions.x, 0.0f)).x;
float hR = height.Sample(pointSampler, texCoord).x;
float uNew = u + g * (hL - hR) * recTexDimensions.x * dt;
return float4(uNew, 0.0f, 0.0f, 0.0f);
float4 PSMain(PSInput input) : SV_TARGET {
float2 texCoord = input.position.xy * recTexDimensions.xy;
float v = velocity.Sample(pointSampler, texCoord).y;
float hB = height.Sample(pointSampler, texCoord - float2(0.0f, recTexDimensions.y)).x;
float hT = height.Sample(pointSampler, texCoord).x;
float vNew = v + g * (hB - hT) * recTexDimensions.y * dt;
return float4(0.0f, vNew, 0.0f, 0.0f);


I've literally spent the entire day debugging this and I've got no idea why nothing seems to work... Hopefully some of you guys have implemented this before and can help me out.


Thanks in advance!

Renormalizing bilinear interpolation weights

03 January 2015 - 12:24 PM



I need to change the default bilinear interpolation functionality to only use known values for interpolation by biasing the weights based on the contents of the 4 pixels, e.g. if one of the four pixels is (0.0, 0.0, 0.0, 0.0) then bias the lerp() function towards the nonzero neighbouring pixel. At least that's what I've understood I need to do for extrapolating velocities (stored in textures) for my fluid simulation, direct quote here:



We then go through the levels from finest to coarsest and obtain velocities by tri-linear interpolation of the velocities of the previous level using only known velocities and renormalizing the interpolation weights accordingly.



I've written a bilinear interpolation function based on what I've found on the web:

static const float2 recTexDim = float2(1.0f / 48.0f, 1.0f / 48.0f); // as a test case, the source image is 48x48
float4 bilerp(float2 texCoord) {
float2 t = frac(texCoord / recTexDim);
float4 tl = source.Sample(pointSampler, texCoord);
float4 tr = source.Sample(pointSampler, texCoord + float2(recTexDim.x, 0.0f));
float4 bl = source.Sample(pointSampler, texCoord + float2(0.0f, recTexDim.y));
float4 br = source.Sample(pointSampler, texCoord + float2(recTexDim.x, recTexDim.y));
return lerp(lerp(tl, tr, t.x), lerp(bl, br, t.x), t.y);
float4 PSMain(PSInput input) : SV_TARGET {
float4 custom =  bilerp(input.texCoord);
float4 builtIn = source.Sample(linearSampler, input.texCoord);
return abs(custom - builtIn);

If my code were correct, the resulting image should be all black (i.e. no difference between the interpolation functions). However I get the following result: http://postimg.org/image/3walbutj1/


I'm not sure where I'm going wrong here. Also, have I even understood the "renormalizing interpolation weights" bit correctly?


Thanks in advance!

Level sets and loss of volume

04 October 2014 - 01:50 PM



I've been trying to convert my simple 2D fluid solver to a liquid solver with a free surface. For that I've introduced the level set method into the application. However, I seem to be losing mass/volume at a ridiculous speed. Here are two videos showing exactly what I mean: I switch between rendering the advected color vector and the the level set where phi < 0 (i.e. the inside of the liquid, rendered as black).





From what I've read from the papers, the problem is that after advection, phi doesn't hold the signed distance anymore and needs to be reinitialized. However, I've got no idea how one would do it. Some papers have mentioned fast marching method but from what I can understand, it doesn't suit well for GPUs (my solver is completely GPU based). Some other papers mentioned Eikonal solvers in their references but I literally have no idea what/how to proceed.


Any help would be greatly appreciated: bonus points if anyone can link to a tutorial/instructional text that isn't a high-level implementation paper glancing over details.


Here's how I've defined the signed distance initially:

float2 p = input.position.xy - pointCenter;
float s = length(p) - radius;
return float4(s, s, s, 1.0f);
Thanks in advance!