Jorak Uln 458 Posted September 5, 2015 Hi, when you take a look at the CM(=cubemap) files at Kotor Tools ERFs, then you see that not every CM is the same size. Some are column like and the SKY ones are square(512x512). What i need specifically is to know how make a square cubemap. My idea is to take a panorama pic from Manaan and make a square CM out of it. But when i take a screenshot in .tga format Kotor 1 crashes. Any ideas? EDIT: Found it out per accident. Basically you can use any .tga. Example: If you want to use a custom cubemap CM_CustomCubemap.tga , the trick is just to drop CM_CustomCubemap.tga into Override, and not to assign a CM_CustomCubemap.txi . Then in your texture example.tga you just assign your .txi as usual adding the following line: envmaptexture CM_CustomCubemap That way it seems you can use any .tga as cubemap. Quote Share this post Link to post Share on other sites
DrMcCoy 40 Posted September 9, 2015 Just to clear it up a bit, you're using that square texture as a reflective environment map. But it's not a cubemap.A cubemap consists of 6 square sides that wrap around a cube. That can be used as a skybox, i.e. you're constructing a cube around your position and put the 6 textures on that sides, emulating the environment you're in.You can also use that as a reflective map. You're basically saying "this cube represents the environment as rendered from the perspective of the object", and then tell your graphics card to distort the texture according to the position and angle you view the object at. This fakes a reflective effect, and you can see an approximation of the object's surround reflected in the object.Likewise, you can use that texture as a refractive map. The idea is similar, only that you math on how to distort the texture is different.See this article for a more in-depth description how it works, the math behind it and how to do this in modern OpenGL (i.e. not quite how KotOR does it).You can also use a normal square texture to for this effect (like you did), but this is even more faked. Instead of having six sides that approximate the suroundings of your object, you'd then only have a generic "metal-y" texture with, say, some light spots. You won't, per se, see anything reflected on the object. If you do use a normal square texture with discernable things from the surroundings on it, you will see those things reflected even where the object faces away from those things. Keep that in mind. And yes, you shouldn't add a TXI with "cube 1" for those square textures. The game will expect a cube map with 6 sides. No idea how to use a TGA for real cubemaps, though. NWN used "cube 1" and "filerange 6" for a foo.txi, and then foo0.tga - foo5.tga. Possible that KotOR still supports that. For the TPC, they do actually contain 6 textures (each with their own set of mip maps), and the game detects that because height / width == 6 (and it divides height / 6, to get square sides).Interestingly, I've been experimenting with environment mapping in KotOR for xoreos in the last few days. KotOR combines this texture with such an environment map, and the blended combination then looks like this. That's the CM_BareMetal.tpc, and those don't contain any visible environment features, though, because CM_BareMetal.tpc is used all over the game. Reflective geometry in areas (like the streets of Taris) are different there, they use Taris-specific textures.And if you forget to turn off the viewpoint-distortion calculation for the default textures, you get this. Quote Share this post Link to post Share on other sites
Jorak Uln 458 Posted September 10, 2015 @DrMcCoy: Hey you seem to be an expert for the technical mechanics - you might seen it already but what i did basically is this: As you see, i used the envmap (or whatever it is) as background, to simulate the distant horizon. SInce its intended to be a computer screen generated image there are some technical animations implemented. However, a weak point id like to change. When you watch the background, the image is still distorted. Do you know how to get rid of that? (You might want to check out my Manaan textures ingame for that) Quote Share this post Link to post Share on other sites
LiliArch 115 Posted September 10, 2015 I don't know about the techy part, but the .txi with "cube 1" with the .tga with the same name seems to work fine in my game, at least. Just check how Darth_Sapiens did it. Quote Share this post Link to post Share on other sites
DrMcCoy 40 Posted September 10, 2015 When you watch the background, the image is still distorted. You mean the distortion based on the view position and angle? I don't think there's a way to get rid of that, because that's one of the reasons reflective environment maps exists at all. From what I've seen in the disassembly, all render paths enable that. It's done by calling glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP), and also for GL_T and GL_R. I.e. it auto-generates 3-dimensional texture coordinates according to a reflective model and based on the view angle. I don't know about the techy part, but the .txi with "cube 1" with the .tga with the same name seems to work fine in my game, at least. Just check how Darth_Sapiens did it. Oh, neat, so KotOR's TGA loader supports that by having the 6 sides one below the other. Very interesting. I assume the code depends on height / width == 6 there as well, and that would explain the crash Jorak Uln had when trying that with a square TGA. From what it looks like, the order is the same as with the TPC (which is slightly different from the order suggested by OpenGL tutorials, since KotOR's in-game coordinate system is rotated to fit a top-down viewpoint; a remnant from the NWN days). But are the TGA cube sides rotated as well? It's a bit difficult to see in those images. I've seen that the TPC loader rotates the sides in 90° steps (In order: 3, 1, 0, 2, 2, 0; each is the number of 90° steps clock-wise), and NWN seems to be similar with its cubemap files. Quote Share this post Link to post Share on other sites
LiliArch 115 Posted September 11, 2015 I assume the code depends on height / width == 6 there as well, and that would explain the crash Jorak Uln had when trying that with a square TGA.It does not. I have some perfectly square cubemaps working perfectly fine, without any crashes at all. Actually, I had to scale all of the cubemaps in the game to appear in my system (the dimensions must be powers of two to show up). My guess is the engine simply divides the height by 6. The ratio doesn't matter. Quote Share this post Link to post Share on other sites