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
Unite Now 2020: An online conference for real-time development | Unity

https://resources.unity.com/unitenow

#unite #conference
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