lewa-j / Unity-Source-Tools

Plugin to import resources from the Source engine in Unity3D.
GNU General Public License v2.0
109 stars 22 forks source link

Incorrect Rotation for Skybox Textures #26

Closed Fronkln closed 5 years ago

Fronkln commented 5 years ago

Just making an "issue" for this so this get's more attention, on my skybox loading code, due to how Source handles skybox textures, the up texture of skybox will have incorrect rotation and will not match with the rest of the skybox.

The solution is simple:

Rotate the Skybox Up Texture2D by 90 degrees clockwise

The issue: I do not know how to do this

So if any of you coders out there can do this it would greatly help loading Skyboxes from the game

antim0118 commented 5 years ago

Have you tried this ?

Fronkln commented 5 years ago

@antimYT It's giving not intended results

Default image

image

Rotate Matrix image

What we actually need to do so it works

image

Fronkln commented 5 years ago

IMPORTANT DISCOVERY!

All textures excluding UP has to be FLIPPED which can be done with Array.Reverse

antim0118 commented 5 years ago

It's giving not intended results

works for me. skyboxgh

i had to write my own code so here it is (im too lazy to pull request it)

if (uSrcSettings.Inst.skyBox)
{
    Material skybox = new Material(Shader.Find("Skybox/6 Sided"));

    string[] skysides = new string[] { "bk", "ft",  "rt", "lf", "up", "dn" };
    string[] skysides_u = new string[] { "_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex" };

    for (int side = 0; side < 6; side++) {
        var tex = ResourceManager.Inst.GetTexture($"skybox/{skyName}{skysides[side]}").ToTexture2D();
        ConvertUtils.FlipTextureVertically(tex);
        if (side >= 4)
            tex = tex.rotateTexture(false);
        tex.wrapMode = TextureWrapMode.Clamp;
        skybox.SetTexture(skysides_u[side], tex);
    }
    RenderSettings.skybox = skybox;
    DynamicGI.UpdateEnvironment();
}

And functions for ConvertUtils.cs: https://pastebin.com/WvR6DKsJ

Fronkln commented 5 years ago

Noted