Browse Source

Adapted AutoExposure & BloomHDR shaders. Improved GLSL commenting out of the unnecessary shader function.

Lasse Öörni 12 years ago
parent
commit
2b95618cdb

+ 20 - 7
Bin/CoreData/Shaders/GLSL/AutoExposure.frag → Bin/CoreData/Shaders/GLSL/AutoExposure.glsl

@@ -1,7 +1,22 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "PostProcess.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
 
 
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+#ifdef COMPILEPS
 uniform float cAutoExposureAdaptRate;
 uniform float cAutoExposureAdaptRate;
 uniform float cAutoExposureMiddleGrey;
 uniform float cAutoExposureMiddleGrey;
 uniform float cAutoExposureSensitivity;
 uniform float cAutoExposureSensitivity;
@@ -10,9 +25,6 @@ uniform vec2 cLum64InvSize;
 uniform vec2 cLum16InvSize;
 uniform vec2 cLum16InvSize;
 uniform vec2 cLum4InvSize;
 uniform vec2 cLum4InvSize;
 
 
-varying vec2 vTexCoord;
-varying vec2 vScreenPos;
-
 float GatherAvgLum(sampler2D texSampler, vec2 texCoord, vec2 texelSize)
 float GatherAvgLum(sampler2D texSampler, vec2 texCoord, vec2 texelSize)
 {
 {
     float lumAvg = 0.0;
     float lumAvg = 0.0;
@@ -22,8 +34,9 @@ float GatherAvgLum(sampler2D texSampler, vec2 texCoord, vec2 texelSize)
     lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
     lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
     return lumAvg / 4.0;
     return lumAvg / 4.0;
 }
 }
+#endif
 
 
-void main()
+void PS()
 {
 {
     #ifdef LUMINANCE64
     #ifdef LUMINANCE64
     float logLumSum = 1e-5;
     float logLumSum = 1e-5;

+ 0 - 15
Bin/CoreData/Shaders/GLSL/AutoExposure.vert

@@ -1,15 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-varying vec2 vTexCoord;
-varying vec2 vScreenPos;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetQuadTexCoord(gl_Position);
-    vScreenPos = GetScreenPosPreDiv(gl_Position);
-}

+ 0 - 18
Bin/CoreData/Shaders/GLSL/AutoExposure.xml

@@ -1,18 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="Luminance64" define="LUMINANCE64" />
-        <variation name="Luminance16" define="LUMINANCE16" />
-        <variation name="Luminance4" define="LUMINANCE4" />
-        <variation name="Luminance1" define="LUMINANCE1" />
-        <variation name="AdaptLuminance" define="ADAPTLUMINANCE" />
-        <variation name="Expose" define="EXPOSE" />
-    </shader>
-    <shader type="ps">
-        <variation name="Luminance64" define="LUMINANCE64" />
-        <variation name="Luminance16" define="LUMINANCE16" />
-        <variation name="Luminance4" define="LUMINANCE4" />
-        <variation name="Luminance1" define="LUMINANCE1" />
-        <variation name="AdaptLuminance" define="ADAPTLUMINANCE" />
-        <variation name="Expose" define="EXPOSE" />
-    </shader>
-</shaders>

+ 20 - 7
Bin/CoreData/Shaders/GLSL/BloomHDR.frag → Bin/CoreData/Shaders/GLSL/BloomHDR.glsl

@@ -1,7 +1,22 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "PostProcess.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
 
 
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+#ifdef COMPILEPS
 uniform float cBloomHDRThreshold;
 uniform float cBloomHDRThreshold;
 uniform float cBloomHDRBlurSigma;
 uniform float cBloomHDRBlurSigma;
 uniform float cBloomHDRBlurRadius;
 uniform float cBloomHDRBlurRadius;
@@ -12,12 +27,10 @@ uniform vec2 cBright4InvSize;
 uniform vec2 cBright8InvSize;
 uniform vec2 cBright8InvSize;
 uniform vec2 cBright16InvSize;
 uniform vec2 cBright16InvSize;
 
 
-varying vec2 vTexCoord;
-varying vec2 vScreenPos;
-
 const int BlurKernelSize = 5;
 const int BlurKernelSize = 5;
+#endif
 
 
-void main()
+void PS()
 {
 {
     #ifdef BRIGHT
     #ifdef BRIGHT
     vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
     vec3 color = texture2D(sDiffMap, vScreenPos).rgb;

+ 0 - 15
Bin/CoreData/Shaders/GLSL/BloomHDR.vert

@@ -1,15 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-varying vec2 vTexCoord;
-varying vec2 vScreenPos;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetQuadTexCoord(gl_Position);
-    vScreenPos = GetScreenPosPreDiv(gl_Position);
-}

+ 0 - 24
Bin/CoreData/Shaders/GLSL/BloomHDR.xml

@@ -1,24 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="Blur2" define="BLUR2" />
-        <variation name="Blur4" define="BLUR4" />
-        <variation name="Blur8" define="BLUR8" />
-        <variation name="Blur16" define="BLUR16" />
-        <variation name="Combine2" define="COMBINE2" />
-        <variation name="Combine4" define="COMBINE4" />
-        <variation name="Combine8" define="COMBINE8" />
-        <variation name="Combine16" define="COMBINE16" />
-    </shader>
-    <shader type="ps">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="Blur2" define="BLUR2" />
-        <variation name="Blur4" define="BLUR4" />
-        <variation name="Blur8" define="BLUR8" />
-        <variation name="Blur16" define="BLUR16" />
-        <variation name="Combine2" define="COMBINE2" />
-        <variation name="Combine4" define="COMBINE4" />
-        <variation name="Combine8" define="COMBINE8" />
-        <variation name="Combine16" define="COMBINE16" />
-    </shader>
-</shaders>

+ 3 - 2
Bin/CoreData/Shaders/GLSL/PostProcess.frag → Bin/CoreData/Shaders/GLSL/PostProcess.glsl

@@ -1,4 +1,4 @@
-
+#ifdef COMPILEPS
 const float PI = 3.14159265;
 const float PI = 3.14159265;
 
 
 vec2 Noise(vec2 coord)
 vec2 Noise(vec2 coord)
@@ -11,7 +11,7 @@ vec2 Noise(vec2 coord)
 // Adapted: http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
 // Adapted: http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
 vec4 GaussianBlur(int blurKernelSize, vec2 blurDir, vec2 blurRadius, float sigma, sampler2D texSampler, vec2 texCoord)
 vec4 GaussianBlur(int blurKernelSize, vec2 blurDir, vec2 blurRadius, float sigma, sampler2D texSampler, vec2 texCoord)
 {
 {
-    const int blurKernelSizeHalfSize = blurKernelSize / 2;
+    int blurKernelSizeHalfSize = blurKernelSize / 2;
 
 
     // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
     // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
     vec3 gaussCoeff;
     vec3 gaussCoeff;
@@ -84,3 +84,4 @@ vec3 ToInverseGamma(vec3 color)
 {
 {
     return vec3(pow(color.r, InverseGamma), pow(color.g, InverseGamma), pow(color.b, InverseGamma));
     return vec3(pow(color.r, InverseGamma), pow(color.g, InverseGamma), pow(color.b, InverseGamma));
 }
 }
+#endif

+ 0 - 18
Bin/CoreData/Shaders/HLSL/AutoExposure.xml

@@ -1,18 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="Luminance64" define="LUMINANCE64" />
-        <variation name="Luminance16" define="LUMINANCE16" />
-        <variation name="Luminance4" define="LUMINANCE4" />
-        <variation name="Luminance1" define="LUMINANCE1" />
-        <variation name="AdaptLuminance" define="ADAPTLUMINANCE" />
-        <variation name="Expose" define="EXPOSE" />
-    </shader>
-    <shader type="ps">
-        <variation name="Luminance64" define="LUMINANCE64" />
-        <variation name="Luminance16" define="LUMINANCE16" />
-        <variation name="Luminance4" define="LUMINANCE4" />
-        <variation name="Luminance1" define="LUMINANCE1" />
-        <variation name="AdaptLuminance" define="ADAPTLUMINANCE" />
-        <variation name="Expose" define="EXPOSE" />
-    </shader>
-</shaders>

+ 0 - 24
Bin/CoreData/Shaders/HLSL/BloomHDR.xml

@@ -1,24 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="Blur2" define="BLUR2" />
-        <variation name="Blur4" define="BLUR4" />
-        <variation name="Blur8" define="BLUR8" />
-        <variation name="Blur16" define="BLUR16" />
-        <variation name="Combine2" define="COMBINE2" />
-        <variation name="Combine4" define="COMBINE4" />
-        <variation name="Combine8" define="COMBINE8" />
-        <variation name="Combine16" define="COMBINE16" />
-    </shader>
-    <shader type="ps">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="Blur2" define="BLUR2" />
-        <variation name="Blur4" define="BLUR4" />
-        <variation name="Blur8" define="BLUR8" />
-        <variation name="Blur16" define="BLUR16" />
-        <variation name="Combine2" define="COMBINE2" />
-        <variation name="Combine4" define="COMBINE4" />
-        <variation name="Combine8" define="COMBINE8" />
-        <variation name="Combine16" define="COMBINE16" />
-    </shader>
-</shaders>

+ 6 - 6
Bin/Data/PostProcess/AutoExposure.xml

@@ -9,27 +9,27 @@
     <command type="quad" tag="AutoExposure" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="hdr128">
     <command type="quad" tag="AutoExposure" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="hdr128">
         <texture unit="diffuse" name="viewport" />
         <texture unit="diffuse" name="viewport" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_Luminance64" ps="AutoExposure_Luminance64" output="lum64">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="LUMINANCE64" psdefines="LUMINANCE64" output="lum64">
         <texture unit="diffuse" name="hdr128" />
         <texture unit="diffuse" name="hdr128" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_Luminance16" ps="AutoExposure_Luminance16" output="lum16">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="LUMINANCE16" psdefines="LUMINANCE16" output="lum16">
         <texture unit="diffuse" name="lum64" />
         <texture unit="diffuse" name="lum64" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_Luminance4" ps="AutoExposure_Luminance4" output="lum4">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="LUMINANCE4" psdefines="LUMINANCE4" output="lum4">
         <texture unit="diffuse" name="lum16" />
         <texture unit="diffuse" name="lum16" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_Luminance1" ps="AutoExposure_Luminance1" output="lum1">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="LUMINANCE1" psdefines="LUMINANCE1" output="lum1">
         <texture unit="diffuse" name="lum4" />
         <texture unit="diffuse" name="lum4" />
     </command>
     </command>
     <command type="quad" tag="AutoExposure" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="prevAdaptedLum">
     <command type="quad" tag="AutoExposure" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="prevAdaptedLum">
         <texture unit="diffuse" name="adaptedLum" />
         <texture unit="diffuse" name="adaptedLum" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_AdaptLuminance" ps="AutoExposure_AdaptLuminance" output="adaptedLum">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="ADAPTLUMINANCE" psdefines="ADAPTLUMINANCE" output="adaptedLum">
         <parameter name="AutoExposureAdaptRate" value="0.6" />
         <parameter name="AutoExposureAdaptRate" value="0.6" />
         <texture unit="diffuse" name="prevAdaptedLum" />
         <texture unit="diffuse" name="prevAdaptedLum" />
         <texture unit="normal" name="lum1" />
         <texture unit="normal" name="lum1" />
     </command>
     </command>
-    <command type="quad" tag="AutoExposure" vs="AutoExposure_Expose" ps="AutoExposure_Expose" output="viewport">
+    <command type="quad" tag="AutoExposure" vs="AutoExposure" ps="AutoExposure" vsdefines="EXPOSE" psdefines="EXPOSE" output="viewport">
         <parameter name="AutoExposureMiddleGrey" value="0.8" />
         <parameter name="AutoExposureMiddleGrey" value="0.8" />
         <parameter name="AutoExposureSensitivity" value="1.2" />
         <parameter name="AutoExposureSensitivity" value="1.2" />
         <texture unit="diffuse" name="viewport" />
         <texture unit="diffuse" name="viewport" />

+ 13 - 13
Bin/Data/PostProcess/BloomHDR.xml

@@ -7,7 +7,7 @@
     <rendertarget name="blur4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
     <rendertarget name="blur4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
     <rendertarget name="blur8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
     <rendertarget name="blur8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
     <rendertarget name="blur16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
     <rendertarget name="blur16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Bright" ps="BloomHDR_Bright" output="bright2">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BRIGHT" psdefines="BRIGHT" output="bright2">
         <parameter name="BloomHDRThreshold" value="0.8" />
         <parameter name="BloomHDRThreshold" value="0.8" />
         <texture unit="diffuse" name="viewport" />
         <texture unit="diffuse" name="viewport" />
     </command>
     </command>
@@ -20,67 +20,67 @@
     <command type="quad" tag="BloomHDR" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="bright16">
     <command type="quad" tag="BloomHDR" vs="CopyFrameBuffer" ps="CopyFrameBuffer" output="bright16">
         <texture unit="diffuse" name="bright8" />
         <texture unit="diffuse" name="bright8" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur16" ps="BloomHDR_Blur16" output="blur16">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="blur16">
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="bright16" />
         <texture unit="diffuse" name="bright16" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur16" ps="BloomHDR_Blur16" output="bright16">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="bright16">
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="blur16" />
         <texture unit="diffuse" name="blur16" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Combine16" ps="BloomHDR_Combine16" output="blur8">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE16" psdefines="COMBINE16" output="blur8">
         <texture unit="diffuse" name="bright8" />
         <texture unit="diffuse" name="bright8" />
         <texture unit="normal" name="bright16" />
         <texture unit="normal" name="bright16" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur8" ps="BloomHDR_Blur8" output="bright8">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="bright8">
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="blur8" />
         <texture unit="diffuse" name="blur8" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur8" ps="BloomHDR_Blur8" output="blur8">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="blur8">
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="bright8" />
         <texture unit="diffuse" name="bright8" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Combine8" ps="BloomHDR_Combine8" output="blur4">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE8" psdefines="COMBINE8" output="blur4">
         <texture unit="diffuse" name="bright4" />
         <texture unit="diffuse" name="bright4" />
         <texture unit="normal" name="blur8" />
         <texture unit="normal" name="blur8" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur4" ps="BloomHDR_Blur4" output="bright4">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="bright4">
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="blur4" />
         <texture unit="diffuse" name="blur4" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur4" ps="BloomHDR_Blur4" output="blur4">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="blur4">
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="bright4" />
         <texture unit="diffuse" name="bright4" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Combine4" ps="BloomHDR_Combine4" output="blur2">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE4" psdefines="COMBINE4" output="blur2">
         <texture unit="diffuse" name="bright2" />
         <texture unit="diffuse" name="bright2" />
         <texture unit="normal" name="blur4" />
         <texture unit="normal" name="blur4" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur2" ps="BloomHDR_Blur2" output="bright2">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="bright2">
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="blur2" />
         <texture unit="diffuse" name="blur2" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Blur2" ps="BloomHDR_Blur2" output="blur2">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="blur2">
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurRadius" value="1.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <parameter name="BloomHDRBlurSigma" value="2.0" />
         <texture unit="diffuse" name="bright2" />
         <texture unit="diffuse" name="bright2" />
     </command>
     </command>
-    <command type="quad" tag="BloomHDR" vs="BloomHDR_Combine2" ps="BloomHDR_Combine2" output="viewport">
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE2" psdefines="COMBINE2" output="viewport">
         <parameter name="BloomHDRMix" value="1.0 0.4" />
         <parameter name="BloomHDRMix" value="1.0 0.4" />
         <texture unit="diffuse" name="viewport" />
         <texture unit="diffuse" name="viewport" />
         <texture unit="normal" name="blur2" />
         <texture unit="normal" name="blur2" />

+ 8 - 1
Source/Engine/Graphics/Direct3D9/D3D9ShaderVariation.cpp

@@ -220,6 +220,7 @@ bool ShaderVariation::LoadByteCode(PODVector<unsigned>& byteCode, const String&
 
 
 bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
 bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
 {
 {
+    const String& sourceCode = owner_->GetSourceCode(type_);
     Vector<String> defines = defines_.Split(' ');
     Vector<String> defines = defines_.Split(' ');
     
     
     // Set the entrypoint, profile and flags according to the shader being compiled
     // Set the entrypoint, profile and flags according to the shader being compiled
@@ -274,6 +275,12 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
         macro.Name = defines[i].CString();
         macro.Name = defines[i].CString();
         macro.Definition = defineValues[i].CString();
         macro.Definition = defineValues[i].CString();
         macros.Push(macro);
         macros.Push(macro);
+
+        // In debug mode, check that all defines are referenced by the shader code
+        #ifdef _DEBUG
+        if (sourceCode.Find(defines[i]) == String::NPOS)
+            LOGWARNING("Shader " + GetName() + " does not use the define " + defineCheck);
+        #endif
     }
     }
     
     
     D3D_SHADER_MACRO endMacro;
     D3D_SHADER_MACRO endMacro;
@@ -282,7 +289,7 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
     macros.Push(endMacro);
     macros.Push(endMacro);
     
     
     // Compile using D3DCompile
     // Compile using D3DCompile
-    const String& sourceCode = owner_->GetSourceCode(type_);
+
     LPD3DBLOB shaderCode = 0;
     LPD3DBLOB shaderCode = 0;
     LPD3DBLOB errorMsgs = 0;
     LPD3DBLOB errorMsgs = 0;
     
     

+ 30 - 24
Source/Engine/Graphics/Shader.cpp

@@ -37,6 +37,31 @@
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
+void CommentOutFunction(String& code, const String& signature)
+{
+    unsigned startPos = code.Find(signature);
+    unsigned braceLevel = 0;
+    if (startPos == String::NPOS)
+        return;
+    
+    code.Insert(startPos, "/*");
+    
+    for (unsigned i = startPos + 2 + signature.Length(); i < code.Length(); ++i)
+    {
+        if (code[i] == '{')
+            ++braceLevel;
+        else if (code[i] == '}')
+        {
+            --braceLevel;
+            if (braceLevel == 0)
+            {
+                code.Insert(i + 1, "*/");
+                return;
+            }
+        }
+    }
+}
+
 Shader::Shader(Context* context) :
 Shader::Shader(Context* context) :
     Resource(context),
     Resource(context),
     timeStamp_(0)
     timeStamp_(0)
@@ -69,40 +94,21 @@ bool Shader::Load(Deserializer& source)
     if (!ProcessSource(shaderCode, source))
     if (!ProcessSource(shaderCode, source))
         return false;
         return false;
     
     
-    // Customize the vertex & pixel shader source code to not include the unnecessary shader,
-    // and on OpenGL, rename either VS() or PS() to main()
+    // OpenGL: customize the vertex & pixel shader source code to not include the unnecessary shader,
+    // and rename either VS() or PS() to main()
     #ifdef USE_OPENGL
     #ifdef USE_OPENGL
     vsSourceCode_ = shaderCode;
     vsSourceCode_ = shaderCode;
     vsSourceCode_.Replace("uniform sampler", "// uniform sampler");
     vsSourceCode_.Replace("uniform sampler", "// uniform sampler");
     vsSourceCode_.Replace("void VS(", "void main(");
     vsSourceCode_.Replace("void VS(", "void main(");
-    if (vsSourceCode_.Find("void PS(") != String::NPOS)
-    {
-        vsSourceCode_.Replace("void PS(", "/* void PS(");
-        vsSourceCode_ += "*/\n";
-    }
-    
+    CommentOutFunction(vsSourceCode_, "void PS(");
+
     psSourceCode_ = shaderCode;
     psSourceCode_ = shaderCode;
     psSourceCode_.Replace("attribute ", "// attribute ");
     psSourceCode_.Replace("attribute ", "// attribute ");
     psSourceCode_.Replace("void PS(", "void main(");
     psSourceCode_.Replace("void PS(", "void main(");
-    if (psSourceCode_.Find("void VS(") != String::NPOS)
-    {
-        psSourceCode_.Replace("void VS(", "/* void VS(");
-        psSourceCode_.Replace("void main(", "*/\nvoid main(");
-    }
+    CommentOutFunction(psSourceCode_, "void VS(");
     #else
     #else
     vsSourceCode_ = shaderCode;
     vsSourceCode_ = shaderCode;
-    if (vsSourceCode_.Find("void PS(") != String::NPOS)
-    {
-        vsSourceCode_.Replace("void PS(", "/* void PS(");
-        vsSourceCode_ += "*/\n";
-    }
-    
     psSourceCode_ = shaderCode;
     psSourceCode_ = shaderCode;
-    if (psSourceCode_.Find("void VS(") != String::NPOS)
-    {
-        psSourceCode_.Replace("void VS(", "/* void VS(");
-        psSourceCode_.Replace("void PS(", "*/\nvoid PS(");
-    }
     #endif
     #endif
     
     
     // If variations had already been created, release them and require recompile
     // If variations had already been created, release them and require recompile