Collections

URP SurfaceInput.hlsl

Declartion:

  • BaseMap
  • BumpMap / NormalMap
  • EmissionMap

Helpers:

  • Alpha()
  • sample albedo and alpha
  • sample normal
  • sample emission

There’s a problem in URP’s hlsl files. They are all tight together to build the URP shader, not SRP. This reminds me that URP is an example of SRP. It’s better to have my own helper library.

URP scalar types

source: https://www.cyanilux.com/tutorials/urp-shader-code/

float - 32 bits / 4 bytes: world space positions, texture coordinates, scalar computations, complex functions such as trigonometry or power/exponentiation.

half - 16 bits / 2 bytes. Short vectors, directions, object space positions, colors.

double - 64 bits / 8 bytes, can’t be used as inputs/outputs

real - used when a function can support either half or float. It defaults to half

uint - GLES2 doesn’t support

LUT

Suppose the LUT is 1024 x 32, that means the width is 1024 and height is 32. Since we use y axis to represent the green value, we should use 32 different numbers to measure red and blue from 0 to 255.

For example, coordinates (32, 16, 0) is located in the 1st segment at (32, 16) pixel, and the color is (1, 0.5, 0); (19, 27, 25) is in the 25th segment at (19, 27), and the color is (0.59375, 0.84375, 0.78125).

Using 0 to 1 to represent it, we divided it by 8 and get 0.125. That means to divide to 8 segments, each segments' length is 0.125.

Misc

Fresnel: pow( 1 - saturate(dot(normalize(normal), noramlize(viewDir))), power);

Interesting webpages: