• 基于顶点的地形纹理融合


    对于地形的纹理融合有很多方法,我使用的是一种利用顶点格式中添加纹理比重的方法实现的,有无需多次绘制地形和不需要地形纹理的Alph混合过程的两个优点,具体做法是在每个顶点中用4个浮点数分别表示4个纹理的比重,4个值的和为1.0f然后在像素着色过程根据比重融合相应的纹理,相关shader脚本部分如下

    struct VS_OUTPUT
    {
        ...
        float4 TextureTens      : TEXCOORD3;   // 各纹理的比重
    };

    VS_OUTPUT RenderSceneVS(..., float4 vTexCoord1 : TEXCOORD1 ) //纹理比重
    {
        VS_OUTPUT Out;
        ...
        Out.TextureTens = vTexCoord1;
    }

    struct PS_OUTPUT
    {
        float4 RGBColor : COLOR0;  // Pixel color   
    };

    PS_OUTPUT RenderScenePS( VS_OUTPUT In, ... uniform int  nTextureNum, ...) 
    {
        PS_OUTPUT Output;
        ...
        //纹理融合
        Output.RGBColor = tex2D(TerrinTextureSampler0, In.TextureUV0.xy)*In.TextureTens[0];
        if( nTextureNum >= 2 )
            Output.RGBColor += tex2D(TerrinTextureSampler1, In.TextureUV0.xy)*In.TextureTens[1];
        if( nTextureNum >= 3 )
            Output.RGBColor += tex2D(TerrinTextureSampler2, In.TextureUV0.xy)*In.TextureTens[2];
        if( nTextureNum >= 4 )
            Output.RGBColor += tex2D(TerrinTextureSampler3, In.TextureUV0.xy)*In.TextureTens[3];
        ...
        return Output;
    }

    实现的效果截图

  • 相关阅读:
    Grid search in the tidyverse
    Handling Class Imbalance with R and Caret
    R语言-Kindle特价书爬榜示例 & 输出HTML小技巧(转)
    Centos7下安装部署MXNET
    特征选择, 经典三刀(转)
    vue知识点14
    vue知识点13
    vue知识点12
    vue知识点11
    vue知识点10
  • 原文地址:https://www.cnblogs.com/crown20/p/2187810.html
Copyright © 2020-2023  润新知