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

How can I get the correct color value of a Texture2D in a compute shader?,

$
0
0
I would like to get the red, green and blue color values of a specific pixel in a compute shader. But unfortunately the values I get are always lower than the correct value unless it is 0 or 1. To test this I have created a shader that writes a certain color in a pixel: fixed4 frag() : SV_Target { return _Color; } And read the value in the compute shader: RWStructuredBuffer _Color; Texture2D _Source; ... if (dispatchThreadId.x == 990 & dispatchThreadId.y == 1038) { float3 color = _Source[dispatchThreadId].rgb; _Color.x = color.r; } The compute shader is called in OnRenderImage: private void OnRenderImage(RenderTexture source, RenderTexture destination) { int kernel = m_ComputeShader.FindKernel("KCompute"); m_ComputeShader.SetBuffer(kernel, "_Color", m_Buffer); m_ComputeShader.SetTexture(kernel, "_Source", source); m_ComputeShader.Dispatch(kernel, Mathf.CeilToInt(source.width / 16f), Mathf.CeilToInt(source.height / 16f), 1); } Unfortunately the written and the read values are not equals. If I write for example a 0.5 in the shader, I get a 0.2 in the compute shader. Only if a 0 or a 1 is written, it is the same in the compute shader. I am pretty sure that the writing is correct, as I exported the Texture as png in the OnRenderImage and validated the pixel color of the png in Gimp. Do you have any ideas how I can get the correct values? Does it perhaps have something to do with the sRGB? ,

Viewing all articles
Browse latest Browse all 287

Latest Images

Trending Articles



Latest Images

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