Messing About with Shaders in Unity

Well what started as a little overview for the weekend, has now spilled into Monday.
But I must say, once i got my head round some of the mad syntax and code layout, im really enjoying tinkering with them :slight_smile:

early days, but playing around with surface shaders

3 Likes

That’s awesome. I’ve recently started with HLSL, too. Made some gradient stuff for GUI materials and a blurred, “transparent” background. :slight_smile:

Did you write everything yourself or did you tweak a premade shader?

(Have I mentioned that I really love the look of that water material? It reminds me of green marble.)

3 Likes

Cheers Nina,

took the standard surface shader, or the default unlit diffuse, then stripped it back to basics and added bits here and there to have a look to see what makes the Shaderlab wrapper work and how it goes together.
so i can see how the input struct then ties into either the surface or fragment functions.

enjoying it, and so far ive managed to get rid of some of the dread I had when first looking at them…

Just doing it little bit by bit, and using the Nvidia Cg book that I bought a few month back for reference to some of the things that dont quite make sense.

How you finding it yourself?

3 Likes

Sounds great. One day, I’ll create a water shader, too. Did you use the _Time value for the animation?

I struggled for about two days grasping the syntax, and, until today, I don’t know what exactly is happening in the shader code structure. And what’s with those tags??? Even though I tried to read the Nvidia Cg book, I almost didn’t unterstand anything. That frustrated me but I decided to just learn how to use variables, and to dive into the details later when I’m a bit more experienced. Unfortunately, I don’t have time for that at the moment.

My actual goal was a bit more complex than a shader, and I needed a few custom shaders for it: a blurred GUI background. Developing the whole thing took me about 100h within one and a half weeks. My first own shader was tinted a texture and had a displacement texture. Very basic. My second one was a top-down and a bottom-up shader with alpha stuff, “opacity” and such. Developing algorithms isn’t that difficult once you got how to pass on data.

I had some issues with C# reference issues and memory leaks, though, which took me lots of hours to fix. :confused:

Perhaps a displacement texture could be interesting for you to distort your water texture a bit?

(Sorry for being annoying, but I have to mention once more that I absolutely love how the water looks.)

2 Likes

yea, ive only just started since the weekend, and i too started reading the Cg book and found it quite overwhelming as a work-through type thing. ill revisit it once i get a bit more comfortable.
but one book I picked up last week on the free PackT book of the day was the Unity5 shader cookbook, and im about 50 pages in and finding it quite straightforward for the most part to work through. then for some of the things that I dont quite grasp ill look up the Cg book for a different explanation on it.

yep, spot on, took the input UVs then incremented with a speed and the _Time to adjust and put them back to the output.

so I have this in the properties

  _ScrollXSpeed ("X Scroll Speed", Range(-10, 10)) = 0
  _ScrollYSpeed ("Y Scroll Speed", Range(-10, 10)) = 0

and referenced that two vars in the top of the Cg section.

and popped them back to the Surface method.

void surf (Input IN, inout SurfaceOutputStandard o) {
fixed2 _scrolledUV = IN.uv_MainTex;

  	// create variables that store the indivudual x and y
  	// components for the UVs scaled by time
  	fixed xScrollValue = _ScrollXSpeed * _Time.y;
  	fixed yScrollValue = _ScrollYSpeed * _Time.y;

  	// apply the final UV Offset
  	_scrolledUV += fixed2(xScrollValue, yScrollValue);

  	// apply texture and tint
  	half4 c = tex2D (_MainTex, _scrolledUV);
  	o.Albedo = c.rgb;
  	o.Alpha = c.a;
  }

Theres a couple of tweaks i want to do, going to see if I can add a secondary texture above it slightly transparent and with either a half or double the speed (not sure yet)

then i need to see about how to add procedural textures, with a sort of voronoi look but ill save that for when im away at work and something to get the teeth into :slight_smile:

I like that Making Stuff Look Good channel, watched a couple and nice explanations.

3 Likes

heres a nice read about the shaders and SFX used for zelda.

if you scroll down and click through to the Ocean link its a really interesting case study.

3 Likes

It seems, I need to get that book, too. :slight_smile:

I like that the creator of the Making Stuff Look Good channel videos quickly gets to the point. At least he inspired me to not give up within 5 minutes. And I found catlikecoding helpful for understanding the HLSL/Cg syntax/code structure.

Voronoi is always so beautiful. I wished I knew more about maths to use something like Llyod’s relaxation algorithm, even though I have no idea what to do with it.

Thanks for the medium.com link. It’s incredible what some people were/are able to achieve within the limitations of their respective target system.

I can’t wait to see the improved version of your shader. :3

3 Likes

Awesome work Daz :heart_eyes: , the shader is looking good, studying shaders is also on my todo list, but I will take a while before starting to study it more.

I like watching this channel’s videos, it is only about unity shaders, the guy is very impressive:

2 Likes

sort of getting there, still have some Zdepth camera issues, but the occlusion is working ish so thats this weekends job, try and get it behaving right

1 Like