Everyday Unity – Telegram
Everyday Unity
1.11K subscribers
157 photos
59 videos
42 files
2.36K links
A game developer and tech lead in a top grossing company posting Unity, programming, and gamedev related stuff that I find interesting
Website: https://gamedev.center

Most used tags are:
#performance
#shader
#interview

Author: @alexmtr
Download Telegram
Scrolling Energy Shader Breakdown

https://www.reddit.com/r/Unity3D/comments/ftp4a2/scrolling_energy_shader_breakdown/

Apply texture - Created the texture in photoshop using the smudge tool, pushing and pulling to create this wavy particle texture. After that using filter > other > offset to make sure the texture properly tiles. Then I set the texture as the color in the shader.

Use texture rgb as alpha - The alpha in a texture is just another channel like the rgb values. Since I want the black areas of the texture to be transparent, I just made the alpha channel equal the red channel. You can do the same thing by constructing the texture to be white on transparent, but I like working with black and white particle sprites.

Change UVs over time to create scroll effect - Take the existing uvs and add the speed you want the uvs to change multiplied by time. o.uv = TRANSFORM_TEX(v.uv, _MainTex).xy + frac(_Time.y * float2(_ScrollSpd.x, _ScrollSpd.y));

Edit tiling scale to stretch texture - When you create a new texture variable in a shader, tiling and offset variables are included in unity's editor, letting you change how the texture scales or its position.

Apply HDR color to RGB - Multiply the existing color by a HDR color you set. HDR lets you set color values beyond the 0 to 1 intensity of what your display outputs, letting the particle be brighter. With a bloom post-processing filter, the HDR color also glows, giving it a proper energy feeling.

Multiply mask over alpha - To let the scrolling particles exist in different shapes, I added an additional mask that is multiplied on top of the previously calculated alpha. This mask needs to have its own UVs defined to make sure it doesn't scroll/scale with the main texture.

Extra - There are additional improvements to add, like giving the mask its own independent scrolling or setting its scale to match the main texture.

#shader #energy
Fix artifacting in the grid shader.
Normally you can fix this by enabling Unity mipmapping on your textures. However, that doesn't work here because the grid cells aren't textures -- they're generated through a shader.

Instead, I have the grid cell colors slowly bleed into each other as the individual cells get smaller on the screen. When they get smaller than one pixel, there's no such thing as individual cells; everything is uniformly colored with the average of the two colors in the grid.

It's a sort of fake mipmapping that only works for this specific situation.

#shader #grid #mipmap
https://markheath.net/post/async-antipatterns

Async await antipatterns:
1. Forgotten await
2. Ignoring tasks - The danger with this approach is that nothing is going to catch any exceptions thrown. At best, that means you didn't know it failed to complete. At worst, it can terminate your process. So use this approach with caution, and make sure the method has good exception handling.
3. Using async void methods - The trouble is, that the caller of the method has no way to await the outcome of this method. They have no access to the Task that awaited method returned. So you're essentially ignoring a task again.
4. Blocking on tasks with .Result or .Wait - there are some problems here. The first is that using blocking calls like Result ties up a thread that could be doing other useful work. More seriously, mixing async code with calls to .Result (or .Wait()) opens the door to some really nasty deadlock problems.
5. Mixing ForEach with async methods
6. Excessive parallelization
7. Non-thread-safe side-effects - prefer pure functions instead of relying on the calling method to run on the main thread.
8. Missing ConfigureAwait(false) - not so useful for Unity since its api is not thread safe
9. Ignoring the async version
10. try catch without await - dont return Task inside try-catch since the catch will not be triggered if exception happens inside task. It can only be triggered on task creation.

#async #patterns
Understanding Audio Compression Settings in Unity

https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f

Vorbis requires significantly higher CPU resources to decompress the audio for playback.

One major difference between MP3 and Vorbis is that MP3 cannot loop seamlessly.

PCM is lossless compression and, while light on the CPU, has a much larger file size

ADPCM has a fixed compression ratio of about 3.5 and, while a good compromise between PCM and Vorbis/MP3, can sometimes cause unwanted noise (quantitative distortion) in audio files with lots of high-frequency content

Vorbis is a very efficient audio codec that offers high-quality lossy compression but requires more CPU resources for decompression

MP3 also offers high-quality lossy compression but causes problems for audio assets that should loop

#audio #settings #compression