-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c4850
commit 01f2eb5
Showing
31 changed files
with
1,679 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
sampler TextureSampler : register(s0); | ||
sampler LightSampler : register(s1); | ||
|
||
float4 BasicString(float2 texCoord : TEXCOORD0, float4 color : COLOR0) : COLOR0 | ||
{ | ||
float4 colorGround = tex2D(TextureSampler, texCoord); | ||
float4 colorShadow = tex2D(LightSampler, texCoord); | ||
colorShadow.a = 0; // Sets the shadow's alpha to 0, making it invisible instead of black. | ||
|
||
float4 resultColor = colorGround * colorShadow + colorShadow * colorGround; | ||
return resultColor; | ||
} | ||
|
||
technique Basic | ||
{ | ||
pass Pass0 | ||
{ | ||
PixelShader = compile ps_2_0 BasicString(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
sampler ScreenSampler : register(s0); | ||
sampler MaskSampler : register(s1); | ||
|
||
// here we do the real work. | ||
float4 PixelShaderFunction(float2 inCoord: TEXCOORD0) : COLOR | ||
{ | ||
// we retrieve the color in the original texture at | ||
// the current coordinate remember that this function | ||
// is run on every pixel in our texture. | ||
float4 color = tex2D(ScreenSampler, inCoord); | ||
|
||
// Since we are using a black and white mask the black | ||
// area will have a value of 0 and the white areas will | ||
// have a value of 255. Hence the black areas will subtract | ||
// nothing from our original color, and the white areas of | ||
// our mask will subtract all color from the color. | ||
color.rgba = color.rgba - tex2D(MaskSampler, inCoord).r; | ||
|
||
// return the new color of the pixel. | ||
return color; | ||
} | ||
|
||
technique | ||
{ | ||
pass P0 | ||
{ | ||
PixelShader = compile ps_2_0 PixelShaderFunction(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Effect applies normalmapped lighting to a 2D sprite. | ||
|
||
float4 LightIntensity = 1.0; | ||
int NumberOfLights; | ||
float3 LightPosition[5]; // Max number of lights. | ||
float LightSize[5]; | ||
float4 AmbientColor = 1; | ||
|
||
sampler TextureSampler : register(s0); | ||
sampler NormalSampler : register(s1); | ||
|
||
|
||
float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
//texCoord coordinates are returned between values 0 to 1. | ||
// Look up the texture and normalmap values. | ||
float4 tex = tex2D(TextureSampler, texCoord); | ||
|
||
if (NumberOfLights > 0) | ||
{ | ||
float3 normal = tex2D(NormalSampler, texCoord); | ||
|
||
float3 pixelPosition = float3(1320 * texCoord.x, 720 * texCoord.y, 0); | ||
float lightAmount = 0; | ||
|
||
for (int i = 0; i < NumberOfLights; i++) | ||
{ | ||
float internalAmount = max(dot(normal, normalize(LightPosition[i] - pixelPosition)), 0); | ||
if (internalAmount > lightAmount) | ||
lightAmount = internalAmount; | ||
} | ||
|
||
color.rgb *= 0 + lightAmount * LightIntensity; | ||
} | ||
return tex * color; | ||
} | ||
|
||
float4 AmbientNormalCombination(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
//texCoord coordinates are returned between values 0 to 1. | ||
float4 tex = tex2D(TextureSampler, texCoord); | ||
|
||
if (NumberOfLights > 0) | ||
{ | ||
float3 normal = tex2D(NormalSampler, texCoord); | ||
|
||
float3 pixelPosition = float3(1320 * texCoord.x, 720 * texCoord.y, 0); | ||
float lightAmount = 0; | ||
|
||
for (int i = 0; i < NumberOfLights; i++) | ||
{ | ||
float internalAmount = max(dot(normal, normalize(LightPosition[i] - pixelPosition)), 0); | ||
if (internalAmount > lightAmount) | ||
lightAmount = internalAmount; | ||
} | ||
|
||
if ((lightAmount < 1 && lightAmount > 0.7f)) // Change this second value to shrink the circle. | ||
color = (color * (1 - AmbientColor.a)) + ((AmbientColor + (lightAmount * LightIntensity)) * AmbientColor.a); | ||
else | ||
color.rgb *= 0 + lightAmount * LightIntensity * 2; | ||
} | ||
return tex * color; | ||
} | ||
|
||
technique AmbientNormalmap | ||
{ | ||
pass Pass1 | ||
{ | ||
//PixelShader = compile ps_2_0 main(); | ||
PixelShader = compile ps_2_0 AmbientNormalCombination(); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
sampler TextureSampler : register(s1); | ||
sampler LightSampler : register(s0); | ||
|
||
float4 MaskShade(float2 texCoord : TEXCOORD0, float4 color : COLOR0) : COLOR0 | ||
{ | ||
float4 colorGround = tex2D(TextureSampler, texCoord); | ||
float4 colorShadow = tex2D(LightSampler, texCoord); | ||
float4 resultColor = 0; | ||
|
||
if (colorShadow.r == 0 && colorShadow.g == 0 && colorShadow.b == 0) | ||
resultColor = colorGround; | ||
|
||
return resultColor; | ||
} | ||
|
||
technique Basic | ||
{ | ||
pass Pass0 | ||
{ | ||
PixelShader = compile ps_2_0 MaskShade(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
float BlurDistance = 0.003f; | ||
|
||
sampler TextureSampler : register(s0); | ||
|
||
float4 BlurShader(float2 Tex:TEXCOORD0) : COLOR0 | ||
{ | ||
float4 Color; | ||
|
||
// Get the texel from ColorMapSampler using a modified texture coordinate. This | ||
// gets the texels at the neighbour texels and adds it to Color. | ||
Color = tex2D( TextureSampler, float2(Tex.x+BlurDistance, Tex.y+BlurDistance)); | ||
Color += tex2D( TextureSampler, float2(Tex.x-BlurDistance, Tex.y-BlurDistance)); | ||
Color += tex2D( TextureSampler, float2(Tex.x+BlurDistance, Tex.y-BlurDistance)); | ||
Color += tex2D( TextureSampler, float2(Tex.x-BlurDistance, Tex.y+BlurDistance)); | ||
// We need to devide the color with the amount of times we added | ||
// a color to it, in this case 4, to get the avg. color | ||
Color = Color / 4; | ||
|
||
// returned the blurred color | ||
return Color; | ||
} | ||
|
||
technique Technique1 | ||
{ | ||
pass Pass1 | ||
{ | ||
PixelShader = compile ps_2_0 BlurShader(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
uniform extern float BloomThreshold; | ||
float2 halfPixel; | ||
sampler TextureSampler : register(s0); | ||
float4 BrightPassPS(float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
texCoord -= halfPixel; | ||
// Look up the original image color. | ||
float4 c = tex2D(TextureSampler, texCoord); | ||
// Adjust it to keep only values brighter than the specified threshold. | ||
return saturate((c - BloomThreshold) / (1 - BloomThreshold)); | ||
} | ||
technique BloomExtract | ||
{ | ||
pass P0 | ||
{ | ||
PixelShader = compile ps_2_0 BrightPassPS(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
sampler TextureSampler : register(s0); | ||
|
||
// TODO: add effect parameters here. | ||
|
||
float4 desiredTint; | ||
float4 ColourSwappedOut1; | ||
float4 ColourSwappedIn1; | ||
float4 ColourSwappedOut2; | ||
float4 ColourSwappedIn2; | ||
|
||
float Opacity = 1; | ||
|
||
const float colourBuffer = 0.2f; | ||
|
||
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
float4 color = tex2D(TextureSampler, texCoord); | ||
|
||
if (color.r == ColourSwappedOut1.r && color.g == ColourSwappedOut1.g && color.b == ColourSwappedOut1.b) | ||
return ColourSwappedIn1 * Opacity; | ||
|
||
if (color.r == ColourSwappedOut2.r && color.g == ColourSwappedOut2.g && color.b == ColourSwappedOut2.b) | ||
return ColourSwappedIn2 * Opacity; | ||
|
||
return color * desiredTint * Opacity; | ||
} | ||
|
||
technique Technique1 | ||
{ | ||
pass Pass1 | ||
{ | ||
PixelShader = compile ps_2_0 PixelShaderFunction(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
float2 ScreenLightPos; | ||
float Density = .5f; | ||
float Decay = .95f; | ||
float Weight = 1.0f; | ||
float Exposure = .08f; | ||
sampler DryImage : register(s0) | ||
{ | ||
MinFilter = Linear; | ||
MagFilter = Linear; | ||
MipFilter = Linear; | ||
AddressU = Wrap; | ||
AddressV = Wrap; | ||
}; | ||
|
||
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
float2 deltaTexCoord = (texCoord - ScreenLightPos.xy); | ||
deltaTexCoord *= 1.0f / 50 * Density; | ||
float4 color = tex2D(DryImage, texCoord); | ||
float illuminationDecay = 1.0f; | ||
for (int i = 0; i < 20; i++) | ||
{ | ||
texCoord -= deltaTexCoord; | ||
float4 sample = tex2D(DryImage, texCoord); | ||
sample *= illuminationDecay * Weight; | ||
color += sample; | ||
illuminationDecay *= Decay; | ||
} | ||
return color * Exposure; | ||
} | ||
|
||
technique Technique1 | ||
{ | ||
pass Pass1 | ||
{ | ||
PixelShader = compile ps_2_0 PixelShaderFunction(); | ||
} | ||
} | ||
|
||
uniform extern float BloomThreshold; | ||
float2 halfPixel; | ||
sampler TextureSampler : register(s0); | ||
float4 BrightPassPS(float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
texCoord -= halfPixel; | ||
// Look up the original image color. | ||
float4 c = tex2D(TextureSampler, texCoord); | ||
// Adjust it to keep only values brighter than the specified threshold. | ||
return saturate((c - BloomThreshold) / (1 - BloomThreshold)); | ||
} | ||
technique BloomExtract | ||
{ | ||
pass P0 | ||
{ | ||
PixelShader = compile ps_2_0 BrightPassPS(); | ||
} | ||
} | ||
|
||
|
||
sampler2D Scene: register(s0){ | ||
AddressU = Mirror; | ||
AddressV = Mirror; | ||
}; | ||
texture OrgScene; | ||
sampler2D orgScene = sampler_state | ||
{ | ||
Texture = <OrgScene>; | ||
AddressU = CLAMP; | ||
AddressV = CLAMP; | ||
}; | ||
|
||
|
||
float4 BlendPS(float2 texCoord : TEXCOORD0 ) : COLOR0 | ||
{ | ||
texCoord -= halfPixel; | ||
float4 col = tex2D(orgScene,texCoord) * tex2D(Scene,texCoord); | ||
return col; | ||
} | ||
float4 AditivePS(float2 texCoord : TEXCOORD0 ) : COLOR0 | ||
{ | ||
texCoord -= halfPixel; | ||
float4 col = tex2D(orgScene,texCoord) + tex2D(Scene,texCoord); | ||
return col; | ||
} | ||
technique Blend | ||
{ | ||
pass p0 | ||
{ | ||
PixelShader = compile ps_2_0 BlendPS(); | ||
} | ||
} | ||
technique Aditive | ||
{ | ||
pass p0 | ||
{ | ||
PixelShader = compile ps_2_0 AditivePS(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#define RADIUS 7 | ||
#define KERNEL_SIZE (RADIUS * 2 + 1) | ||
|
||
//----------------------------------------------------------------------------- | ||
// Globals. | ||
//----------------------------------------------------------------------------- | ||
|
||
float weights[KERNEL_SIZE]; | ||
float2 offsets[KERNEL_SIZE]; | ||
|
||
//----------------------------------------------------------------------------- | ||
// Textures. | ||
//----------------------------------------------------------------------------- | ||
|
||
sampler colorMap : register(s0); | ||
|
||
//----------------------------------------------------------------------------- | ||
// Pixel Shaders. | ||
//----------------------------------------------------------------------------- | ||
|
||
float4 PS_GaussianBlur(float2 texCoord : TEXCOORD) : COLOR0 | ||
{ | ||
float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); | ||
|
||
for (int i = 0; i < KERNEL_SIZE; ++i) | ||
color += tex2D(colorMap, texCoord + offsets[i]) * weights[i]; | ||
|
||
return color; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Techniques. | ||
//----------------------------------------------------------------------------- | ||
|
||
technique GaussianBlur | ||
{ | ||
pass | ||
{ | ||
PixelShader = compile ps_2_0 PS_GaussianBlur(); | ||
} | ||
} |
Oops, something went wrong.