Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 Nov 2010
Offline Last Active Jul 20 2014 07:09 PM

Topics I've Started

SOLVED: Compute shader atomic shared variable problem

26 June 2014 - 09:05 AM

SOLUTION: Ugh. Don't do 

    minDepth = atomicMin(minDepth, depth);

Just do

    atomicMin(minDepth, depth);

The assignment breaks the atomicity. 





I was doing some experiments on tiled deferred shading and ended up with a very strange problem. I tried to compute the minimum and maximum depth of each tile using two shared uints.

shared uint minDepth = 0xFFFFFFFF;
shared uint maxDepth = 0;

The idea was to compute the maximum and minimum depth using atomicMin() and atomicMax() like this:

uint depth = ...;
minDepth = atomicMin(minDepth, depth); //DON'T DO THIS, SEE ABOVE
maxDepth = atomicMax(maxDepth, depth); //DON'T DO THIS, SEE ABOVE

However, this is not working correctly. I seem to be getting synchronization problems since the result flickers a lot despite the camera not moving so the depth buffer identical. barrier() has no effect at all on the result. 




I fail to see how this could possibly happen. The atomic min and max functions do not seem to work correctly, with some pixels being randomly ignored. For testing, I decided to output the following:

if(minDepth > d){
    result = vec3(5, 0, 0);
    result = vec3(0);

In other words, if the depth of the current pixel is less than the calculated minimum depth of the tile, make it bright red. Here's the horrifying flickering result:




What am I doing wrong? How can this possibly happen when I'm using barrier()? Why isn't barrier() nor memoryBarrierShared() working as they should?


SOLVED, see above.


















Temporal Subpixel Reconstruction Antialiasing

09 June 2014 - 05:25 AM



I came up with a way of extending Subpixel Reconstruction Antialiasing with a temporal component to improve subpixel accuracy and achieve antialiasing of shading as well, while also completely preventing ghosting.


Here's a comparison of no antialiasing, SRAA and TSRAA to help catch your interest. =P




Here's a link to the article I wrote about it.

Algorithm from going from point X to point Y with specific velocities

04 May 2014 - 06:34 PM



I'm trying to come up with an algorithm for moving around objects in my 2D world. Given an object at position P0(x0, y0) with velocity V0(vx0, vy0), I want to find out exactly how I need to accelerate (how much and in which direction) to reach a new position P1, and when the object reaches P1(x1, y1) it needs to have a specific velocity V1(vx1, vy1).


Could this possibly be solved by calculating bezier curves or something like that? How would I detect and handle a situation where the object cannot accelerate fast enough to be able to follow the bezier curve (e.g. impossible movement)?

Want to use blending but all 4 color channels are taken

03 April 2014 - 07:51 AM

I would like to blend in some decals into my G-buffer, which looks like this:



GBuffer0: diffuseR diffuseG, diffuseB, unused

GBuffer1: normal1, normal2, specular, gloss

GBuffer2: emissiveR, emissiveG, emissiveB, primitive ID number



I have no problem blending with gBuffer0 and gBuffer2 since I can just use glBlendFuncSeparate to disable any modification of the alpha value, but GBuffer1 needs to have all its values blended. Is there no way of specifying a separate 5th blending value or something like that? Even a separate global value would be extremely convenient.


PS: I'm using the 4th method of this article for my normals: http://aras-p.info/texts/CompactNormalStorage.html#method04spheremap.

Gradient troubles with motion blur using textureGrad() and anisotropic filtering

20 March 2014 - 03:14 PM



I am trying to implement motion blur for my particles by abusing anisotropic filtering. The idea is to use a particle texture with premultiplied alpha, enable 16x anisotropic filtering and set the clamp mode to GL_CLAMP_TO_BORDER (fade to vec4(0, 0, 0, 0) on edges). Theoretically, I could then sample the texture using textureGrad() with custom gradients to sample 16 pixels at a time from the particle texture.  I've computed correct motion vectors in pixels for my particles and increased their size to allow them to blur over their edges. However, I am having trouble with calculating correct gradients to achieve my blur. I have a very hard time wrapping my head around the gradients affect the sample pattern of anisotropic filtering. It's worth noting that my particle sprites are always screen aligned and unrotated.


Here are the relevant parts of my fragment shader so far:

uniform sampler2D particleTexture;

uniform float motionBlurMaxRadius;

in vec2 gTexCoord;
in vec2 gMotionVector;

void main(){
    float length = max(0.0001, sqrt(dot(gMotionVector, gMotionVector)));
    float clampedLength = min(motionBlurMaxRadius, length);
    vec2 dfdx = dFdx(gTexCoord);
    vec2 dfdy = dFdy(gTexCoord);
    vec2 gx = dfdx + gMotionVector * clampedLength / length;
    vec2 gy = dfdy + gMotionVector * clampedLength / length;
    vec4 textureResult = textureGrad(particleTexture, gTexCoord, gx, gy);

    //soft depth test, write to framebuffer, etc.












The super small sparks work pretty well, but the fire and smoke is blurred beyond recognition... I just don't know how I should modify the gradient to achieve a certain amount of blur in screen space! Any help is appreciated!