Quantcast
Channel: Questions in topic: "compute shader"
Viewing all articles
Browse latest Browse all 287

Using compute shader to return whether texture has certain colour

$
0
0
I'm writing a Compute Shader which I need to do a very simple task: check whether any pixel in the image has green == 1 and blue > 0.5. (For clarity - the green channel is a 2d "light" and the blue channel is that lights "trail" - I want to detect whenever the light crosses back over its trail.) I'm as far as displaying the overlap (shown in white) for debugging purposes, but I have no idea how to do something as simple as return a value indicating whether the texture actually contains an overlap. My confusion stems from how threads work. I have a float buffer with room for a single float - I simply need a 1 or 0. For clarification the following two images show a "before" and "after" - all I need is a single "true" value telling me that some white exists in the second image. ![Before][1] ![After][2] The compute shader is as follows: #pragma kernel CSMain Texture2D InputTexture; RWTexture2D OutputTexture; RWStructuredBuffer FloatBuffer; [numthreads(8,8,1)] void CSMain(uint3 id : SV_DispatchThreadID) { // need to detect any region where g == 1 and blue > 0.5 float green = InputTexture[id.xy].g; float blue = round(InputTexture[id.xy].b); float overlap = round((green + blue) / 2.0); OutputTexture[id.xy] = float4(overlap, overlap, overlap, 1); // answer here?? Note that the output texture is only for debugging purposes FloatBuffer[0] = ?? } [1]: /storage/temp/108791-image1.png [2]: /storage/temp/108792-image2.png

Viewing all articles
Browse latest Browse all 287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>