Normal Map
From Adobe Labs
Load 2 images and change the position, color, and brightness of a point light.
kernel NormalMap
{
parameter float3 lightcolor
<
minValue:float3(0.0, 0.0, 0);
maxValue:float3(1.0, 1.0, 1);
defaultValue:float3(1.0, 1.0, 1);
>;
parameter float3 lightpos
<
minValue:float3(0.0, 0.0, 0);
maxValue:float3(2048.0, 2048.0, 2048);
defaultValue:float3(200.0, 50.0, 200);
>;
parameter float brightness
<
minValue:float(0);
maxValue:float(2048*4);
defaultValue:float(500);
>;
void
evaluatePixel(in image3 src, in image4 map, out float4 dst)
{
float4 col = sampleNearest(map, outCoord());
float3 normal = sampleNearest(src, outCoord());
float3 surface = float3(outCoord().x, 0, outCoord().y);
float dist = length( lightpos-surface );
float scale = dot((normalize(lightpos-surface)), normalize(normalize(normal)-float3(.5, .5, .5)))*((brightness*float(10))/(dist*dist));
dst = float4(col.r*scale*lightcolor.r, col.g*scale*lightcolor.g, col.b*scale*lightcolor.b, col.a);
}
}
