Shader informations nice blog ~ ~

 https://halisavakis.com/my-take-on-shaders-geometry-shaders/

My take on shaders: Parallax effect (Part II)

Welcome to the second part of the tutorial on Parallax effects! Now, initially I intended for this tutorial to only have two parts, with which I so naively open on the previous post. However, there’s probably going to be a third part on the series, the subject of which I won’t reveal now, for some dramatic tension.

The subject of this part was what I initially intended to achieve and it led me to stumble upon the previous and next tutorials, for which I’m really grateful. It’s the effect that got me so excited about parallax, as I mentioned in the backstory of the previous post, and it’s the very same effect covered in that tutorial I mentioned before, but without the Shader Graph:

1
2
3
4
5
6
7
8
// Calculates UV offset for parallax bump mapping
inline float2 ParallaxOffset( half h, half height, half3 viewDir )
{
    h = h * height - height/2.0;
    float3 v = normalize(viewDir);
    v.z += 0.42;
    return h * (v.xy / v.z);
}

Actually interesting part

Now that we sorted how I got here, let’s dive into the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Shader "Custom/ParallaxShader" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Normal ("Normal", 2D) = "bump" {}
        _Height("Height", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _Parallax("Parallax", float) = 0
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
 
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows
 
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0
 
        sampler2D _MainTex;
        sampler2D _Normal;
        sampler2D _Height;
 
        struct Input {
            float2 uv_MainTex;
            float2 uv_Normal;
            float2 uv_Height;
            float3 viewDir;
        };
 
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        float _Parallax;
 
        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)
 
        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            float heightTex = tex2D(_Height, IN.uv_Height).r;
            float2 parallaxOffset = ParallaxOffset(heightTex, _Parallax, IN.viewDir);
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex + parallaxOffset) * _Color;
            o.Normal = UnpackNormal(tex2D(_Normal, IN.uv_Normal + parallaxOffset));
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Let’s check the properties first. As you can see, this is a surface shader, so most of them were filled out already. 






댓글

이 블로그의 인기 게시물

About AActor!!! "UObject" has no member "BeginPlay"

UNREAL Android build information