Created
April 3, 2016 06:48
-
-
Save iodiot/0e083a01980db24746f51bdfdcf50443 to your computer and use it in GitHub Desktop.
Light map shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Macros.fxh" | |
#include "Common.fxh" | |
static const int MAX_LIGHTS = 50; | |
DECLARE_TEXTURE(Texture, 0); | |
uniform extern float2 LightPositions[MAX_LIGHTS]; | |
uniform extern float4 LightColors[MAX_LIGHTS]; | |
uniform extern float LightRadiuses[MAX_LIGHTS]; | |
struct VsOutput | |
{ | |
float4 PositionPS : SV_POSITION; | |
float4 Color : COLOR0; | |
float2 TexCoord : TEXCOORD0; | |
}; | |
float4 ComputeLight(float2 p) | |
{ | |
float4 light = float4(0, 0, 0, 0); | |
int i; | |
for (i = 0; i < MAX_LIGHTS; ++i) | |
{ | |
float lightR = LightRadiuses[i]; | |
float4 lightC = LightColors[i]; | |
float2 lightP = LightPositions[i]; | |
float d = clamp(length(p - lightP), 0, lightR); | |
float fadeCoef = lerp(1.0, 0.0, d / lightR); | |
// Blending: Screen | |
light = light + lightC * fadeCoef * (1 - light); | |
} | |
return light; | |
} | |
VsOutput LightMapVs(VsInput vin) | |
{ | |
VsOutput vout; | |
vout.PositionPS = mul(vin.Position, WorldViewProj); | |
vout.Color = vin.Color; | |
vout.TexCoord = vin.TexCoord; | |
return vout; | |
} | |
float4 LightMapPs(VsOutput pin) : SV_Target0 | |
{ | |
float4 light = ComputeLight(pin.PositionPS.xy); | |
return light; | |
} | |
TECHNIQUE(LightMap, LightMapVs, LightMapPs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment