A game about forced loneliness, made by TACStudios
at master 39 lines 2.0 kB view raw view rendered
1# Normal From Texture Node 2 3## Description 4 5Converts a height map defined by input **Texture** into a normal map. UV values and sampler state can be defined by inputs **UV** and **Sampler** respectively. If nothing is connected to these ports they will use default values from the inputs. See [Port Bindings](Port-Bindings.md) for more information. 6 7The strength of the created normal map can be defined by inputs **Offset** and **Strength**, where **Offset** defines the maximum distance of a normal detail and **Strength** acts as a multiplier to the result. 8 9If you experience texture sampling errors while using this node in a graph which includes Custom Function Nodes or Sub Graphs, you can resolve them by upgrading to version 10.3 or later. 10 11## Ports 12 13| Name | Direction | Type | Binding | Description | 14|:------------ |:-------------|:-----|:---|:---| 15| Texture | Input | Texture | None | Height map | 16| UV | Input | Vector 2 | UV | Texture coordinates | 17| Sampler | Input | Sampler State | None | Sampler for **Texture** | 18| Offset | Input | Float | None | Amount to offset samples | 19| Strength | Input | Float | None | Strength multiplier | 20| Out | Output | Vector 3 | None | Output value | 21 22## Generated Code Example 23 24The following example code represents one possible outcome of this node. 25 26``` 27void Unity_NormalFromTexture_float(Texture texture, SamplerState Sampler, float2 UV, float Offset, float Strength, out float3 Out) 28{ 29 Offset = pow(Offset, 3) * 0.1; 30 float2 offsetU = float2(UV.x + Offset, UV.y); 31 float2 offsetV = float2(UV.x, UV.y + Offset); 32 float normalSample = Texture.Sample(Sampler, UV); 33 float uSample = Texture.Sample(Sampler, offsetU); 34 float vSample = Texture.Sample(Sampler, offsetV); 35 float3 va = float3(1, 0, (uSample - normalSample) * Strength); 36 float3 vb = float3(0, 1, (vSample - normalSample) * Strength); 37 Out = normalize(cross(va, vb)); 38} 39```