Tekkaman

导航

 

如何显示当前Mipmap级别?

  乘以 mainTextureSize/mipTextureSize是为了让mipColorsTexture纹理与mainTexture级别对应。直接用uv是不行的,因为如果这样,那么直到纹理小于32x32,才会使得mipCOlorsTexture与mainTexture匹配上。

truct 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 / mipTextureSize;
    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;    
}

参考:http://aras-p.info/blog/2011/05/03/a-way-to-visualize-mip-levels/

 

posted on 2014-10-20 18:24  Tekkaman  阅读(3147)  评论(0编辑  收藏  举报