A way to visualize mip levels

Recently a discussion on Twitter about folks using 2048 textures on a pair of dice spawned this post. How do artists know if the textures are too high or too low resolution? Here’s what we do in Unity, which may or may not work elsewhere.

When you have a game scene that, for example, looks like this:
 
We provide a “mipmaps” visualization mode that renders it like this:

Original texture colors mean it’s a perfect match (1:1 texels to pixels ratio); more red = too much texture detail; more blue = too little texture detail.

That’s it, end of story, move along!

Now of course it’s not that simple. You can just go and resize all textures that were used on the red stuff. The player might walk over to those red objects, and then they would need more detail!

Also, the amount of texture detail needed very much depends on the screen resolution the game will be running at:

Still, even with varying resolution sizes and the fact that the same objects in 3D can be near & far from the viewer, this view can answer the question of “does something have a too high/too low texture detail?”, mostly by looking at colorization mismatch between nearby objects.

In the picture above, the railings have too little texture detail (blue), while the lamp posts have too much (red). The little extruded things on the floating pads have too much detail as well.

The image below reveals that floor and ceiling have mismatching texture densities: floor has too little, while ceiling has too much. Probably should be the other way around, in a platform you’d more often be looking at the floor.

How to do this?

In the mipmap view shader, we display the original texture mixed with a special “colored mip levels” texture. The regular texture is sampled with original UVs, while the color coded texture is sampled with more dense ones, to allow visualization of “too little texture detail”. In shader code (HLSL, shader model 2.0 compatible):

struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float2 mipuv : TEXCOORD1; };float2 mainTextureSize; v2f vert (float4 vertex : POSITION, float2 uv : TEXCOORD0) { v2f o; o.pos = mul (matrix_mvp, vertex); o.uv = uv; o.mipuv = uv * mainTextureSize / 8.0; return o; } half4 frag (v2f i) : COLOR0 { half4 col = tex2D (mainTexture, i.uv); half4 mip = tex2D (mipColorsTexture, i.mipuv); half4 res; res.rgb = lerp (col.rgb, mip.rgb, mip.a); res.a = col.a; return res; }

The mainTextureSize above is the pixel size of the main texture, for example (256,256). Division by eight might seem a bit weird, but it really isn’t!

To show the colored mip levels, we need to create mipColorsTexture that has different colors in each mip level.

Let’s say we would create a 32×32 size texture for this, and the largest mip level would be used to display “ideal texel to pixel density”. If the original texture was 256 pixels in size and we want to sample a 32 pixels texture at exactly the same texel density as the original one, we have to use more dense UVs: newUV = uv * 256 / 32 or in a more generic way, newUV = uv * textureSize / mipTextureSize.

Why there’s 8.0 in the shader then, if we create the mip texture at 32×32 size? That’s because we don’t want the largest mip level to indicate “ideal texel to pixel” density. We also want a way to visualize “not enough texel density”. So we push the ideal mip level two levels down, which means it’s four times UV difference. That’s how 32 becomes 8 in the shader.

The actual colors we use for this 32×32 mipmaps visualization texture are, in RGBA: (0.0,0.0,1.0,0.8); (0.0,0.5,1.0,0.4); (1.0,1.0,1.0,0.0); (1.0,0.7,0.0,0.2); (1.0,0.3,0.0,0.6); (1.0,0.0,0.0,0.8). Alpha channel controls how much to interpolate between the original color and the tinted color. Our 3rd mip level has zero alpha so it displays unmodified color.

Now, step 2 is somehow forcing artists to actually use this ;)

A way to visualize mip levels相关推荐

  1. 【Unity URP】Rendering Debugger和可视化MipMap方案

    写在前面 最近开始学习Unity性能优化,是结合了<Unity游戏优化>这本书和教程<Unity性能优化>第叁节--静态资源优化(3)--纹理的基础概念一起学习.在学习纹理优化 ...

  2. UNREAL ENGINE 4.13 正式发布!

    这次的版本带来了数百个虚幻引擎 4 的更新,包括来自 GitHub 的社区成员们提交的 145 个改进!感谢所有为虚幻引擎 4 添砖加瓦贡献的人们: alk3ovation, Allegorithmi ...

  3. [Unity3D]总结使用Unity 3D优化游戏运行性能的经验

    作者:Amir Fasshihi 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow Blade>已经将在标准iPhone和iPad设备上实现每秒60帧视为一个重要目 ...

  4. D3DPOOL(资源池)

    D3DPOOL定义了资源对应的内存类型,资源可以是texture surface, vertex buffer等,从内存的角度来看,资源有以下几种类型. D3DPOOL_DEFAULT D3DPOOL ...

  5. OpenGL ES 3.0之Texturing纹理详解(二)

    Texture Filtering and Mipmapping 纹理过滤与多级纹理 前面我们已经讲了单个2D图像的2D纹理的介绍,这篇文章主要讲解多级纹理.纹理坐标是用于生成一个2D索引,当放大和缩 ...

  6. [译]Vulkan教程(32)生成mipmap

    [译]Vulkan教程(32)生成mipmap Generating Mipmaps 生成mipmap Introduction 入门 Our program can now load and ren ...

  7. Vulkan in 30 minutes

    Vulkan 1.0 的标准终于发布啦!文档在这里:https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/xhtml/vks ...

  8. learnopengl——Specular IBL——貌似读懂了

    https://learnopengl.com/#!PBR/IBL/Specular-IBL in the previous tutorial we've set up PBR in combinat ...

  9. 【翻译】Unity2017.2.0f3 版本发布说明

    文章目录 目录 操作系统改变 功能 **API Changes** 和 **Fixes** 不再列出,各位若有兴趣可以去官网看看~ 目录 本文翻译自官方文档2017.2.0f3 Release Not ...

最新文章

  1. ROW_NUMBER() OVER()函数用法;(分组,排序),partition by
  2. MySQL的IFNULL函数
  3. ※交换排序(1)——快速排序(quick sort)
  4. python中scale_Python中的Log-scale mathplotlib?
  5. 全国计算机二级哪几门比较热,【热】全国计算机二级office难吗
  6. # 57. 插入区间
  7. Java学习笔记2.5.1 循环结构 - 条件循环
  8. 魔术师利用一副牌中的13张红桃c语言,魔术师的猜牌术(1) 魔术师利用一副牌中的13张黑桃 - 下载 - 搜珍网...
  9. spin_lock浅析【转】
  10. 等保-机房日常巡检记录表
  11. 数据结构与算法之美-问题与思考收集
  12. 阿里云服务器怎么重装系统?
  13. 十万个为什么哪个版本适合小学生阅读
  14. Q1手机银行运营报告:交易规模超150万亿,月活跃用户4.9亿
  15. 无线网感叹号不能上网怎么办
  16. SECS-GEM通信标准的特点
  17. dd wrt linux内核,可以刷DD-WRT(linux核心)的无线路由器_网海拾贝
  18. Web server failed to start. Port 8082 was already in use.
  19. MediaCodec硬编码成H264视频流
  20. WinRAR x64 v5.5中文版去广告过程

热门文章

  1. Streaming API
  2. 找出出现次数最多的字母
  3. Java基础03 字符串连接符+
  4. php mkdir 无效,PHP mkdir()无写权限的问题解决方法
  5. 基于python的分类模型_python SVM 线性分类模型的实现
  6. 网络盘的计算机密码是什么情况,电脑e盘拒绝访问是什么原因?e盘加密方法
  7. 不使用输入框如何实现下拉_如何利用Axure实现下拉子菜单?
  8. 运行项目报错invalid notify_url
  9. 【BZOJ2154】Crash的数字表格,数论练习之二维LCM(莫比乌斯反演)
  10. 安卓手机 服务器 性能,鲁大师Q3安卓手机性能榜发布:华为Mate30 Pro第三 这款手机称王...