美术那边需要一个能在3dmax里用的支持diffuse纹理和顶点色的additive shader(不带光照)。

以前没搞过这个,于是从3dmax自带的vertexcolor.fx,DiffuseBump.fx拼凑出了一个,如下:

//-----------------------------DiffuseMapVertexcolorAdditive.fx

// 3ds max effect file
// Simple vertex color - work with the Vertex Paint tool.  The max effect parser
// allows you to define any arbitary map channel to be passed in via a texcoord.
// In this case we are interested in Vertex Color, Illumination and Alpha which
// are stored in 0,-1,-2 respectively.

// light direction (view space)

// transformations
float4x4 World      :         WORLD;
float4x4 View       :         VIEW;
float4x4 Projection :         PROJECTION;
float4x4 WorldViewProj :     WORLDVIEWPROJ;
float4x4 WorldView :         WORLDVIEW;

texture diffuseTexture : DiffuseMap<
    string name = "seafloor.dds";
    string UIName = "Diffuse Texture";
    int Texcoord = 0;
    int MapChannel = 1;
    >;

int texcoord1 : Texcoord
<
    int Texcoord = 1;
    int MapChannel = 0;
>;
int texcoord2 : Texcoord
<
    int Texcoord = 2;
    int MapChannel = -2;
>;

struct AppData
{
    float3 Pos  : POSITION;
    float2 TexCoord : TEXCOORD0;
    float3 col    : TEXCOORD1;
    float3 alpha :TEXCOORD2;
 
};

struct v2f
{
    float4 Pos  : POSITION;
    float4 color : COLOR;
    float2 TexCoord0 : TEXCOORD0;

};

struct f2fb {
    float4 col : COLOR;
};

v2f VS(
    AppData IN
 
)
{
    v2f Out = (v2f)0;
   
    Out.Pos  = mul(float4(IN.Pos,1),WorldViewProj);    // position (projected)
    
    float4 diff;
    diff = float4(IN.col,1);

Out.color = diff;
        
    Out.color.a = IN.alpha.x;

Out.TexCoord0.xy = IN.TexCoord.xy;

return Out;
    
}
f2fb PS(v2f IN,
        uniform sampler2D DiffuseMap)
{
    f2fb OUT;

//fetch base color
    float4 color = tex2D(DiffuseMap,IN.TexCoord0 );

//fetch vertex color
    float4 vertexColor=IN.color;

OUT.col = color *vertexColor;

return OUT;
}

sampler2D diffuseSampler = sampler_state
{
    Texture = <diffuseTexture>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    ADDRESSU = WRAP;
    ADDRESSV = WRAP;
};

technique tech
{
    pass P0
    {
        ZEnable = true;
    ZWriteEnable = false;
        AlphaBlendEnable = TRUE;
        SrcBlend         = SRCALPHA;
        DestBlend        = ONE;//InvSrcAlpha;  
        CullMode = None;
        ShadeMode = Gouraud;  
        // shaders
        
        VertexShader = compile vs_2_0 VS();
    PixelShader = compile ps_2_0 PS(diffuseSampler);
    }  
}

technique tech_cullModeCW
{
    pass P0
    {
        ZEnable = true;
    ZWriteEnable = false;
        AlphaBlendEnable = TRUE;
        SrcBlend         = SRCALPHA;
        DestBlend        = ONE;//InvSrcAlpha;  
        CullMode = CW;
        ShadeMode = Gouraud;  
        // shaders
        
        VertexShader = compile vs_2_0 VS();
    PixelShader = compile ps_2_0 PS(diffuseSampler);
    }  
}

----

补充:

1,内置的dx shader vertexcolor.fx在3dmax2012中会报错,在3dmax2010中vertexcolor.fx中是可用的。

2,仿照vertexcolor.fx,顶点色col用mapchannel 0,顶点透明度alpha用mapchannel -2。那个diffuse纹理,用一个跟它们不冲突的通道即可,我这里用的是mapchannel 1。

补充2:

3dmax里似乎没有办法控制渲染顺序,所以在复杂场景中,使用了blend的物体,显示结果并不一定符合预期。

3dmax fx shader, vertex color的更多相关文章

  1. Vertex color blending & UV tiling

    [Vertex color blending & UV tiling] 1.GemotryData控件用于代码顶点数据,如网格中的Vertex Color(下左图),UV Coord(下右图) ...

  2. Shader编程教程

    2010-05-13 11:37:14|  分类: DirectX 3D学习|举报|字号 订阅     Shader编程教程1-环境光照 您好,欢迎来到XNA Shader教程1.我的名字叫Petri ...

  3. DirectX11笔记(八)--Direct3D渲染4--VERTEX SHADER

    原文:DirectX11笔记(八)--Direct3D渲染4--VERTEX SHADER 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u0103 ...

  4. Unity3d 着色器语法(Shader)

    Shader "name" { [Properties] Subshaders [Fallback] } 定义了一个着色器.着色器拥有一个 Properties 的列表.着色器包含 ...

  5. Unity3D shader简介

    Unity3D shader简介 可以肯定的说Unity3D使得很多开发者开发游戏更容易.毫无疑问,shader(着色器)编码,仍有很长的路要走.shader是一个专门运行在GPU的程序,经常被神秘包 ...

  6. Shader 之 顶点变形

    可以使3D物体通过顶点变形弯曲,常见于跑酷游戏的跑道.可向左.右.上.下弯曲. Shader "Custom/VertexColorCurved" { Properties { / ...

  7. Surface Shader

    Surface Shader: (1)必须放在SubShdader块,不能放在Pass内部: (2)#pragma sufrace surfaceFunction lightModel [option ...

  8. UnityShader之固定管线命令Combine纹理混合【Shader资料4】

    Combine,纹理混合. 我们先看圣典上给的解释. 纹理在基本的顶点光照被计算后被应用.在着色器中通过SetTexture 命令来完成. SetTexture 命令在片面程序被使用时不会生效:这种模 ...

  9. Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )

    Pass Tags 通过使用tags来告诉渲染引擎在什么时候该如何渲染他们所期望的效果. Syntax 语法 Tags { "TagName1" = "Value1&qu ...

随机推荐

  1. OpenShift DNS的机制

    为什么不直接用kube-dns? 为什么不直接用kube-dns? 为什么不直接用kube-dns? 感谢各位前辈的专研,在下午有限的时间里把Openshift DNS的机制理了一下.更详细的材料大家 ...

  2. Spring核心之IoC——依赖注入

    在J2EE开发平台中,Spring是一种优秀的轻量级企业应用解决方案.Spring倡导一切从实际出发,它的核心技术就是IOC(控制反转)和AOP(面向切面编程)技术.本文用的Spring版本为spri ...

  3. 数学图形(2.15)Spherical sinusoid球面正弦曲线

    这个曲线与之前的数学图形(2.7)sphere sine wave很相似.而且个人觉得从其公式上看sphere sine wave更应该叫做球面正弦曲线.当然从渲染的曲线图上看,它是非常明显的贴在球上 ...

  4. SQL INNER JOIN

    A INNER JOIN command is queries that combine data from more than 1 table.For two tables that want to ...

  5. RHEL7.0 配置网络IP的三种方法

    导读 RHEL7里面的网卡命名方式从eth0,1,2的方式变成了enoXXXXX的格式. en代表的是enthernet (以太网),o 代表的是onboard (内置),那一串数字是主板的某种索引编 ...

  6. android.content.res.Resources$NotFoundException: String resource ID #0x0

    仔细检查是不是在settext的时候设置进去的时int属性的值,所以android会认为这是在strings中的值,所以会拿着这个int值当做string的id值去找,结果当然是找不到的.

  7. 初识 NoSQL Databases RethinkDB

    初识 NoSQL Databases RethinkDB rethinkDB所有数据都是基于 json的Document; 官网:http://rethinkdb.com/ github: https ...

  8. 在Ubuntu 12 服务器上源码安装 OpenERP 8.0

    原文:http://vivianyw.blog.163.com/blog/static/134547422201421112349489/ 1. 安装SSH: sudo apt-get install ...

  9. WPF显示经常使用的几个显示文字控件TextBox, TextBlock, Lable

    TextBox, TextBlock. Lable 当中TextBox 和Lable均继承了Control类 能够对其进行模板编辑. 而TextBlock没有继承Control所以不能对其进行模板编辑 ...

  10. jquery获取含有某元素的的控件 “控件名[属性名=值]”

    jquery获取含有某元素的的控件 “控件名[属性名=值]”. 如,获取 <input id="${cheackbox}" data-role="icheck&qu ...