I'm trying to make a compute shader that uses Lighting.cginc, but it always fails because fixed4 (and fixed in general) is not a recognized variable type.
Shader error in 'RaymarchComputeShaderV2.compute': unrecognized identifier 'fixed4' at kernel CSMain at UnityLightingCommon.cginc(4) (on d3d11)
Commenting out `#include "Lighting.cginc"` and instead adding `static fixed testing = 0` gives a similar error.
Shader error in 'RaymarchComputeShaderV2.compute': unrecognized identifier 'fixed' at kernel CSMain at RaymarchComputeShaderV2.compute(9) (on d3d11)
Why doesn't the fixed variable type work for me? I am running 2019.3.0a10
↧
unrecognized identifier 'fixed4' in Compute Shader
↧
Use compute shader to convert RenderTexture to Vector4 array
I am making a picture analyzer which needs the accurate values of color. When I tried to parse float values from compute shader to my script via **Texture2D**, it's not accurate. For example, when parsing float **0.5** via the r channel texture, it will first convert to value **127**, which represents "**half of a channel**". Then in my script, I use Texture2D.GetPixel(x, y) to read the color, it will convert **127** to **127/255** back. So **float 0.5 from compute shader to my script will be converted to 0.498039……**, which isn't I expected.
Therefore, I want to **use an array to read the output value but not the texture**.
However, It has some problem. I do a test. Here are my codes:
###Compute shader
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D input;
RWStructuredBuffer output;
[numthreads(16,16,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!
uint index = id.x * 16 + id.y;
//There should be some operations here, then I get the final value
//Operations.....................
//Then get the result here
float4 finalValue = input[id.xy];
output[index] = finalValue;
}
###Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestParse : MonoBehaviour
{
public ComputeShader shader;
public RenderTexture input;
public Material material;
private Vector4[] output;
private ComputeBuffer buffer;
private int kernel;
private Texture2D texture;
// Start is called before the first frame update
void Start()
{
output = new Vector4[16 * 16];
buffer = new ComputeBuffer(16 * 16, 4 * sizeof(float));
kernel = shader.FindKernel("CSMain");
input.enableRandomWrite = true;
shader.SetTexture(kernel, "input", input);
shader.SetBuffer(kernel, "output", buffer);
texture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
texture.filterMode = FilterMode.Point;
material.SetTexture("_MainTex", texture);
}
// Update is called once per frame
void Update()
{
shader.Dispatch(kernel, 16, 16, 1);
buffer.GetData(output);
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
int index = i * 16 + j;
texture.SetPixel(i, j, new Color(output[index].x, output[index].y, output[index].z, output[index].w));
}
}
texture.Apply();
}
private void OnDisable()
{
buffer.Release();
}
}
In this example, I can parse the **RenderTexture** to the compute shader, then copy the value to a **Vector4** array, then set the color of the test **Texture2D** based on the array. So in theory, the colors of the test **Texture2D** will be the same as the colors of the input **RenderTexture**.
However, this is what I get:
![alt text][1]
![alt text][2]
[1]: /storage/temp/143954-computeshadererror.png
[2]: /storage/temp/143955-gif-animation-001.gif
Does anyone knows how to solve this problem? If it can't be solve, do you know why? Thanks.
↧
↧
Creating a native UAV into a meshes native vertex buffer (DX11)
I have a native plugin which generates mesh data using compute shaders. My ideal solution would be to pass down the native vertex buffer pointer down to the plugin, create a UAV into it, and bind that directly to my compute shader.
Attempting to create the UAV returns an invalid args result. The vertex buffer appears to not be a structured buffer (buffer description has a structured byte stride of 0). Could this be why this method will not work?
↧
#include not finding compute file
I'm working on a shader that requires me to be able to 'latch on' to another compute shader.
I'm using #Include "/Includes/LookupTables.compute" and that shader is in a folder named Includes and I've made sure everything is right. I tried doing Assests/Scripts/...etc and that doesnt work either. I also tried the .cginc extension and that doesn't work either. I look at some docs for unity and it says that #include is no longer supported. If so then what can I use?
↧
My mesh is spagetti??!
Hey! So I decided to calculate noise on a compute shader for my infinite terrain. My issue is when I get the data the mesh I get in return is spaggetti. Like they arent connecting to the correct vertices. What I do is give the shader the vertices and it returns the vertices with the height data. I know that it wont return the vertices in order so I made a triangle struct to make sure they return correctly but it doesn't seem to work. Is there something I'm missing that I need to take in to account while working with compute shaders? Thanks
↧
↧
Generating a plane with a compute shader.
I'm making a JRPG style dungeon crawler, and I'm currently trying to generate the floor. I currently have the ability to generate the floor using the mesh generation code given in the Brackeys tutorial on the same topic. Unfortunately, "for loops" have a nasty habit of locking up Unity until they're done. It's the reason why infinite loops are so dangerous. Because I wanted to show a loading animation while the mesh generates, I decided to do it inside of a coroutine, but then it becomes extremely slow. Even a 32 x 32 grid takes too long to generate.
That's when I learned about Compute shaders. They're apparently capable of running a piece of code many times in parallel, thus it seems like the perfect fix.
However, I've been looking into them for several days and I'm still having trouble understanding exactly how they work.
If it's possible, could anyone please push me in the right direction.
↧
Create Mesh from Triangle Data Created on ComputeShader
Hi!
I have recently finished working on a terrain generation system that utilizes the GPU to generate the noise for the terrain and calculate the vertices and triangles of each terrain chunk.
After I got it fully working, I have been trying to optimize it as best as I can, and I noticed that calling `ComputeBuffer.GetData()` on a buffer with a large amount of data stored in it can be very costly.
One such buffer is the buffer that stores the triangulation data of the mesh of a terrain chunk, which is later used to create the actual mesh for the terrain chunk `GameObject` in the scene.
So my question is this: is there a way to skip getting the data from the GPU back to the CPU to generate the mesh? i.e is there a way to generate the mesh for a `GameObject` in the scene straight from the `ComputeShader` I use to generate the triangles in the first place?
Thank you!
I have recently finished working on a terrain generation system that utilizes the GPU to generate the noise for the terrain and calculate the vertices and triangles of each terrain chunk.
After I got it fully working, I have been trying to optimize it as best as I can, and I noticed that calling `ComputeBuffer.GetData()` on a buffer with a large amount of data stored in it can be very costly.
One such buffer is the buffer that stores the triangulation data of the mesh of a terrain chunk, which is later used to create the actual mesh for the terrain chunk `GameObject` in the scene.
So my question is this: is there a way to skip getting the data from the GPU back to the CPU to generate the mesh? i.e is there a way to generate the mesh for a `GameObject` in the scene straight from the `ComputeShader` I use to generate the triangles in the first place?
Thank you!
↧
Compute Shaders Tutorial/Docs
Searched the web for compute shaders tutorial, everything I have seen so far is shallow. I need indepth tutorial/material/books etc... cause this seems to be an important subject. Even unity's own docs is lacking tbh.
Is there a book/video/online reading material outta there that gives indepth training on compute shaders?
appreciated.
↧
Are ComputeShader dispatches sequential?
If I dispatch 3 different kernels on the same compute shader like this:
_computeShader.Dispatch(kernel1, x, y, z);
_computeShader.Dispatch(kernel2, x, y, z);
_computeShader.Dispatch(kernel3, x, y, z);
will they run in the order they are called?
↧
↧
Compute Shader threads fail randomly on mobile, but work fine on PC.
You can see here, failed threads show up as black or light blue- Dark blue vertices were fine (probably) https://cdn.discordapp.com/attachments/552308534906454017/663503305816670231/Gif_503.gif
Another gif: It appears that all 20 ish of my kernel dispatches are missing threads randomly on mobile https://cdn.discordapp.com/attachments/552308534906454017/663545642479648778/Gif_509.gif
On PC unity editor the character is solid blue, all threads execute and the simulation runs fine. No code is different between PC and mobile versions right now. Anyone ever seen something like this before? It's pretty random, like changing the series of dispatches can make the threads fail a lot less. It's not a performance problem, renderdoc reports lots of leeway.
I'm coding for the Oculus Quest, which has a tiling based mobile GPU.
↧
Shader Raycasting From Camera
Hi, I need to raycast from a secondary camera taking into account its properties (focal length, aspect ratio,etc) and then get the pixel hit in a shader for the main camera so that you can visualize what the secondary camera is exactly seeing. I hope the attached image is enough to explain the desired effect.
Thanks in advance!
![alt text][1]
[1]: /storage/temp/151041-example.png
↧
Android Crash on UpdateComputeBuffers in libunity.so
**The Problem**
I have a bunch of ComputeBuffers and RenderTextures in my 2D game, and up until recently, they were working just fine.
Now, all of a sudden I am seeing crashes after the Start() functions are run to create the ComputeBuffers. The Update() functions are never called, so its something to do with the instantiation, probably delayed a frame as it has to work on the GPU. I tested on Android, Galaxy S6 and Pixel, using release and debug builds.
I believe this is related to some setting I may have accidentally changed, and I cannot figure out what I did.
.
It is crashing on this line in /lib/arm/libunity.so:
GfxDeviceGLES::UpdateComputeResources(ComputeShaderResources const&)+184
.
**Here is the relevant ERROR message from the debug build logs:**
05-19 13:46:33.382 12588-12618/? A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 12618 (UnityGfxDeviceW), pid 12588 (dgames.blackout)
05-19 13:46:33.443 12712-12712/? A/DEBUG﹕ pid: 12588, tid: 12618, name: UnityGfxDeviceW >>> com.fivesecondgames.blackout <<<
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #00 pc 009cb81c /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceGLES::UpdateComputeResources(ComputeShaderResources const&)+184)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #01 pc 009ab3b4 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)+31428)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #02 pc 009abc48 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)+112)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #03 pc 009abbb8 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::Run()+128)
05-19 13:46:33.461 12712-12712/? A/DEBUG﹕ #04 pc 009a3764 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunGfxDeviceWorker(void*)+4)
05-19 13:46:33.461 12712-12712/? A/DEBUG﹕ #05 pc 00769c30 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (Thread::RunThreadWrapper(void*)+84)
.
**Settings**
![alt text][1]
![alt text][2]
.
**And here is the complete log from start of app till crash:**
05-19 13:46:29.815 879-6956/? I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity bnds=[35,252][237,514]} from uid 10047
05-19 13:46:29.838 879-4725/? I/ActivityManager﹕ Start proc 12588:com.fivesecondgames.blackout/u0a173 for activity com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity
05-19 13:46:30.037 12588-12588/? I/Unity﹕ onResume
05-19 13:46:30.084 12588-12604/? D/Unity﹕ SetWindow 0 0xe297e808
05-19 13:46:30.085 12588-12604/? D/Unity﹕ SetWindow 0 0xe297e808
05-19 13:46:30.109 12588-12588/? I/Unity﹕ windowFocusChanged: true
05-19 13:46:30.115 879-922/? I/ActivityManager﹕ Displayed com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity: +285ms
05-19 13:46:30.124 12588-12604/? D/Unity﹕ [VFS] Mount /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk
05-19 13:46:30.128 12588-12604/? D/Unity﹕ Loading player data from /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk/assets/bin/Data/data.unity3d
05-19 13:46:30.198 12588-12604/? I/Unity﹕ SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 4, Memory = 3754mb
05-19 13:46:30.198 12588-12604/? I/Unity﹕ SystemInfo ARM big.LITTLE configuration: 2 big (mask: 12), 2 little (mask: 3)
05-19 13:46:30.199 12588-12604/? I/Unity﹕ ApplicationInfo com.fivesecondgames.blackout version 1.0 build 15837c2c-8c67-4c38-8827-583c1d09cd63
05-19 13:46:30.199 12588-12604/? I/Unity﹕ Built from '2018.1/staging' branch, Version '2018.1.0f2 (d4d99f31acba)', Build type 'Development', Scripting Backend 'mono'
05-19 13:46:30.199 12588-12604/? D/Unity﹕ Loading player data from /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk/assets/bin/Data/data.unity3d
05-19 13:46:30.215 12588-12604/? D/Unity﹕ Failed to install Player data archive: /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk/assets/bin/Data/data.unity3d!
05-19 13:46:30.215 12588-12604/? D/Unity﹕ [EGL] Attaching window :0xe297e808
05-19 13:46:30.218 12588-12604/? D/Unity﹕ Unable to find library path for 'monobdwgc-2.0'.
05-19 13:46:30.221 12588-12604/? D/Unity﹕ Mono path[0] = '/data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk/assets/bin/Data/Managed'
05-19 13:46:30.221 12588-12604/? D/Unity﹕ Mono config path = 'assets/bin/Data/Managed/etc'
05-19 13:46:30.221 12588-12604/? D/Unity﹕ PlayerConnection initialized from /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/base.apk/assets/bin/Data (debug = 0)
05-19 13:46:30.221 12588-12604/? D/Unity﹕ PlayerConnection initialized network socket : 0.0.0.0 55379
05-19 13:46:30.221 12588-12604/? D/Unity﹕ PlayerConnection initialized unix socket : Unity-com.fivesecondgames.blackout
05-19 13:46:30.222 12588-12604/? D/Unity﹕ Multi-casting "[IP] 192.168.0.4 [Port] 55379 [Flags] 2 [Guid] 3431760615 [EditorId] 2107415186 [Version] 1048832 [Id] AndroidPlayer(Google_Pixel@192.168.0.4) [Debug] 0" to [225.0.0.222:54997]...
05-19 13:46:30.220 12604-12604/? W/UnityMain﹕ type=1400 audit(0.0:3517): avc: denied { read } for name="stat" dev="proc" ino=4026532357 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc_stat:s0 tclass=file permissive=0
05-19 13:46:30.222 12588-12604/? D/Unity﹕ Started listening to [0.0.0.0:55379]
05-19 13:46:30.298 12588-12604/? D/Unity﹕ InitializeScriptEngine OK (0xed820ee0)
05-19 13:46:30.298 12588-12604/? D/Unity﹕ PlayerConnection already initialized - listening to [0.0.0.0:55379]
05-19 13:46:30.313 12588-12604/? D/Unity﹕ Loading player data from assets/bin/Data/data.unity3d
05-19 13:46:30.317 12588-12604/? D/Unity﹕ PlayerInitEngineNoGraphics OK
05-19 13:46:30.317 12588-12604/? D/Unity﹕ AndroidGraphics::Startup window = 0xe297e808
05-19 13:46:30.317 12588-12604/? D/Unity﹕ [EGL] Attaching window :0xe297e808
05-19 13:46:30.321 12588-12604/? D/Unity﹕ [EGL] Request: ES 3.1+AEP RGB0 000 0/0
05-19 13:46:30.322 12588-12604/? D/Unity﹕ [EGL] Checking ES 3.1 support...
05-19 13:46:30.324 12588-12604/? D/Unity﹕ [EGL] ES 3.1 support detected
05-19 13:46:30.324 12588-12604/? D/Unity﹕ [EGL] Found: ID[1] ES 3.1+AEP RGB16 565 0/0
05-19 13:46:30.324 12588-12604/? D/Unity﹕ GfxDevice: creating device client; threaded=1
05-19 13:46:30.324 12588-12604/? D/Unity﹕ [EGL] Request: ES 3.1+AEP RGB0 000 0/0
05-19 13:46:30.325 12588-12604/? D/Unity﹕ [EGL] Found: ID[1] ES 3.1+AEP RGB16 565 0/0
05-19 13:46:30.325 12588-12604/? D/Unity﹕ [EGL] Request: ES 3.0 RGB16 565 0/0
05-19 13:46:30.326 12588-12604/? D/Unity﹕ [EGL] Found: ID[1] ES 3.0 RGB16 565 0/0
05-19 13:46:30.330 12588-12604/? D/Unity﹕ ANativeWindow: (1080/1920) RequestedResolution: (0/0) RenderingResolution: (0/0) EGLSurface: (1080/1920)
05-19 13:46:30.336 12588-12604/? D/Unity﹕ Renderer: Adreno (TM) 530
05-19 13:46:30.336 12588-12604/? D/Unity﹕ Vendor: Qualcomm
05-19 13:46:30.336 12588-12604/? D/Unity﹕ Version: OpenGL ES 3.2 V@258.0 (GIT@2941438, I916dfac403) (Date:10/03/17)
05-19 13:46:30.336 12588-12604/? D/Unity﹕ GLES: 3
05-19 13:46:30.336 12588-12604/? D/Unity﹕ GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_vertex_half_float GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_compressed_ETC1_RGB8_texture GL_AMD_compressed_ATC_texture GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_OES_texture_compression_astc GL_OES_texture_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_OES_texture_3D GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_QCOM_alpha_test GL_OES_depth24 GL_OES_packed_depth_stencil GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_EXT_sRGB GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_sRGB_decode GL_OES_element_index_uint GL_EXT_copy_image GL_EXT_geometry_shader GL_EXT_tessellation_shader GL_OES_texture_stencil8 GL_EXT_shader_io_blocks GL_OES_shader_image_atomic GL_OES_sample_variables GL_EXT_texture_border_clamp GL_EXT_multisampled_render_to_texture GL_EXT_mul
05-19 13:46:30.336 12588-12604/? D/Unity﹕ tisampled_render_to_texture2 GL_OES_shader_multisample_interpolation GL_EXT_texture_cube_map_array GL_EXT_draw_buffers_indexed GL_EXT_gpu_shader5 GL_EXT_robustness GL_EXT_texture_buffer GL_EXT_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_OES_texture_storage_multisample_2d_array GL_OES_sample_shading GL_OES_get_program_binary GL_EXT_debug_label GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_QCOM_tiled_rendering GL_ANDROID_extension_pack_es31a GL_EXT_primitive_bounding_box GL_OES_standard_derivatives GL_OES_vertex_array_object GL_EXT_disjoint_timer_query GL_KHR_debug GL_EXT_YUV_target GL_EXT_sRGB_write_control GL_EXT_texture_norm16 GL_EXT_discard_framebuffer GL_OES_surfaceless_context GL_OVR_multiview GL_OVR_multiview2 GL_EXT_texture_sRGB_R8 GL_KHR_no_error GL_EXT_debug_marker GL_OES_EGL_image_external_essl3 GL_OVR_multiview_multisampled_render_to_texture GL_EXT_buffer_storage GL_EXT_external_buffer GL_EXT_blit_framebuffer_params GL_EXT_clip_cull_distance
05-19 13:46:30.336 12588-12604/? D/Unity﹕ GL_EXT_protected_textures GL_EXT_shader_non_constant_global_initializers GL_QCOM_framebuffer_foveated GL_QCOM_shader_framebuffer_fetch_noncoherent GL_EXT_EGL_image_array GL_NV_shader_noperspective_interpolation
05-19 13:46:30.343 12588-12604/? D/Unity﹕ OPENGL LOG: Creating OpenGL ES 3.2 graphics device ; Context level ; Context handle -808474560
05-19 13:46:30.344 12588-12604/? D/Unity﹕ [EGL] Attaching window :0xe297e808
05-19 13:46:30.345 12588-12604/? D/Unity﹕ Requested framebuffer: resolution[1080x1920], rgba[5/6/5/0], depth+stencil[on], samples[1]
05-19 13:46:30.345 12588-12604/? D/Unity﹕ Created framebuffer: resolution[1080x1920], rgba[5/6/5/0], depth+stencil[24/8], samples[0]
05-19 13:46:30.345 12588-12604/? D/Unity﹕ [EGL] Attaching window :0xe297e808
05-19 13:46:30.345 12588-12604/? D/Unity﹕ Initialize engine version: 2018.1.0f2 (d4d99f31acba)
05-19 13:46:30.384 12588-12604/? D/Unity﹕ Begin MonoManager ReloadAssembly
05-19 13:46:30.620 12588-12604/? D/Unity﹕ - Completed reload, in 0.235 seconds
05-19 13:46:30.747 12588-12604/? D/Unity﹕ PlayerInitEngineGraphics OK
05-19 13:46:30.749 12588-12604/? D/Unity﹕ Found 27 native sensors
05-19 13:46:30.754 12588-12604/? D/Unity﹕ Sensor : Accelerometer ( 1) ; 0.004788 / 0.00s ; BMI160 accelerometer / Bosch
05-19 13:46:30.756 12588-12604/? D/Unity﹕ Sensor : Accelerometer ( 1) ; 0.004788 / 0.00s ; BMI160 accelerometer / Bosch
05-19 13:46:30.765 12588-12604/? D/Unity﹕ SetWindow 0 0xe297e808
05-19 13:46:30.765 12588-12604/? D/Unity﹕ [EGL] Attaching window :0xe297e808
05-19 13:46:30.864 12588-12588/? I/Unity﹕ windowFocusChanged: true
05-19 13:46:32.820 12588-12604/? D/Unity﹕ UnloadTime: 4.095000 ms
05-19 13:46:32.834 12588-12604/? D/Unity﹕ UUID: b1dbc0e34a78a55b => c11e79cb129c8d2e71ffd8f934d1e7f2
05-19 13:46:33.028 12588-12604/? D/Unity﹕ Sensor : Accelerometer ( 1) ; 0.004788 / 0.00s ; BMI160 accelerometer / Bosch
05-19 13:46:33.042 12588-12604/? D/Unity﹕ Choreographer available: Enabling VSYNC timing
05-19 13:46:33.382 12588-12618/? A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 12618 (UnityGfxDeviceW), pid 12588 (dgames.blackout)
05-19 13:46:33.443 12712-12712/? A/DEBUG﹕ pid: 12588, tid: 12618, name: UnityGfxDeviceW >>> com.fivesecondgames.blackout <<<
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #00 pc 009cb81c /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceGLES::UpdateComputeResources(ComputeShaderResources const&)+184)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #01 pc 009ab3b4 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)+31428)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #02 pc 009abc48 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)+112)
05-19 13:46:33.460 12712-12712/? A/DEBUG﹕ #03 pc 009abbb8 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::Run()+128)
05-19 13:46:33.461 12712-12712/? A/DEBUG﹕ #04 pc 009a3764 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (GfxDeviceWorker::RunGfxDeviceWorker(void*)+4)
05-19 13:46:33.461 12712-12712/? A/DEBUG﹕ #05 pc 00769c30 /data/app/com.fivesecondgames.blackout-zROeIAc7XeHJdGewXa2C0A==/lib/arm/libunity.so (Thread::RunThreadWrapper(void*)+84)
05-19 13:46:35.059 879-12713/? W/ActivityManager﹕ Force finishing activity com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity
05-19 13:46:35.142 499-1615/? E/SurfaceFlinger﹕ Failed to find layer (SurfaceView - com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity#0) in layer parent (no-parent).
05-19 13:46:35.142 499-531/? E/SurfaceFlinger﹕ Failed to find layer (Background for - SurfaceView - com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity#0) in layer parent (no-parent).
05-19 13:46:35.142 879-1131/? W/InputDispatcher﹕ channel '1c67346 com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
05-19 13:46:35.142 879-1131/? E/InputDispatcher﹕ channel '1c67346 com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-19 13:46:35.143 879-4724/? I/WindowManager﹕ WIN DEATH: Window{1c67346 u0 com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity}
05-19 13:46:35.143 879-4724/? W/InputDispatcher﹕ Attempted to unregister already unregistered input channel '1c67346 com.fivesecondgames.blackout/com.unity3d.player.UnityPlayerActivity (server)'
[1]: /storage/temp/117216-blackoutgraphicssettings1.png
[2]: /storage/temp/117217-blackoutgraphicssettings2.png
↧
Texture sampling will move when sampled same position.
I'm facing a sampling problem. I'm trying to use Compute Shader via `SampleLevel` method.
I've written shader code like below.
[numthreads(8,8,1)]
void Test(uint2 id : SV_DispatchThreadID)
{
float w, h;
_SourceTexture.GetDimensions(w, h);
float2 uv = float2(id.x/w, id.y/h);
float4 t = _SourceTexture.SampleLevel(_LinearClamp, uv, 0);
_ResultTexture[id] = t;
}
And it will be dispatched like below.
int kernel = _shader.FindKernel("Test");
_shader.SetTexture(kernel, "_SourceTexture", _previewBuffer.Current);
_shader.SetTexture(kernel, "_ResultTexture", _previewBuffer.Other);
_shader.Dispatch(kernel, _previewBuffer.Width / 8, _previewBuffer.Height / 8, 1);
_previewBuffer.Swap();
_preview.texture = _previewBuffer.Current;
The texture will swap each frame.
So I'm wondering why the shader code sampled same position but the texture will move toward up-right.
I also attached a movie for the problem.
Does anyone have any idea?
![alt text][1]
[1]: https://i.gyazo.com/c57379fb76ea8d5f44a3f3f3fa5ae483.gif
↧
↧
Compute shader loop in editor
I'm working on a tool for the editor in which you can take a sprite and it blurs it for you. I'm using a compute shader with buffer approach to blur it but blur requires multiple passes. After using Shader.Dispatch(), I'm trying to use Buffer.GetData() but this returns a black/empty texture because (I think) the buffer will only be done after a frame update which only happens in editor when you change something. I tried using corourines in the editor but that does not work. Using a non-buffer approach (RenderTexture & ReadPixels) only allows me to do one blur pass. Is there another way to Dispatch() and use the result of a compute shader in a loop in the editor?
Here's the piece of code I written so far:
SpriteRenderer sr = GetComponent();
reftex = sr.sprite.texture;
Color[] outputData = new Color[reftex.width * reftex.height];
ComputeBuffer buffer = new ComputeBuffer(reftex.width * reftex.height, 16);
Color[] bufferData = outputData;
buffer.SetData(bufferData);
int kernel = shader.FindKernel("CSMain");
shader.SetTexture(kernel, "Input", reftex);
shader.SetVector("TexelSize", new Vector4(1f / reftex.width, 1f / reftex.height, reftex.width, reftex.height));
shader.SetBuffer(kernel, "Output", buffer);
shader.Dispatch(kernel, buffer.count, 1, 1);
//yield return new WaitForEndOfFrame();
buffer.GetData(outputData);
resultTexture.SetPixels(outputData);
resultTexture.Apply();
↧
ComputeBuffer stays empty in compute shader in URP
I'm trying to pass a ComputeBuffer to read on my ComputeShader with the Universal Render Pipeline, and everything works, except that the buffer remains empty in the shader.
I'm relatively new to the ScriptableRenderPipeline and shaders, tried to piece things together from various forum threads and SRP tutorials, so there might be some major concept I'm missing to get this to work. But I couldn't find any code example with ComputeShader in SRP, let alone using a ComputeBuffer.
I've created a separate project to isolate the problem, with only one ScriptableRenderPass, that creates a RenderTexture, dispatches the ComputeShader on it and blit it to the camera's texture. I send a float4 _Color for sanity check and draw it on every pixels, that works. I then send a StructuredBuffer _Colors with the exact same content, and draw it on every pixels, and I get nothing.
Here's the renderpass:
class CustomRenderPass : ScriptableRenderPass {
public ComputeShader computeShader;
public string commandBufferName;
public RenderTargetIdentifier source;
RenderTexture target;
RenderTargetIdentifier targetIdentifier;
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) {
if (target != null)
target.Release();
target = new RenderTexture(cameraTextureDescriptor) {
enableRandomWrite = true
};
target.Create();
targetIdentifier = new RenderTargetIdentifier(target);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) {
CommandBuffer cmd = CommandBufferPool.Get(commandBufferName);
//Setting the compute shader's texture to target
cmd.SetComputeTextureParam(computeShader, 0, "Result", targetIdentifier);
//Setting the StructuredBuffer _Colors
ComputeBuffer buffer = new ComputeBuffer(1, 4 * sizeof(float));
buffer.SetData(new Vector4[] {new Vector4(1, 0, 0, 1)});
cmd.SetComputeBufferParam(computeShader, 0, "_Colors", buffer);
//Setting an example float4 _Color
cmd.SetComputeVectorParam(computeShader, "_Color", new Vector4(1, 0, 0, 1));
//Dispatching compute shader
cmd.DispatchCompute(
computeShader,
0,
Mathf.CeilToInt(Screen.width / 8f),
Mathf.CeilToInt(Screen.height / 8f),
1
);
//Pasting texture on the camera's
cmd.Blit(targetIdentifier, source);
context.ExecuteCommandBuffer(cmd);
buffer.Release();
CommandBufferPool.Release(cmd);
}
}
And here's the compute shader:
#pragma kernel CSMain
RWTexture2D Result;
StructuredBuffer _Colors;
float4 _Color;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID) {
//This doesn't work
Result[id.xy] = _Colors[0];
//But this works
//Result[id.xy] = _Color;
}
I've removed everything else so I don't see how this could not work. I don't get any errors, it just draws black.
For context, I'm trying to render spheres with Ray Marching on top of my scene, and I was following [GPU Ray Tracing in Unity][1] for instructions on the Compute Shader as well as [a Ray Marching tutorial][2], I've got hard coded spheres to render no issues, but I'm stuck when trying to pass a ComputeBuffer of sphere structs.
[1]: http://blog.three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/
[2]: https://www.youtube.com/watch?v=PGtv-dBi2wE
↧
perform action on shader compilation/update
i am using a compute shader to generate a terrain (height map), then generate and stream a mesh into the live game.
----------
in order to iterate faster, i would like to automatically restart the terrain generator, as soon as i change / update the shader.
is there a callback / way to hook up to the shader recompile?
or a shader version property of some sort, that i can check for changes?
----------
ideally, i would like to get to a setup where the shader recompiles and i can use it as soon as i save the shader (not wait until i switch back to the unity editor window). that would be the best case and would help a lot with iteration speed
↧
Render texture copy to splat map problem
Hi, i'm modifying renderTextures in a compute shader thrue this simplified code:
Compute shader
RWTexture2D splat0; // splat map
RWTexture2D splat1;
[numthreads(8, 8, 1)]
void UpdateAll(uint2 id : SV_DispatchThreadID)
{
splat0[coord] = color0;
splat1[coord] = color1;
}
Then i copy the render textures directly into my terrain splatmaps like this:
C#
Graphics.CopyTexture(_splat0Temp, splatMap0);
Graphics.CopyTexture(_splat1Temp, splatMap1);
But something is going wrong (I can't show you here how cause when i try to upload an image or a gif i get this error "Error parsing the uploaded file." so i will try to explain it...)
When i zoom in the modifications shows up but if i zoom out modifications fade out, maybe this is something due to mip maps but i don't know how to resolve it.
If someone is having a clue of what's going on, i would be very happy to know.
Thanks
↧
↧
How can we get mesh vertices position which has been deformed by the shader graph?
Hi,
I am working on procedural cloud generation. So have generated custom plane mesh which is in a rectangle shape and for cloud effect and it’s shaping I have developed shader on shader graph.
This shader is getting vertice position of the mesh and deforming its position to cloud shape as per noise value and method which has been defined in the shader graph.
So in-game the player has to interact with the cloud. So I need a collider for the cloud and I want polygon collider2d instead of mesh collider.
So the problem is here shader works on Graphic Pip-line and shader does not share vertices data to the mesh-filter component.
From R&D I got to know that with the COMPUTE_SHADER we can access the shader property for the game object component but still not sure, will this method solve the problem or not!,Hi,
I am working on procedural cloud generation. So have generated custom plane mesh which is in a rectangle shape and for cloud effect and it’s shaping I have developed shader on shader graph.
This shader is getting vertice position of the mesh and deforming its position to cloud shape as per noise value and method which has been defined in the shader graph.
So in-game the player has to interact with the cloud. So I need a collider for the cloud and which has to be polygon collider2d instead of mesh collider.
So the problem is here shader works on Graphic Pip-line and shader does not share vertices data to the mesh-filter component.
From R&D I got to know that with the COMPUTE_SHADER we can access the shader property for the game object component but still not sure, will this method solve the problem or not!
(Image: 1). Simple plane mesh procedurally generated
![alt text][1]
(Image: 2). Deformed mesh vertices with the shader.
![alt text][2]
[1]: /storage/temp/153504-screenshot-2020-02-28-at-72952-pm.png
[2]: /storage/temp/153503-screenshot-2020-02-28-at-71558-pm.png
↧
Persistent Data in Compute Shaders.
Hey there,
I have created a little raytracer in unity using the compute shader and now I want to store (for example) the last 100 outputs on the GPU memory for later calculations. The CPU does not need to have any access to this data so there is no need to shift this data between the GPU and the CPU. Up to now I have not seen any opportunity to initialize data directly from the compute shader with HLSL. Is there any way to create an array of Texture2D and initialize it on the GPU or do you know another workaround?
I ask this question as a newcomer to graphics programming so I don't know if this is even possible, but I would appreciate if somebody could explain me how to achieve this simple task.
↧
GraphicsBuffer for vertices inquiry
Hi,
I wanted to pass some vertices from CPU to GPU's computeShader's kernel via GraphicsBuffer, but I stumbled upon some incosistent information.
https://docs.unity3d.com/ScriptReference/GraphicsBuffer-ctor.html states that **GraphicsBuffer** constructor takes **target** as the first argument, which should enable you to choose indices or vertices (as per description), but https://docs.unity3d.com/ScriptReference/GraphicsBuffer.Target.html shows that only indices are available. How to make it work with vertices?
↧