private static void F3D_TEXTURE(ref TempMaterial temp, byte[] cmd) { ushort tsX = (ushort)bytesToInt(cmd, 4, 2); ushort tsY = (ushort)bytesToInt(cmd, 6, 2); if ((temp.geometryMode & 0x40000) == 0x40000) { temp.w = (ushort)(tsX >> 6); temp.h = (ushort)(tsY >> 6); } else { if (tsX != 0xFFFF) { temp.texScaleX = (float)tsX / 65536.0f; } else { temp.texScaleX = 1.0f; } if (tsY != 0xFFFF) { temp.texScaleY = (float)tsY / 65536.0f; } else { temp.texScaleY = 1.0f; } } }
private static bool G_SETCOMBINE(ref TempMaterial temp, byte[] cmd) { if (bytesToInt(cmd, 0, 4) == 0xFCFFFFFF) { temp.segOff = 0; return(true); } return(false); }
private static void G_SETTIMG(ref TempMaterial temp, byte[] cmd, ref string desc) { temp.segOff = bytesToInt(cmd, 4, 4); byte format = (byte)(cmd[1] & 0xF8); desc = "Set load format to " + TextureFormats.ConvertFormatToString((byte)(format >> 5), (byte)(format >> 3)) + " & address to 0x" + temp.segOff.ToString("X8"); temp.isPaletteRGBA16 = (format != 0x70); }
private static void F3D_MOVEMEM(ref TempMaterial temp, ref Level lvl, byte[] cmd) { if (cmd[1] == 0x86) { ROM rom = ROM.Instance; byte[] colData = rom.getDataFromSegmentAddress(bytesToInt(cmd, 4, 4), 4); temp.color = (bytesToInt(colData, 0, 3) | 0xFF000000); //rom.printArray(colData, 4); } }
private static void G_LOADTLUT(byte[] cmd, ref TempMaterial temp, ref string desc, byte?areaID) { byte paletteTileDescriptor = cmd[4]; ushort numColorsToLoadInPalette = (ushort)((bytesToInt(cmd, 5, 2) >> 6) + 1); desc = "Load " + numColorsToLoadInPalette + " colors into texture memory cache"; byte[] segmentData = ROM.Instance.getSegment((byte)(temp.segOff >> 24), areaID); uint offset = temp.segOff & 0x00FFFFFF; for (int i = 0; i < numColorsToLoadInPalette; i++) { temp.palette[i] = (ushort)((segmentData[offset + (i * 2)] << 8) | segmentData[offset + (i * 2) + 1]); } }
private static void F3D_MOVEMEM(ref TempMaterial temp, ref Level lvl, byte[] cmd, ref string desc, byte?areaID) { if (cmd[1] == 0x86) { ROM rom = ROM.Instance; byte[] colData = rom.getDataFromSegmentAddress(bytesToInt(cmd, 4, 4), 4, areaID); temp.color = (bytesToInt(colData, 0, 3) | 0xFF000000); desc = "Load light values for normal shading from address 0x" + bytesToInt(cmd, 4, 4).ToString("X8"); //rom.printArray(colData, 4); } else if (cmd[1] == 0x88) { desc = "Load dark values for normal shading from address 0x" + bytesToInt(cmd, 4, 4).ToString("X8"); } }
private static void switchTextureStatus(ref Model3D mdl, ref TempMaterial temp, bool status, byte?areaID) { ROM rom = ROM.Instance; if (mdl.builder.processingTexture != status) { if (status == false) { if (!mdl.builder.hasTexture(temp.segOff)) { if (temp.segOff != 0 && temp.w != 0 && temp.h != 0) { mdl.builder.AddTexture( TextureFormats.decodeTexture( temp.format, rom.getDataFromSegmentAddress_safe( temp.segOff, (uint)(temp.w * temp.h * 4), areaID ), temp.w, temp.h, temp.palette, temp.isPaletteRGBA16 ), mdl.builder.newTexInfo(temp.wrapS, temp.wrapT), temp.segOff ); } else { mdl.builder.AddTexture( TextureFormats.createColorTexture(System.Drawing.Color.FromArgb((int)temp.color)), mdl.builder.newTexInfo(temp.wrapS, temp.wrapT), temp.segOff ); } } } mdl.builder.processingTexture = status; } }
private static void switchTextureStatus(ref Model3D mdl, ref TempMaterial temp, bool status) { ROM rom = ROM.Instance; if (mdl.builder.processingTexture != status) { if (status == false) { if (!mdl.builder.hasTexture(temp.segOff)) { //System.Console.WriteLine("Adding new texture!"); if (temp.segOff != 0) { //System.Console.WriteLine("temp.segOff = " + temp.segOff.ToString("X8")); mdl.builder.AddTexture( TextureFormats.decodeTexture( temp.format, rom.getDataFromSegmentAddress( temp.segOff, (uint)(temp.w * temp.h * 2) ), temp.w, temp.h ), mdl.builder.newTexInfo(temp.wrapS, temp.wrapT), temp.segOff ); } else { mdl.builder.AddTexture( TextureFormats.createColorTexture(System.Drawing.Color.FromArgb((int)temp.color)), mdl.builder.newTexInfo(temp.wrapS, temp.wrapT), temp.segOff ); } } } mdl.builder.processingTexture = status; } }
private static void G_SETTILE(ref TempMaterial temp, byte[] cmd) { if (bytesToInt(cmd, 4, 4) == 0x07000000) { return; } if (cmd[4] == 0x00) // Make sure the tile is TX_RENDERTILE (0x0) and not TX_LOADTILE (0x7) { /* * The format for a texture should actually be used from SetTile (0xF5) command, * and not the SetTextureImage (0xFD) command. If you used the format from 0xFD, * then you will have issues with 4-bit textures. This is because the N64 4-bit * textures use 16-bit formats to load data. */ temp.format = cmd[1]; } temp.wrapT = getWrap((cmd[5] >> 2) & 0x2); temp.wrapS = getWrap(cmd[6] & 0x2); }
private static void G_SETTIMG(ref TempMaterial temp, byte[] cmd) { temp.segOff = bytesToInt(cmd, 4, 4); }
private static void G_SETTILESIZE(byte[] cmd, ref TempMaterial temp) { temp.w = (ushort)((((cmd[5] << 8) | (cmd[6] & 0xF0)) >> 6) + 1); temp.h = (ushort)((((cmd[6] & 0x0F) << 8 | cmd[7]) >> 2) + 1); }
private static void F3D_TRI1(F3D_Vertex[] vertices, ref Model3D mdl, ref Level lvl, ref TempMaterial temp, byte[] cmd) { mdl.builder.numTriangles++; F3D_Vertex a = vertices[cmd[5] / 0x0A]; Vector3 a_pos = new Vector3(a.x, a.y, a.z); Vector2 a_uv = new Vector2(a.u * temp.texScaleX, a.v * temp.texScaleY); Vector4 a_color = new Vector4(a.nx_r / 255.0f, a.ny_g / 255.0f, a.nz_b / 255.0f, 1.0f); F3D_Vertex b = vertices[cmd[6] / 0x0A]; Vector3 b_pos = new Vector3(b.x, b.y, b.z); Vector2 b_uv = new Vector2(b.u * temp.texScaleX, b.v * temp.texScaleY); Vector4 b_color = new Vector4(b.nx_r / 255.0f, b.ny_g / 255.0f, b.nz_b / 255.0f, 1.0f); F3D_Vertex c = vertices[cmd[7] / 0x0A]; Vector3 c_pos = new Vector3(c.x, c.y, c.z); Vector2 c_uv = new Vector2(c.u * temp.texScaleX, c.v * temp.texScaleY); Vector4 c_color = new Vector4(c.nx_r / 255.0f, c.ny_g / 255.0f, c.nz_b / 255.0f, 1.0f); //System.Console.WriteLine("Adding new Triangle: " + a_pos + "," + b_pos + "," + c_pos); if ((temp.geometryMode & 0x20000) != 0) { mdl.builder.AddTempVertex(a_pos, a_uv, getColor(temp.color)); mdl.builder.AddTempVertex(b_pos, b_uv, getColor(temp.color)); mdl.builder.AddTempVertex(c_pos, c_uv, getColor(temp.color)); } else { mdl.builder.AddTempVertex(a_pos, a_uv, a_color); mdl.builder.AddTempVertex(b_pos, b_uv, b_color); mdl.builder.AddTempVertex(c_pos, c_uv, c_color); } }
private static void G_SETTILESIZE(byte[] cmd, ref TempMaterial temp, ref string desc) { temp.w = (ushort)((((cmd[5] << 8) | (cmd[6] & 0xF0)) >> 6) + 1); temp.h = (ushort)((((cmd[6] & 0x0F) << 8 | cmd[7]) >> 2) + 1); desc = "Set texture size (width = " + temp.w + ", height = " + temp.h + ")"; }