From 2ec6e8fbda3cf2a33f507a9bd0b86871460f2994 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 16 Jan 2008 20:56:54 +0000 Subject: [PATCH] Added normal based material. --- .../programs/NormalFragmentProgram.cg | 10 +++++++ .../materials/programs/NormalVertexProgram.cg | 27 +++++++++++++++++++ media/materials/programs/Thermite.program | 14 ++++++++++ media/materials/scripts/Normal.material | 18 +++++++++++++ source/PolyVoxSceneManager.cpp | 16 ----------- 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 media/materials/programs/NormalFragmentProgram.cg create mode 100644 media/materials/programs/NormalVertexProgram.cg create mode 100644 media/materials/scripts/Normal.material diff --git a/media/materials/programs/NormalFragmentProgram.cg b/media/materials/programs/NormalFragmentProgram.cg new file mode 100644 index 00000000..fe5c6bf7 --- /dev/null +++ b/media/materials/programs/NormalFragmentProgram.cg @@ -0,0 +1,10 @@ +struct v2f +{ + float4 Position : POSITION; //in projection space + float4 Normal : TEXCOORD0; +}; + +float4 main(v2f IN) : COLOR +{ + return abs(IN.Normal); +} \ No newline at end of file diff --git a/media/materials/programs/NormalVertexProgram.cg b/media/materials/programs/NormalVertexProgram.cg new file mode 100644 index 00000000..4302e33b --- /dev/null +++ b/media/materials/programs/NormalVertexProgram.cg @@ -0,0 +1,27 @@ +struct a2v +{ + float4 Position : POSITION; //in object space + float3 Normal : NORMAL; + float2 Alpha : TEXCOORD0; +}; + +struct v2f +{ + float4 Position : POSITION; //in projection space + float4 Normal : TEXCOORD0; +}; + +v2f main(a2v IN, uniform float4x4 world, uniform float4x4 viewProj) +{ + v2f OUT; + + OUT.Position = mul(world, IN.Position); + + IN.Normal = normalize(IN.Normal); + + OUT.Normal = float4(IN.Normal,0.0); + + OUT.Position = mul(viewProj, OUT.Position); + + return OUT; +} \ No newline at end of file diff --git a/media/materials/programs/Thermite.program b/media/materials/programs/Thermite.program index 938f190d..ed7a01d4 100644 --- a/media/materials/programs/Thermite.program +++ b/media/materials/programs/Thermite.program @@ -94,4 +94,18 @@ fragment_program TextureAtlasExperimentalFragmentProgram cg source TextureAtlasExperimentalFragmentProgram.cg entry_point main profiles ps_1_1 arbfp1 +} + +vertex_program NormalVertexProgram cg +{ + source NormalVertexProgram.cg + entry_point main + profiles vs_1_1 arbvp1 +} + +fragment_program NormalFragmentProgram cg +{ + source NormalFragmentProgram.cg + entry_point main + profiles ps_1_1 arbfp1 } \ No newline at end of file diff --git a/media/materials/scripts/Normal.material b/media/materials/scripts/Normal.material new file mode 100644 index 00000000..db4e0ab9 --- /dev/null +++ b/media/materials/scripts/Normal.material @@ -0,0 +1,18 @@ +material NormalMaterial +{ + technique + { + pass + { + vertex_program_ref NormalVertexProgram + { + param_named_auto world world_matrix + param_named_auto viewProj viewproj_matrix + } + + fragment_program_ref NormalFragmentProgram + { + } + } + } +} diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index b2cd1408..713a7749 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -520,22 +520,6 @@ namespace Ogre const uchar material0 = vertMaterials[triTable[iCubeIndex][i ]]; const uchar material1 = vertMaterials[triTable[iCubeIndex][i+1]]; const uchar material2 = vertMaterials[triTable[iCubeIndex][i+2]]; - - /*if(surfacePatchMapResult.find(material0) == surfacePatchMapResult.end()) - { - surfacePatchMapResult.insert(std::make_pair(material0,new IndexedSurfacePatch)); - } - if(surfacePatchMapResult.find(material1) == surfacePatchMapResult.end()) - { - surfacePatchMapResult.insert(std::make_pair(material1,new IndexedSurfacePatch)); - } - if(surfacePatchMapResult.find(material2) == surfacePatchMapResult.end()) - { - surfacePatchMapResult.insert(std::make_pair(material2,new IndexedSurfacePatch)); - }*/ - - //float materialToUse = std::max(material0,std::max(material1,material2)); - //If all the materials are the same, we just need one triangle for that material with all the alphas set high.