Skip to content

Commit 68abce4

Browse files
committed
cst offset/length
1 parent 1810509 commit 68abce4

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

CathodeLib/Scripts/CATHODE/Materials.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ override protected bool LoadInternal()
7373
for (int x = 0; x < 5; x++)
7474
{
7575
int cstCount = reader.ReadByte();
76-
material.ConstantBuffers.Add(new Material.ConstantBuffer() { ShaderIndex = x, CstIndex = cstIndexes[x], CstCount = cstCount });
76+
//TODO: just read the CST data into the material
77+
material.ConstantBuffers.Add(new Material.ConstantBuffer() { Offset = cstIndexes[x], Length = cstCount });
7778
}
7879
reader.BaseStream.Position += 7;
7980
material.UnknownValue0 = reader.ReadInt32();
@@ -151,15 +152,13 @@ override protected bool SaveInternal()
151152
if (Entries[i].ConstantBuffers.Count > 5) throw new Exception("Too many constant buffer definitions!");
152153
for (int x = 0; x < 5; x++)
153154
{
154-
Material.ConstantBuffer cst = Entries[i].ConstantBuffers.FirstOrDefault(o => o.ShaderIndex == x);
155-
if (cst == null) writer.Write(0);
156-
else writer.Write(cst.CstIndex);
155+
if (Entries[i].ConstantBuffers.Count <= x) writer.Write(0);
156+
else writer.Write(Entries[i].ConstantBuffers[x].Offset);
157157
}
158158
for (int x = 0; x < 5; x++)
159159
{
160-
Material.ConstantBuffer cst = Entries[i].ConstantBuffers.FirstOrDefault(o => o.ShaderIndex == x);
161-
if (cst == null) writer.Write((byte)0);
162-
else writer.Write((byte)cst.CstCount);
160+
if (Entries[i].ConstantBuffers.Count <= x) writer.Write(0);
161+
else writer.Write((byte)Entries[i].ConstantBuffers[x].Length);
163162
}
164163
writer.Write(new byte[7]);
165164
writer.Write(Entries[i].UnknownValue0);
@@ -209,7 +208,7 @@ public class Material
209208
public string Name;
210209

211210
public List<Texture> TextureReferences = new List<Texture>(); //Max of 12
212-
public List<ConstantBuffer> ConstantBuffers = new List<ConstantBuffer>(); //Max of 5
211+
public List<ConstantBuffer> ConstantBuffers = new List<ConstantBuffer>(); //Should always be 5 (1 per CST block) - TODO: maybe just change this to 5 variables?
213212

214213
public int UnknownValue0;
215214
public int UberShaderIndex;
@@ -225,11 +224,11 @@ public override string ToString()
225224
return "[" + Color + "] " + Name;
226225
}
227226

227+
//Offset and length within the CST file
228228
public class ConstantBuffer
229229
{
230-
public int ShaderIndex; // Entry index in the material texture ref write list for shaders to access.
231-
public int CstIndex; // Entry index in the CST data array, cross ref'd by shader tables.
232-
public int CstCount; // Entry count in the CST data array from index - should match shader data
230+
public int Offset = 0;
231+
public int Length = 0;
233232
}
234233

235234
public class Texture

0 commit comments

Comments
 (0)