Ver Fonte

Updated the shader *.fx files to XNA 4, as per Shawn Hargreaves suggestion of using the Bloom sample. First attempt at porting these shaders to GLSL.

Dominique Louis há 14 anos atrás
pai
commit
f1b70c8f60

+ 34 - 0
StarterKits/MacOS/VectorRumble/Content/Effects/BloomCombine.fsh

@@ -1 +1,35 @@
+uniform sampler2D BloomSampler;
+uniform sampler2D BaseSampler;
 
+uniform vec2 float BloomIntensity;
+uniform vec2 float BaseIntensity;
+
+uniform vec2 float BloomSaturation;
+uniform vec2 float BaseSaturation;
+
+// Helper for modifying the saturation of a color.
+vec4 AdjustSaturation(vec4 color, vec saturation)
+{
+    // The constants 0.3, 0.59, and 0.11 are chosen because the
+    // human eye is more sensitive to green light, and less to blue.
+    vec grey = dot(color, vec3(0.3, 0.59, 0.11));
+
+    return lerp(grey, color, saturation);
+}
+
+void main()
+{
+	// Look up the bloom and original base image colors.
+	vec4 bloom = gl_Color * texture2D(BloomSampler, gl_TexCoord[0].xy);
+	vec4 base = gl_Color * texture2D(BaseSampler, gl_TexCoord[0].xy);
+	
+	// Adjust color saturation and intensity.
+	bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
+    base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
+    
+    // Darken down the base image in areas where there is a lot of bloom,
+    // to prevent things looking excessively burned-out.
+    base *= (1 - clamp(bloom,0.0,1.0));
+	
+    gl_FragColor = base + bloom;
+}

+ 2 - 2
StarterKits/MacOS/VectorRumble/Content/Effects/BloomCombine.fx

@@ -23,7 +23,7 @@ float4 AdjustSaturation(float4 color, float saturation)
 }
 
 
-float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
+float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
 {
     // Look up the bloom and original base image colors.
     float4 bloom = tex2D(BloomSampler, texCoord);
@@ -46,6 +46,6 @@ technique BloomCombine
 {
     pass Pass1
     {
-        PixelShader = compile ps_2_0 PixelShader();
+        PixelShader = compile ps_2_0 PixelShaderFunction();
     }
 }

+ 11 - 28
StarterKits/MacOS/VectorRumble/Content/Effects/BloomExtract.fsh

@@ -1,32 +1,15 @@
-uniform sampler2D bgl_RenderedTexture;
+uniform sampler2D TextureSampler;
+
+uniform vec2 BloomThreshold;
 
 void main()
 {
-   vec4 sum = vec4(0);
-   vec2 texcoord = vec2(gl_TexCoord[0]);
-   int j;
-   int i;
-
-   for( i= -4 ;i < 4; i++)
-   {
-        for (j = -3; j < 3; j++)
-        {
-            sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * 0.25;
-        }
-   }
-       if (texture2D(bgl_RenderedTexture, texcoord).r < 0.3)
-    {
-       gl_FragColor = sum*sum*0.012 + texture2D(bgl_RenderedTexture, texcoord);
-    }
-    else
-    {
-        if (texture2D(bgl_RenderedTexture, texcoord).r < 0.5)
-        {
-            gl_FragColor = sum*sum*0.009 + texture2D(bgl_RenderedTexture, texcoord);
-        }
-        else
-        {
-            gl_FragColor = sum*sum*0.0075 + texture2D(bgl_RenderedTexture, texcoord);
-        }
-    }
+	// Look up the original image color.
+	vec4 tex = gl_Color * texture2D(TextureSampler, gl_TexCoord[0].xy);
+	
+	// Adjust it to keep only values brighter than the specified threshold.
+	vec4 color = tex;
+	color *= clamp((tex.a - BloomThreshold) / (1 - BloomThreshold),0.0,1.0);
+	
+    gl_FragColor = color;
 }

+ 2 - 2
StarterKits/MacOS/VectorRumble/Content/Effects/BloomExtract.fx

@@ -6,7 +6,7 @@ sampler TextureSampler : register(s0);
 float BloomThreshold;
 
 
-float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
+float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
 {
     // Look up the original image color.
     float4 c = tex2D(TextureSampler, texCoord);
@@ -20,6 +20,6 @@ technique BloomExtract
 {
     pass Pass1
     {
-        PixelShader = compile ps_2_0 PixelShader();
+        PixelShader = compile ps_2_0 PixelShaderFunction();
     }
 }

+ 20 - 0
StarterKits/MacOS/VectorRumble/Content/Effects/GaussianBlur.fsh

@@ -1 +1,21 @@
+uniform sampler2D TextureSampler;
 
+#define SAMPLE_COUNT 15
+
+vec2 SampleOffsets[SAMPLE_COUNT];
+vec SampleWeights[SAMPLE_COUNT];
+
+void main()
+{
+	// Look up the original image color.
+	vec4 color = vec4(0);
+   	vec2 texcoord = vec2(gl_TexCoord[0]);
+	
+	// Combine a number of weighted image filter taps.
+    for (int i = 0; i < SAMPLE_COUNT; i++)
+    {
+        color += gl_Color * (texture2D(TextureSampler, texcoord + SampleOffsets[i]) * SampleWeights[i]);
+    }
+	
+    gl_FragColor = color;
+}

+ 2 - 2
StarterKits/MacOS/VectorRumble/Content/Effects/GaussianBlur.fx

@@ -10,7 +10,7 @@ float2 SampleOffsets[SAMPLE_COUNT];
 float SampleWeights[SAMPLE_COUNT];
 
 
-float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
+float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
 {
     float4 c = 0;
     
@@ -28,6 +28,6 @@ technique GaussianBlur
 {
     pass Pass1
     {
-        PixelShader = compile ps_2_0 PixelShader();
+        PixelShader = compile ps_2_0 PixelShaderFunction();
     }
 }