Browse Source

simplify Deferred

Nikos Kastellanos 11 months ago
parent
commit
3cc3a1b1e3

BIN
Shaders/Deferred/Resources/DeferredBasicEffect.dx11.fxo.10


BIN
Shaders/Deferred/Resources/DeferredBasicEffect.ogl.fxo.10


+ 12 - 9
Shaders/Deferred/Shaders/DeferredBasicEffect.fx

@@ -6,9 +6,10 @@ float4x4 Projection;
 float specularIntensity = 0.8f;
 float specularPower = 0.5f; 
 
-DECLARE_TEXTURE(Diffuse, 0) = sampler_state
+//texture2D Diffuse : register(t0);
+sampler DiffuseSampler : register(s0) = sampler_state
 {
-    //Texture = (Diffuse);
+    Texture = (Diffuse);
     MAGFILTER = LINEAR;
     MINFILTER = LINEAR;
     MIPFILTER = LINEAR;
@@ -16,9 +17,10 @@ DECLARE_TEXTURE(Diffuse, 0) = sampler_state
     AddressV = Wrap;
 };
 
-DECLARE_TEXTURE(SpecularMap, 1) = sampler_state
+//texture2D SpecularMap : register(t1);
+sampler SpecularMapSampler : register(s1) = sampler_state
 {
-    //Texture = (SpecularMap);
+    Texture = (SpecularMap);
     MagFilter = LINEAR;
     MinFilter = LINEAR;
     Mipfilter = LINEAR;
@@ -26,9 +28,10 @@ DECLARE_TEXTURE(SpecularMap, 1) = sampler_state
     AddressV = Wrap;
 };
 
-DECLARE_TEXTURE(NormalMap, 2) = sampler_state
+//texture2D NormalMap : register(t2);
+sampler NormalMapSampler : register(s2) = sampler_state
 {
-    //Texture = (NormalMap);
+    Texture = (NormalMap);
     MagFilter = LINEAR;
     MinFilter = LINEAR;
     Mipfilter = LINEAR;
@@ -83,14 +86,14 @@ struct PixelShaderOutput
 PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
 {
     PixelShaderOutput output;
-    output.Color = SAMPLE_TEXTURE(Diffuse, input.TexCoord);
+    output.Color = tex2D(DiffuseSampler, input.TexCoord);
     
-    float4 specularAttributes = SAMPLE_TEXTURE(SpecularMap, input.TexCoord);
+    float4 specularAttributes = tex2D(SpecularMapSampler, input.TexCoord);
     //specular Intensity
     output.Color.a = specularAttributes.r;
     
     // read the normal from the normal map
-    float3 normalFromMap = SAMPLE_TEXTURE(NormalMap, input.TexCoord);
+    float3 normalFromMap = tex2D(NormalMapSampler, input.TexCoord);
     //tranform to [-1,1]
     normalFromMap = 2.0f * normalFromMap - 1.0f;
 	normalFromMap = float3(0,0,1); //if we don't have a normalMap do this!

+ 6 - 4
Shaders/Deferred/Shaders/DeferredCombine.fx

@@ -1,6 +1,7 @@
 #include "Macros.fxh"
 
-DECLARE_TEXTURE(colorMap, 0) = sampler_state
+texture2D colorMap : register(t0);
+sampler colorMapSampler : register(s0) = sampler_state
 {
     Texture = (colorMap);
     AddressU = CLAMP;
@@ -10,7 +11,8 @@ DECLARE_TEXTURE(colorMap, 0) = sampler_state
     Mipfilter = LINEAR;
 };
 
-DECLARE_TEXTURE(lightMap, 1) = sampler_state
+texture2D lightMap : register(t1);
+sampler lightMapSampler : register(s1) = sampler_state
 {
     Texture = (lightMap);
     AddressU = CLAMP;
@@ -44,8 +46,8 @@ VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
 
 float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
 {
-    float3 diffuseColor = SAMPLE_TEXTURE(colorMap,input.TexCoord).rgb;
-    float4 light = SAMPLE_TEXTURE(lightMap,input.TexCoord);
+    float3 diffuseColor = tex2D(colorMapSampler, input.TexCoord).rgb;
+    float4 light = tex2D(lightMapSampler, input.TexCoord);
     float3 diffuseLight = light.rgb;
     float specularLight = light.a;
 	return float4((diffuseColor * diffuseLight + specularLight),1);

+ 9 - 6
Shaders/Deferred/Shaders/DeferredPointLight.fx

@@ -23,7 +23,8 @@ float lightRadius;
 float lightIntensity = 1.0f;
 
 // diffuse color, and specularIntensity in the alpha channel
-DECLARE_TEXTURE(colorMap, 0) = sampler_state
+texture2D colorMap : register(t0);
+sampler colorMapSampler : register(s0) = sampler_state
 {
     Texture = (colorMap);
     AddressU = CLAMP;
@@ -34,7 +35,8 @@ DECLARE_TEXTURE(colorMap, 0) = sampler_state
 };
 
 // normals, and specularPower in the alpha channel
-DECLARE_TEXTURE(normalMap, 1) = sampler_state
+texture2D normalMap : register(t1);
+sampler normalMapSampler : register(s1) = sampler_state
 {
     Texture = (normalMap);
     AddressU = CLAMP;
@@ -45,7 +47,8 @@ DECLARE_TEXTURE(normalMap, 1) = sampler_state
 };
 
 //depth
-DECLARE_TEXTURE(depthMap, 2) = sampler_state
+texture2D depthMap : register(t2);
+sampler depthMapSampler : register(s2) = sampler_state
 {
     Texture = (depthMap);
     AddressU = CLAMP;
@@ -91,17 +94,17 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
     texCoord -=halfPixel;
 
     //get normal data from the normalMap
-    float4 normalData = SAMPLE_TEXTURE(normalMap,texCoord);
+    float4 normalData = tex2D(normalMapSampler, texCoord);
     //tranform normal back into [-1,1] range
     float3 normal = 2.0f * normalData.xyz - 1.0f;
 
     //get specular power
     float specularPower = normalData.a * 255;
     //get specular intensity from the colorMap
-    float specularIntensity = SAMPLE_TEXTURE(colorMap,texCoord).a;
+    float specularIntensity = tex2D(colorMapSampler, texCoord).a;
 
     //read depth
-    float depthVal = SAMPLE_TEXTURE(depthMap,texCoord).r;
+    float depthVal = tex2D(depthMapSampler, texCoord).r;
 
     //compute screen-space position
     float4 position;

+ 9 - 7
Shaders/Deferred/Shaders/DeferredSpotLight.fx

@@ -28,7 +28,8 @@ float outerAngleCos;
 //control the brightness of the light
 float lightIntensity = 1.0f;
 
-DECLARE_TEXTURE(colorMap, 0) = sampler_state
+texture2D colorMap : register(t0);
+sampler colorMapSampler : register(s0) = sampler_state
 {
     Texture = (colorMap);
     AddressU = CLAMP;
@@ -39,7 +40,8 @@ DECLARE_TEXTURE(colorMap, 0) = sampler_state
 };
 
 // normals, and specularPower in the alpha channel
-DECLARE_TEXTURE(normalMap, 1) = sampler_state
+texture2D normalMap : register(t1);
+sampler normalMapSampler : register(s1) = sampler_state
 {
     Texture = (normalMap);
     AddressU = CLAMP;
@@ -50,7 +52,8 @@ DECLARE_TEXTURE(normalMap, 1) = sampler_state
 };
 
 //depth
-DECLARE_TEXTURE(depthMap, 2) = sampler_state
+texture2D depthMap : register(t2);
+sampler depthMapSampler : register(s2) = sampler_state
 {
     Texture = (depthMap);
     AddressU = CLAMP;
@@ -60,7 +63,6 @@ DECLARE_TEXTURE(depthMap, 2) = sampler_state
     Mipfilter = POINT;
 };
 
-
 struct VertexShaderInput
 {
     float3 Position : POSITION0;
@@ -97,17 +99,17 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
     texCoord -=halfPixel;
 
     //get normal data from the normalMap
-    float4 normalData = SAMPLE_TEXTURE(normalMap,texCoord);
+    float4 normalData = tex2D(normalMapSampler, texCoord);
     //tranform normal back into [-1,1] range
     float3 normal = 2.0f * normalData.xyz - 1.0f;
 
     //get specular power
     float specularPower = normalData.a * 255;
     //get specular intensity from the colorMap
-    float specularIntensity = SAMPLE_TEXTURE(colorMap,texCoord).a;
+    float specularIntensity = tex2D(colorMapSampler, texCoord).a;
 
     //read depth
-    float depthVal = SAMPLE_TEXTURE(depthMap,texCoord).r;
+    float depthVal = tex2D(depthMapSampler, texCoord).r;
 
     //compute screen-space position
     float4 position;

+ 0 - 10
Shaders/Deferred/Shaders/Macros.fxh

@@ -9,17 +9,7 @@
 #define TECHNIQUE(name, vsname, psname ) \
 	technique name { pass { VertexShader = compile vs_2_0 vsname (); PixelShader = compile ps_2_0 psname(); } }
 
-
-#define DECLARE_TEXTURE(Name, index) \
-    texture2D Name : register(t##index); \
-    sampler Name##Sampler : register(s##index) 
-
-#define DECLARE_CUBEMAP(Name, index) \
-    textureCUBE Name : register(t##index); \
-    sampler Name##Sampler : register(s##index) 
-
 #define SAMPLE_TEXTURE(Name, texCoord)  tex2D(Name##Sampler, texCoord)
-#define SAMPLE_CUBEMAP(Name, texCoord)  texCUBE(Name##Sampler, texCoord)
 
 
 #ifdef SM4  // Macros for targetting HLSL 4.0