From 58f30cf003a6b7b3686f70fa0539aa45d126b457 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 6 Feb 2011 04:02:38 +0100 Subject: shader reading support --- NW4RTools/BrresReader.cs | 33 ++++++++++++++++++++++++++------- NW4RTools/Models/Material.cs | 1 + NW4RTools/Models/Shader.cs | 5 +++++ NW4RTools/bin/Debug/NW4RTools.dll | Bin 28672 -> 29184 bytes NW4RTools/bin/Debug/NW4RTools.dll.mdb | Bin 10087 -> 10124 bytes 5 files changed, 32 insertions(+), 7 deletions(-) (limited to 'NW4RTools') diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index 36634d0..cd9452d 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -146,7 +146,7 @@ namespace NW4RTools { // Load vertex data // COMMENTED OUT TO MAKE DEUBG OUTPUT CLEARER FOR NOW - /* + /* using (var c2 = Debug.Push("Vertex Position Data")) mdl.VtxPosData = ReadAndConvertDict(ins.At(startPos + vtxPosOffset), ConvertVtxPosData); using (var c2 = Debug.Push("Vertex Normal Data")) @@ -155,15 +155,18 @@ namespace NW4RTools { mdl.VtxClrData = ReadAndConvertDict(ins.At(startPos + vtxClrOffset), ConvertVtxClrData); using (var c2 = Debug.Push("Vertex TexCoord Data")) mdl.VtxTexCoordData = ReadAndConvertDict(ins.At(startPos + texCoordOffset), ConvertVtxTexCoordData); - */ + //*/ - // Load materials - using (var c2 = Debug.Push("Materials")) - mdl.Materials = ReadAndConvertDict(ins.At(startPos + materialOffset), ConvertModelMaterial); + // Load materials and associated structs + // Material classes refer to Shaders using an offset, so this is used to fix those up + ShaderOffsetRefs = new Dictionary(); using (var c2 = Debug.Push("Shaders")) mdl.Shaders = ReadAndConvertDict(ins.At(startPos + shaderOffset), ConvertModelShader); + using (var c2 = Debug.Push("Materials")) + mdl.Materials = ReadAndConvertDict(ins.At(startPos + materialOffset), ConvertModelMaterial); + return mdl; } } @@ -412,9 +415,8 @@ namespace NW4RTools { ins.Skip(1); // Other stuff - // Shader offset points to an entry in the Shaders group, must fix this up later - // like I did with Node classes Int32 shaderOffset = ins.ReadInt32(); + m.ShaderRef = ShaderOffsetRefs[startPos + shaderOffset]; //Debug.Send("Shader offset for {0}: {1:X} [dest {2:X}]", name, shaderOffset, startPos + shaderOffset); UInt32 boundTexCount = ins.ReadUInt32(); @@ -556,6 +558,8 @@ namespace NW4RTools { + private Dictionary ShaderOffsetRefs; + private Models.Shader ConvertModelShader(string name, InputStream ins) { var s = new Models.Shader(); @@ -569,6 +573,21 @@ namespace NW4RTools { // if I'm making sense or not. Too tired to look it up, it's 4:51am... OffsetMap[ins.Position] = "Shader: " + name; + UInt32 size = ins.ReadUInt32(); + Int32 mdlOffset = ins.ReadInt32(); + + s.Index = ins.ReadUInt32(); + s.TevStageCount = ins.ReadByte(); + ins.Skip(3); + + s.Unk1 = ins.ReadUInt32(); + s.Unk2 = ins.ReadUInt32(); + ins.Skip(8); + + s.DisplayList = ins.ReadBytes(0x1E0); + + ShaderOffsetRefs[startPos] = s; + return s; } diff --git a/NW4RTools/Models/Material.cs b/NW4RTools/Models/Material.cs index 8ece6ad..8ca5082 100644 --- a/NW4RTools/Models/Material.cs +++ b/NW4RTools/Models/Material.cs @@ -55,6 +55,7 @@ namespace NW4RTools.Models { // Other public List BoundTextures; + public Shader ShaderRef; // Display Lists public byte[] PixDL; diff --git a/NW4RTools/Models/Shader.cs b/NW4RTools/Models/Shader.cs index 42586da..767470e 100644 --- a/NW4RTools/Models/Shader.cs +++ b/NW4RTools/Models/Shader.cs @@ -3,6 +3,11 @@ using System.Collections.Generic; namespace NW4RTools.Models { public class Shader { + public UInt32 Index; + public byte TevStageCount; + public UInt32 Unk1, Unk2; // TODO: figure these out + public byte[] DisplayList; + public Shader() { } } diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll index fcfb2a6..dc75f55 100755 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll and b/NW4RTools/bin/Debug/NW4RTools.dll differ diff --git a/NW4RTools/bin/Debug/NW4RTools.dll.mdb b/NW4RTools/bin/Debug/NW4RTools.dll.mdb index 7d4ac90..00c8b7b 100644 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll.mdb and b/NW4RTools/bin/Debug/NW4RTools.dll.mdb differ -- cgit v1.2.3