Jump to content

Texture MipMaps


SpiderPig
 Share

Recommended Posts

I've started creating a large texture atlas for my terrain so that I can use more textures with less slots.  The problem is the default mip-map generation creates bleeding on lower mip levels, and from what it says here, I need to create each mip-map separately and then combine them.  Does anyone know of a way to manually set each mip-map level into a texture?

Can I perhaps make a .dds texture with the mip-maps I want and will the editor then convert it to .tex format using those mip-maps?

Link to comment
Share on other sites

The .tex files doesn't seem to retain the mipmaps in the .dds file.  I've attached the test files I used.  Also I used this code to extract the mipmap level then later draw it to the screen;

//On Load
Texture* t = Texture::Load("Terrain/Textures/beach_dirt_b.tex");
char* buffer = new char[t->GetMipmapSize(1) * 4];
t->GetPixels(buffer, 1);
Texture* tex = Texture::Create(t->GetWidth(1), t->GetHeight(1));
tex->SetPixels(buffer);

//On Run
context->DrawImage(tex, 100, 100);

Here is what the second mipmap should like;

testmipmap.png.88af99d339d7dc3787c49f8316677b5e.png

 

 

 

Using gimp to load and edit the dds file, I can see that it is defiantly saving the second mipmap with the edit I did.  It just not showing up in the conversion to tex.

Is it possible to add a command to the texture class; SetMipMap(Texture* texture, int level)?  Provided of course it has the right resolution for that level...

beach_dirt_b.tex

beach_dirt_b.tex.meta

beach_dirt_b.dds

Link to comment
Share on other sites

I wonder if its due to the default settings for the editor when converting an image to TEX that it automatically saves it as DXT1 and with the 'Generate Mipmaps' option selected? Is it overwriting your mipmaps because of this? These have always been settings i wish we had control over instead of them just being hard-written as the defaults.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Just a quick and dirty script to view the mipmaps saved inside a TEX file:

window = Window:Create("texture detail example",0,0,800,600,Window.Titlebar+Window.Center)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
tex = Texture:Load("Materials/beach_dirt_b.tex")
mips = tex:CountMipmaps()

while window:KeyDown(Key.Escape)==false do
	if window:Closed() then break end
	
	Time:Update()
	world:Update()
	world:Render()

	context:SetBlendMode(Blend.Alpha)
	for i = 0, mips-1 do 
		Texture:SetDetail(i+1)
		if i <= 4 then 
			context:DrawImage(tex,155*i,150,150,150)
		else
			context:DrawImage(tex,155*(i-5),305,150,150)
		end
	end
	context:DrawText("Number of Mipmaps: "..mips,2,2)
	context:SetBlendMode(Blend.Solid)
	context:Sync(true)
end

mipmaps.jpg.d89440573200821f1508d49c0db330d4.jpg

  • Like 1
  • Thanks 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Okay, so the way Leadwerks supports DDS is it just loads it with FreeImage and regenerates mipmaps.

Here is a little program you can use to convert a DDS into a TEX file and save the same mipmap data.

dds2tex.zip

Just drag the DDS file onto the EXE and it will convert it.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

hmmm. This still seems to be saving the same way as the Editor does where it overwrites the existing mipmaps. I am not seeing a difference when viewing with the above program. The second mipmap should look like this:

mipmaps2.jpg.65ad10d58f259e73fa5fa48dee80ef02.jpg

  • Like 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I tried the converter on my DDS that has only 5 mipmaps and got this when loading into the editor.  So I guess it's trying to calculate them still...?

Error: Texture mipmap count (5) does not match calculated mipmap count (10).
Error: Failed to load texture "G:/Leadwerks/Projects/TestingGrounds/Materials/beach_dirt_b.tex"

 

As a general rule are all mipmaps supposed to present?  Right down to the lowest size? (2x2 or 1x1)?

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

If the DDS only contains five mipmaps it will not work. Textures must be mipmap-complete. The way you calculate this is to keep dividing the width and the height until they both equal 1.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...