Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Last active August 25, 2017 21:25
Show Gist options
  • Save ScatteredRay/dd60889a61d08a25d67e035b986e6c8c to your computer and use it in GitHub Desktop.
Save ScatteredRay/dd60889a61d08a25d67e035b986e6c8c to your computer and use it in GitHub Desktop.
@(at-point 'surface-struct
'(
(float3 albedo1 ;)
(float3 albedo2 ;)
(float blend ;)))
@(at-point 'surface-calc
'(
(surface . albedo1 = ... ;)
(surface . albedo2 = ... ;)
(surface . blend = ... ;)))
@(at-point 'surface-params """
params.albedo = lerp(surface.albedo1, surface.albedo2, surface.blend);
""")
@(include "surface.frag")
@(log "Building %d layer blend" numLayers)
@(at-point 'surface-struct
(map
(lambda (i) '(
(float3 ,(concatenate "albedo" i) ;)
(float ,(concatenate "blend" i) ;))
(range 0 numLayers)))
@(at-point 'surface-calc
'(...))
@(at-point 'surface-params
(map
(lambda (i)
(list "params.albedo = lerp(params.albedo, surface." (concatenate "albedo" i) ", surface." (concatenate "blend" i) ");"))
(range 0 numLayers)))
@(include "surface.frag")
struct LightParams {
float3 albedo;
};
struct Surface {
@(point 'surface-struct)
};
void main()
{
Surface surface;
@(point 'surface-calc)
...
LightParams params;
params.albedo = float3(0,0,0);
@(point 'surface-params)
float3 color = evalLights(params);
@(point 'modify-color)
out_color = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment