示例#1
0
文件: PSXGPU.cs 项目: ArtReeX/memoria
 private static void SetTexture(Int32 TP, Int32 TY, Int32 TX, Int32 clutY, Int32 clutX, FilterMode filter = FilterMode.Point)
 {
     if (TP != 2)
     {
         PSXGPU.constOffset.z  = 0.5f;
         PSXGPU.constTexSize.x = 256f;
         PSXGPU.constTexSize.y = 256f;
         PSXTexture texture = PSXTextureMgr.GetTexture(TP, TY, TX, clutY, clutX);
         texture.SetFilter(filter);
         if (texture.key != PSXGPU.texKey)
         {
             PSXGPU.curMaterial.mainTexture = texture.texture;
             PSXGPU.texKey        = texture.key;
             PSXGPU.isNeedSetPass = true;
         }
     }
     else
     {
         PSXGPU.constOffset.z  = (Single)((TX << 6) - PSXTextureMgr.GEN_TEXTURE_X) + 0.5f;
         PSXGPU.constTexSize.x = (Single)PSXTextureMgr.GEN_TEXTURE_W;
         PSXGPU.constTexSize.y = (Single)PSXTextureMgr.GEN_TEXTURE_H;
         if (PSXGPU.texKey != 4294967295u)
         {
             PSXGPU.curMaterial.mainTexture = PSXTextureMgr.genTexture;
             PSXGPU.texKey        = UInt32.MaxValue;
             PSXGPU.isNeedSetPass = true;
         }
     }
 }
示例#2
0
    private void _GenerateSPSMesh()
    {
        if (this.spsPrims.Count == 0)
        {
            return;
        }
        Single    num      = (Single)this.scale / 4096f;
        Matrix4x4 matrix4x = Matrix4x4.TRS(this.pos, Quaternion.Euler(this.rot.x, this.rot.y, this.rot.z), new Vector3(-num, -num, num));

        base.transform.position = this.pos;
        Single d = 0.00390625f;

        this._vertices.Clear();
        this._colors.Clear();
        this._uv.Clear();
        this._indices.Clear();
        for (Int32 i = 0; i < this.spsPrims.Count; i++)
        {
            WorldSPS.WorldSPSPrim worldSPSPrim = this.spsPrims[i];
            Vector3 b     = new Vector3(0f, 0f, (Single)(this.spsPrims.Count - i) / 100f);
            Int32   count = this._vertices.Count;
            this._vertices.Add(worldSPSPrim.v0 + b);
            this._vertices.Add(worldSPSPrim.v1 + b);
            this._vertices.Add(worldSPSPrim.v2 + b);
            this._vertices.Add(worldSPSPrim.v3 + b);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._uv.Add(worldSPSPrim.uv0 * d);
            this._uv.Add(worldSPSPrim.uv1 * d);
            this._uv.Add(worldSPSPrim.uv2 * d);
            this._uv.Add(worldSPSPrim.uv3 * d);
            this._indices.Add(count);
            this._indices.Add(count + 1);
            this._indices.Add(count + 2);
            this._indices.Add(count + 1);
            this._indices.Add(count + 3);
            this._indices.Add(count + 2);
        }
        Mesh mesh = this.meshFilter.mesh;

        mesh.Clear();
        mesh.vertices        = this._vertices.ToArray();
        mesh.colors          = this._colors.ToArray();
        mesh.uv              = this._uv.ToArray();
        mesh.triangles       = this._indices.ToArray();
        this.meshFilter.mesh = mesh;
        WorldSPS.WorldSPSPrim worldSPSPrim2 = this.spsPrims[0];
        PSXTexture            texture       = PSXTextureMgr.GetTexture(worldSPSPrim2.FlagTP, worldSPSPrim2.FlagTY, worldSPSPrim2.FlagTX, worldSPSPrim2.FlagClutY, worldSPSPrim2.FlagClutX);

        if (texture.texture.filterMode != FilterMode.Bilinear)
        {
            texture.SetFilter(FilterMode.Bilinear);
        }
        Int32 num2 = (Int32)((this.arate >= 4) ? 4 : this.arate);

        this.materials[num2].mainTexture = texture.texture;
        this.meshRenderer.material       = this.materials[num2];
    }
示例#3
0
    private void _GenerateSPSMesh()
    {
        if (this.spsPrims.Count == 0)
        {
            return;
        }
        Boolean   flag            = false;
        BGCAM_DEF currentBgCamera = this.fieldMap.GetCurrentBgCamera();

        if (currentBgCamera == null)
        {
            return;
        }
        Single    num      = (Single)this.scale / 4096f;
        Matrix4x4 localRTS = Matrix4x4.identity;
        Boolean   flag2    = false;

        if (FF9StateSystem.Common.FF9.fldMapNo == 2929)
        {
            flag = true;
        }
        if (flag)
        {
            if (FF9StateSystem.Common.FF9.fldMapNo == 2929)
            {
                localRTS = Matrix4x4.TRS(this.pos * 0.9925f, Quaternion.Euler(-this.rot.x / 2f, -this.rot.y / 2f, this.rot.z / 2f), new Vector3(num, -num, 1f));
            }
            else
            {
                localRTS = Matrix4x4.TRS(this.pos, Quaternion.Euler(this.rot.x, this.rot.y, this.rot.z), new Vector3(num, -num, 1f));
            }
        }
        else
        {
            Vector3 vector = PSX.CalculateGTE_RTPT_POS(this.pos, Matrix4x4.identity, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset(), true);
            num *= currentBgCamera.GetViewDistance() / vector.z;
            if (vector.z < 0f)
            {
                flag2 = true;
            }
            vector.z /= 4f;
            vector.z += (Single)currentBgCamera.depthOffset;
            base.transform.localPosition = new Vector3(vector.x, vector.y, vector.z + (Single)this.zOffset);
            base.transform.localScale    = new Vector3(num, -num, 1f);
            base.transform.localRotation = Quaternion.Euler(this.rot.x, this.rot.y, -this.rot.z);
        }
        this._vertices.Clear();
        this._colors.Clear();
        this._uv.Clear();
        this._indices.Clear();
        for (Int32 i = 0; i < this.spsPrims.Count; i++)
        {
            if (flag2)
            {
                break;
            }
            FieldSPS.FieldSPSPrim fieldSPSPrim = this.spsPrims[i];
            Int32 count = this._vertices.Count;
            if (flag)
            {
                Vector3 a    = PSX.CalculateGTE_RTPT(fieldSPSPrim.v0, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset());
                Vector3 a2   = PSX.CalculateGTE_RTPT(fieldSPSPrim.v1, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset());
                Vector3 a3   = PSX.CalculateGTE_RTPT(fieldSPSPrim.v2, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset());
                Vector3 a4   = PSX.CalculateGTE_RTPT(fieldSPSPrim.v3, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset());
                Single  num2 = PSX.CalculateGTE_RTPTZ(Vector3.zero, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset());
                num2 /= 4f;
                num2 += (Single)currentBgCamera.depthOffset;
                Vector3 b = new Vector3(0f, 0f, num2 - (Single)i / 100f);
                this._vertices.Add(a + b);
                this._vertices.Add(a2 + b);
                this._vertices.Add(a3 + b);
                this._vertices.Add(a4 + b);
            }
            else
            {
                Vector3 b2 = new Vector3(0f, 0f, (Single)(this.spsPrims.Count - i) / 100f);
                this._vertices.Add(fieldSPSPrim.v0 + b2);
                this._vertices.Add(fieldSPSPrim.v1 + b2);
                this._vertices.Add(fieldSPSPrim.v2 + b2);
                this._vertices.Add(fieldSPSPrim.v3 + b2);
            }
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._uv.Add((fieldSPSPrim.uv0 + new Vector2(0.5f, 0.5f)) * 0.00390625f);
            this._uv.Add((fieldSPSPrim.uv1 + new Vector2(-0.5f, 0.5f)) * 0.00390625f);
            this._uv.Add((fieldSPSPrim.uv2 + new Vector2(0.5f, -0.5f)) * 0.00390625f);
            this._uv.Add((fieldSPSPrim.uv3 + new Vector2(-0.5f, -0.5f)) * 0.00390625f);
            this._indices.Add(count);
            this._indices.Add(count + 1);
            this._indices.Add(count + 2);
            this._indices.Add(count + 1);
            this._indices.Add(count + 3);
            this._indices.Add(count + 2);
        }
        Mesh mesh = this.meshFilter.mesh;

        mesh.Clear();
        mesh.vertices        = this._vertices.ToArray();
        mesh.colors          = this._colors.ToArray();
        mesh.uv              = this._uv.ToArray();
        mesh.triangles       = this._indices.ToArray();
        this.meshFilter.mesh = mesh;
        FieldSPS.FieldSPSPrim fieldSPSPrim2 = this.spsPrims[0];
        PSXTexture            texture       = PSXTextureMgr.GetTexture(fieldSPSPrim2.FlagTP, fieldSPSPrim2.FlagTY, fieldSPSPrim2.FlagTX, fieldSPSPrim2.FlagClutY, fieldSPSPrim2.FlagClutX);

        texture.SetFilter(FilterMode.Bilinear);
        Int32 num3 = (Int32)((this.arate >= 4) ? 4 : this.arate);

        this.materials[num3].mainTexture = texture.texture;
        this.meshRenderer.material       = this.materials[num3];
        if (this.spsActor != (UnityEngine.Object)null)
        {
            this.spsActor.spsPos = this.pos;
        }
    }
示例#4
0
    private void _GenerateSPSMesh()
    {
        if (this.spsPrims.Count == 0)
        {
            return;
        }
        Single num = (Single)this.scale / 4096f;

        base.transform.localScale    = new Vector3(-num, -num, num);
        base.transform.localRotation = Quaternion.Euler(this.rot.x, this.rot.y, this.rot.z);
        base.transform.localPosition = this.pos;
        Camera  camera = Camera.main ? Camera.main : GameObject.Find("Battle Camera").GetComponent <BattleMapCameraController>().GetComponent <Camera>();
        Vector3 a      = camera.worldToCameraMatrix.inverse.GetColumn(3);
        Single  num2   = Vector3.Distance(a, this.pos);
        Single  num3   = num2 * this.spsScale * BattleSPS.spsK;

        if (num3 > 3f)
        {
            num3 = 3f;
        }
        base.transform.localScale *= num3;
        Matrix4x4 inverse = camera.worldToCameraMatrix.inverse;
        Vector3   vector  = inverse.MultiplyVector(Vector3.forward);
        Vector3   rhs     = inverse.MultiplyVector(Vector3.right);
        Vector3   a2      = Vector3.Cross(vector, rhs);

        base.transform.LookAt(base.transform.position + vector, -a2);
        Single d = 0.00390625f;

        this._vertices.Clear();
        this._colors.Clear();
        this._uv.Clear();
        this._indices.Clear();
        for (Int32 i = 0; i < this.spsPrims.Count; i++)
        {
            BattleSPS.FieldSPSPrim fieldSPSPrim = this.spsPrims[i];
            Vector3 b     = new Vector3(0f, 0f, (Single)(this.spsPrims.Count - i) / 100f);
            Int32   count = this._vertices.Count;
            Vector3 v     = fieldSPSPrim.v0;
            Vector3 v2    = fieldSPSPrim.v1;
            Vector3 v3    = fieldSPSPrim.v2;
            Vector3 v4    = fieldSPSPrim.v3;
            this._vertices.Add(v + b);
            this._vertices.Add(v2 + b);
            this._vertices.Add(v3 + b);
            this._vertices.Add(v4 + b);
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._colors.Add(fieldSPSPrim.color);
            this._uv.Add(fieldSPSPrim.uv0 * d);
            this._uv.Add(fieldSPSPrim.uv1 * d);
            this._uv.Add(fieldSPSPrim.uv2 * d);
            this._uv.Add(fieldSPSPrim.uv3 * d);
            this._indices.Add(count);
            this._indices.Add(count + 1);
            this._indices.Add(count + 2);
            this._indices.Add(count + 1);
            this._indices.Add(count + 3);
            this._indices.Add(count + 2);
        }
        Mesh mesh = this.meshFilter.mesh;

        mesh.Clear();
        mesh.vertices        = this._vertices.ToArray();
        mesh.colors          = this._colors.ToArray();
        mesh.uv              = this._uv.ToArray();
        mesh.triangles       = this._indices.ToArray();
        this.meshFilter.mesh = mesh;
        BattleSPS.FieldSPSPrim fieldSPSPrim2 = this.spsPrims[0];
        PSXTexture             texture       = PSXTextureMgr.GetTexture(fieldSPSPrim2.FlagTP, fieldSPSPrim2.FlagTY, fieldSPSPrim2.FlagTX, fieldSPSPrim2.FlagClutY, fieldSPSPrim2.FlagClutX);

        texture.SetFilter(FilterMode.Bilinear);
        Int32 num4 = (Int32)((this.arate >= 4) ? 4 : this.arate);

        this.materials[num4].mainTexture = BattleSPSSystem.statusTextures[this.refNo].textures[0];
        this.meshRenderer.material       = this.materials[num4];
        if (this.spsActor != (UnityEngine.Object)null)
        {
            this.spsActor.spsPos = this.pos;
        }
    }