• Create Account

# mr_malee

Member Since 18 Oct 2007
Offline Last Active Jan 13 2016 06:15 PM

### In Topic: Find parabola velocity needed to reach a point with air resistance

23 July 2015 - 11:40 AM

Ok thanks. I have no idea what a polynomial is, but I'm going to do some reading.

so let's say

t = 3,

start position = 0,0,

end position = 10,5

gravity: -9.81

drag: 0.5

### In Topic: Direct Compute, extracting bounds of pixels

12 May 2015 - 01:32 PM

Thanks yeah this shader is for a specific sized texture

### In Topic: Direct Compute, extracting bounds of pixels

12 May 2015 - 11:59 AM

You are a life saver. I finally got it working. I didn't realize that making a reference to bounds[0] was copying it to a new variable!

If I use bounds[0] in the InterlockedMin function, it saves my data

final working code:

#pragma kernel CSMain

struct Bound {
uint minX;
uint minY;
uint maxX;
uint maxY;
};

Texture2D<float4> tex;
RWStructuredBuffer<Bound> bounds : register(u0);

void CSMain (uint2 pos : SV_DispatchThreadID) {

float4 color = tex[pos];

if (color.r == 0 && color.g == 0 && color.b == 0) {

InterlockedMin(bounds[0].minX, pos.x);
InterlockedMax(bounds[0].maxX, pos.x);
InterlockedMin(bounds[0].minY, pos.y);
InterlockedMax(bounds[0].maxY, pos.y);
}
}

Thanks again

### In Topic: Direct Compute, extracting bounds of pixels

11 May 2015 - 08:51 PM

Ok thanks. So what's happening is multiple threads are accessing the bounds[0] and modifying that value in random order?

You mentioned atomic computations. I've tried implementing the InterlockedMin on a groupshared object without success:

groupshared Bound boundary[1];

void CSMain (uint2 pos : SV_DispatchThreadID) {

Bound b = boundary[0];

InterlockedMin(b.minX, (float)pos.x);
}

But I just get this error:

"interlocked targets must be groupshared or UAV"

How do you define a group shared object?

### In Topic: Direct Compute, extracting bounds of pixels

11 May 2015 - 07:55 PM

This works, but is really really really slow. 5fps

void CSMain (uint2 id : SV_DispatchThreadID) {

uint w, h;
tex.GetDimensions(w, h);

uint2 pos;

Bound b = bounds[0];

for (pos.x = 0; pos.x < w; pos.x++) {

for (pos.y = 0; pos.y < h; pos.y++) {

float4 color = tex[pos];

if (color.r == 0 && color.g == 0 && color.b == 0) {

b.minX = min(b.minX, pos.x);
b.minY = min(b.minY, pos.y);
b.maxX = max(b.maxX, pos.x);
b.maxY = max(b.maxY, pos.y);
}
}
}

bounds[0] = b;
}

How can I translate that into a threaded version without loops?

PARTNERS