SHADER HELP - Shader 2nd Texture Offset and Tilliing not Working
Hi All.
I am learning some basic of shaders. Trying to create one for my water. What I got is a Texture with 2 Displacement Maps.
The First one works as expected but adding the Second Displacement Texture, the second texture it just doesn't offset or tile at all.
Can someone please have a look at my shader for me and maybe tell me where I am going wrong.
Regards
I am learning some basic of shaders. Trying to create one for my water. What I got is a Texture with 2 Displacement Maps.
The First one works as expected but adding the Second Displacement Texture, the second texture it just doesn't offset or tile at all.
Can someone please have a look at my shader for me and maybe tell me where I am going wrong.
Regards
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Setti/Water" { Properties { _MainTex ("MainTex", 2D) = "white" {} _DisplTex ("DisplTex", 2D) = "white" {} _DisplScale("DisplScale", Range(0, 1)) = 0.25 _DisplTex1 ("DisplTex1", 2D) = "white" {} _DisplScale1("DisplScale1", Range(0, 1)) = 0.25 } SubShader { Tags { "Queue" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _DisplTex; uniform float4 _DisplTex_ST; uniform float _DisplScale; uniform sampler2D _DisplTex1; uniform float4 _DisplTex_ST1; uniform float _DisplScale1; struct vertexInput { float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct vertexOutput { float4 pos : SV_POSITION; float4 tex : TEXCOORD0; }; vertexOutput vert(vertexInput input) { vertexOutput output; output.tex = input.texcoord; output.pos = UnityObjectToClipPos(input.vertex); return output; } float4 frag(vertexOutput input) : COLOR { float dipl = (tex2D(_DisplTex, input.tex.xy *_DisplTex_ST.xy + _DisplTex_ST.zw).a-0.5)*2*_DisplScale; fixed4 col = tex2D(_MainTex, _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw + float2(dipl.x, 0)); float dipl2 = (tex2D(_DisplTex1, input.tex.xy *_DisplTex_ST1.xy + _DisplTex_ST1.zw).a-0.5)*2*_DisplScale1; fixed4 col1 = tex2D(_MainTex, _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw + float2(dipl2.x, 0)); return (col+col1)/2; // return col1; } ENDCG } } }
Comments
I think you need to change "_DisplTex_ST1" to "_DisplTex1_ST". Let me know if that helps?
Now I just need both offset x scroll at different speeds.
Should this be avail in the shader or via c# script. Hoping directly in shader
e.g.
Not that important yet maybe, but in general, it'd be better to move your UV calculations into your vertex shader. The vertex shader is run for each vertex, whereas the fragment shader is run for each pixel. In general, objects take up many more pixels on screen than the number of vertices they have, so you typically try to move as much as you can into the vertex shader.
e.g.
Also, thanks @Elyaradine for the tip about doing calculations in the vert shader, makes a lot of sense. Hadn't thought about that :)
Another aside, but usually "displacement" is a word used to describe vertices themselves being offset. I don't know if the thing you're trying to do has a more standard name, but I think it might be called "distortion". This could help you in the future if you're Googling stuff, because most things to do with shader displacement are going to land you in threads about tessellation or vertex offsets or something.
So This Shader case study was a great success . Result.
Next Case study for me. 2d Wind. Maybe interactive Grass
In case you haven't considered it, you can blend your two noise textures together at different speeds, and use the result of that to distort your colours, instead of blending two versions of your colour together. Which one you use depends on your art direction, but I personally prefer blending the noises, because with pixel art I find that you usually want to avoid semi-transparent pixels.
Also thank you for your feedback and input.
Will post my update on my interactive grass soon.
In essence you'd be mixing your noises together, and then using the result to offset your colour.
There are lots of different ways to mix noises together, and which way you do it depends on the visual you're after. It could just be taking the average of the two, or it could be multiplying them, or using various Photoshop blending maths. (The link is in GLSL, so you might have to find the HLSL equivalents of some of their functions.)
Not a game yet. Just doing some case studies on shaders. Using some sprites found on itch.io . But starting to get an idea for an game. Gonna purchase Pyxel editor to creates sprites with.
Thanks for you feedback!!!
Thanks for mentioning this.
1st section of my gif is old shader mixing my colors. Then you will see me change it to V4 in the inspector. This blends the noise first. I really love the look of that reflections.
Thank you again for your imput!!!!
Same as above. First color blending. Then the switch to new version
I agree. I have done some more changes on the look. added some tints to it. It works to match the Sky and suns input. I have been looking into distorting things closer to the camera more. Got stuck on this.
Thank you for your input.
Improvements to the look of the water.
@Elyaradine
It started to look great :-)
Moved active Progress to this thread
http://makegamessa.com/discussion/5694/unknown-pixel-art-adventure