Browse Source

Allow to use RGB normal maps. Different material techniques are used for xGxR normal maps.

Lasse Öörni 13 years ago
parent
commit
570c48c5cf

+ 1 - 0
Bin/CoreData/Shaders/GLSL/LitSolid.xml

@@ -28,6 +28,7 @@
     <shader type="ps">
     <shader type="ps">
         <option name="Diff" define="DIFFMAP" />
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
+        <option name="Packed" define="PACKEDNORMAL" require="NORMALMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
         <option name="EnvCube" define="ENVCUBEMAP" />
         <option name="EnvCube" define="ENVCUBEMAP" />
         <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />

+ 8 - 4
Bin/CoreData/Shaders/GLSL/Samplers.frag

@@ -22,10 +22,14 @@ uniform sampler2D sShadowMap;
 
 
 vec3 DecodeNormal(vec4 normalInput)
 vec3 DecodeNormal(vec4 normalInput)
 {
 {
-    vec3 normal;
-    normal.xy = normalInput.ag * 2.0 - 1.0;
-    normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
-    return normal;
+    #ifdef PACKEDNORMAL
+        vec3 normal;
+        normal.xy = normalInput.ag * 2.0 - 1.0;
+        normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
+        return normal;
+    #else
+        return normalize(normalInput.rgb);
+    #endif
 }
 }
 
 
 vec3 EncodeDepth(float depth)
 vec3 EncodeDepth(float depth)

+ 1 - 0
Bin/CoreData/Shaders/HLSL/LitSolid.xml

@@ -29,6 +29,7 @@
     <shader type="ps">
     <shader type="ps">
         <option name="Diff" define="DIFFMAP" />
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
+        <option name="Packed" define="PACKEDNORMAL" require="NORMALMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
         <option name="EnvCube" define="ENVCUBEMAP" />
         <option name="EnvCube" define="ENVCUBEMAP" />
         <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />

+ 8 - 4
Bin/CoreData/Shaders/HLSL/Samplers.hlsl

@@ -28,8 +28,12 @@ float4 Sample(sampler2D map, float2 texCoord)
 
 
 float3 DecodeNormal(float4 normalInput)
 float3 DecodeNormal(float4 normalInput)
 {
 {
-    float3 normal;
-    normal.xy = normalInput.ag * 2.0 - 1.0;
-    normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
-    return normal;
+    #ifdef PACKEDNORMAL
+        float3 normal;
+        normal.xy = normalInput.ag * 2.0 - 1.0;
+        normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
+        return normal;
+    #else
+        return normalize(normalInput.rgb);
+    #endif
 }
 }

+ 10 - 0
Bin/CoreData/Techniques/DiffNormalPacked.xml

@@ -0,0 +1,10 @@
+<technique>
+    <pass name="base" vs="LitSolid" ps="LitSolid_Diff" />
+    <pass name="litbase" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedAmbient" />
+    <pass name="light" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPacked" depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="prepass" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedPrepass" />
+    <pass name="material" vs="LitSolid" ps="LitSolid_DiffMaterial" depthtest="equal" depthwrite="false" />
+    <pass name="deferred" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedDeferred" />
+    <pass name="depth" vs="Depth" ps="Depth" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 5 - 0
Bin/CoreData/Techniques/DiffNormalPackedAlpha.xml

@@ -0,0 +1,5 @@
+<technique>
+    <pass name="alpha" vs="LitSolid" ps="LitSolid_Diff" depthwrite="false" blend="alpha" />
+    <pass name="litalpha" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPacked" depthwrite="false" blend="addalpha" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 10 - 0
Bin/CoreData/Techniques/DiffNormalPackedAlphaMask.xml

@@ -0,0 +1,10 @@
+<technique>
+    <pass name="base" vs="LitSolid" ps="LitSolid_DiffAlphaMask" alphamask="true" />
+    <pass name="litbase" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedAlphaMaskAmbient" alphamask="true" />
+    <pass name="light" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedAlphaMask" depthtest="equal" depthwrite="false" blend="add" alphamask="true" />
+    <pass name="prepass" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedAlphaMaskPrepass" alphamask="true" />
+    <pass name="material" vs="LitSolid" ps="LitSolid_DiffAlphaMaskMaterial" depthtest="equal" depthwrite="false" alphamask="true" />
+    <pass name="deferred" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedAlphaMaskDeferred" alphamask="true" />
+    <pass name="depth" vs="Depth" ps="Depth_AlphaMask" alphamask="true" />
+    <pass name="shadow" vs="Shadow" ps="Shadow_AlphaMask" alphamask="true" />
+</technique>

+ 9 - 0
Bin/CoreData/Techniques/DiffNormalPackedEnvCube.xml

@@ -0,0 +1,9 @@
+<technique>
+    <pass name="base" vs="LitSolid_NormalEnvCube" ps="LitSolid_DiffNormalPackedEnvCube" />
+    <pass name="light" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPacked" depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="prepass" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedPrepass" />
+    <pass name="material" vs="LitSolid_NormalEnvCube" ps="LitSolid_DiffNormalPackedEnvCubeMaterial" depthtest="equal" depthwrite="false" />
+    <pass name="deferred" vs="LitSolid_NormalEnvCube" ps="LitSolid_DiffNormalPackedEnvCubeDeferred" />
+    <pass name="depth" vs="Depth" ps="Depth" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 5 - 0
Bin/CoreData/Techniques/DiffNormalPackedEnvCubeAlpha.xml

@@ -0,0 +1,5 @@
+<technique>
+    <pass name="alpha" vs="LitSolid_NormalEnvCube" ps="LitSolid_DiffNormalPackedEnvCube" depthwrite="false" blend="alpha" />
+    <pass name="litalpha" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPacked" depthwrite="false" blend="addalpha" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 10 - 0
Bin/CoreData/Techniques/DiffNormalPackedSpec.xml

@@ -0,0 +1,10 @@
+<technique>
+    <pass name="base" vs="LitSolid" ps="LitSolid_Diff" />
+    <pass name="litbase" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapAmbient" />
+    <pass name="light" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMap" depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="prepass" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapPrepass" />
+    <pass name="material" vs="LitSolid" ps="LitSolid_DiffSpecMapMaterial" depthtest="equal" depthwrite="false" />
+    <pass name="deferred" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapDeferred" />
+    <pass name="depth" vs="Depth" ps="Depth" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 5 - 0
Bin/CoreData/Techniques/DiffNormalPackedSpecAlpha.xml

@@ -0,0 +1,5 @@
+<technique>
+    <pass name="alpha" vs="LitSolid" ps="LitSolid_Diff" depthwrite="false" blend="alpha" />
+    <pass name="litalpha" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMap" depthwrite="false" blend="addalpha" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 10 - 0
Bin/CoreData/Techniques/DiffNormalPackedSpecAlphaMask.xml

@@ -0,0 +1,10 @@
+<technique>
+    <pass name="base" vs="LitSolid" ps="LitSolid_DiffAlphaMask" alphamask="true" />
+    <pass name="litbase" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapAlphaMaskAmbient" alphamask="true" />
+    <pass name="light" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapAlphaMask" depthtest="equal" depthwrite="false" blend="add" alphamask="true" />
+    <pass name="prepass" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapAlphaMaskPrepass" alphamask="true" />
+    <pass name="material" vs="LitSolid" ps="LitSolid_DiffSpecMapAlphaMaskMaterial" depthtest="equal" depthwrite="false" alphamask="true" />
+    <pass name="deferred" vs="LitSolid_Normal" ps="LitSolid_DiffNormalPackedSpecMapAlphaMaskDeferred" alphamask="true" />
+    <pass name="depth" vs="Depth" ps="Depth_AlphaMask" alphamask="true" />
+    <pass name="shadow" vs="Shadow" ps="Shadow_AlphaMask" alphamask="true" />
+</technique>

+ 1 - 1
Bin/Data/Materials/Stone.xml

@@ -1,5 +1,5 @@
 <material>
 <material>
-    <technique name="Techniques/DiffNormal.xml" quality="1" />
+    <technique name="Techniques/DiffNormalPacked.xml" quality="1" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />

+ 1 - 1
Bin/Data/Materials/StoneEnvMap.xml

@@ -1,5 +1,5 @@
 <material>
 <material>
-    <technique name="Techniques/DiffNormalEnvCube.xml" quality="1" />
+    <technique name="Techniques/DiffNormalPackedEnvCube.xml" quality="1" />
     <technique name="Techniques/DiffEnvCube.xml" quality="0" />
     <technique name="Techniques/DiffEnvCube.xml" quality="0" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />

+ 1 - 1
Bin/Data/Materials/StoneSmall.xml

@@ -1,5 +1,5 @@
 <material>
 <material>
-    <technique name="Techniques/DiffNormal.xml" quality="1" />
+    <technique name="Techniques/DiffNormalPacked.xml" quality="1" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />

+ 1 - 1
Bin/Data/Materials/StoneTiled.xml

@@ -1,5 +1,5 @@
 <material>
 <material>
-    <technique name="Techniques/DiffNormal.xml" quality="1" />
+    <technique name="Techniques/DiffNormalPacked.xml" quality="1" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />

+ 1 - 1
Bin/Data/Materials/StoneTiledH.xml

@@ -1,5 +1,5 @@
 <material>
 <material>
-    <technique name="Techniques/DiffNormal.xml" quality="1" />
+    <technique name="Techniques/DiffNormalPacked.xml" quality="1" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <technique name="Techniques/Diff.xml" quality="0" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />
     <texture unit="normal" name="Textures/StoneNormal.dds" />

+ 6 - 1
Docs/Reference.dox

@@ -632,7 +632,12 @@ Default culling mode is counterclockwise. The shadowcull element specifies the c
 
 
 Diffuse maps specify the surface color in the RGB channels. Optionally they can use the alpha channel for blending and alpha testing. They should preferably be compressed to DXT1 (no alpha or 1-bit alpha) or DXT5 (smooth alpha) format.
 Diffuse maps specify the surface color in the RGB channels. Optionally they can use the alpha channel for blending and alpha testing. They should preferably be compressed to DXT1 (no alpha or 1-bit alpha) or DXT5 (smooth alpha) format.
 
 
-Normal maps encode the tangent-space surface normal for normal mapping. They need to be stored as xGxR, ie. Y-component in the green channel, and X-component in the alpha (Z will be reconstructed in the pixel shader.) This encoding lends itself well to DXT5 compression. To convert normal maps to this format, you can use AMD's The Compressonator utility, see http://developer.amd.com/Resources/archive/ArchivedTools/gpu/compressonator/Pages/default.aspx Before compression, make sure the normal map is oriented correctly: an even surface should have the color value R 0.5 G 0.5 B 1.0.
+Normal maps encode the tangent-space surface normal for normal mapping. There are two options for storing normals, which require choosing the correct material technique, as the pixel shader is different in each case:
+
+- Store as RGB. In this case use the DiffNormal techniques. This is the default used by AssetImporter, to ensure no conversion of normal textures needs to happen.
+- Store as xGxR, ie. Y-component in the green channel, and X-component in the alpha. In this case use the DiffNormalPacked techniques: Z will be reconstructed in the pixel shader. This encoding lends itself well to DXT5 compression. To convert normal maps to this format, you can use AMD's The Compressonator utility, see http://developer.amd.com/Resources/archive/ArchivedTools/gpu/compressonator/Pages/default.aspx 
+
+Make sure the normal map is oriented correctly: an even surface should have the color value R 0.5 G 0.5 B 1.0.
 
 
 Specular maps encode the specular surface color as RGB. Note that deferred rendering is only able to use monochromatic specular intensity from the G channel, while forward and light pre-pass rendering use fully colored specular. DXT1 format should suit these textures well.
 Specular maps encode the specular surface color as RGB. Note that deferred rendering is only able to use monochromatic specular intensity from the G channel, while forward and light pre-pass rendering use fully colored specular. DXT1 format should suit these textures well.