首页 业界咨询 专题中心 数字创意 技术设备 教育培训 招聘求职 博客 联盟论坛 作品展示 技术教程 书刊杂志 高级搜索
首页 >> 技术教程 >> 理论教程 >> CG创造HALF TONE效果

CG创造HALF TONE效果

 作者:未知  来源:  发布日期:2007-07-24 11:26:46 

//Vertex input data
struct vertexInput {
 float4 position      : POSITION;
 float3 normal        : NORMAL;
 float4 texCoordDiffuse    : TEXCOORD0;
};

//Vertex output data
struct vertexOutput {
 float4 hPosition    : POSITION;
 float4 objPos      : TEXCOORD0; //Object-space position
 float4 texCoordDiffuse  : TEXCOORD1;
 float3 normal      : TEXCOORD2;
};

//Vertex Program
vertexOutput main_vp(vertexInput IN, uniform float4x4 worldViewProj)
{
 vertexOutput OUT;
 OUT.hPosition = mul(worldViewProj, IN.position);
 OUT.objPos= IN.position;         //Keep the object-space data
 OUT.texCoordDiffuse = IN.texCoordDiffuse;
 OUT.normal = IN.normal;          //To be interpolated

 return OUT;
}

//Fragment program
float4 main_fp( vertexOutput IN,
     //parameters
     uniform float timeBlend,
     uniform float4 uvFactor,      //To adjust the haltone texture
     uniform float4 lightAmbient,    //Ambient light for the halftone only!
     uniform float3 lightPosition,
     uniform sampler2D diffuseTex,
     uniform sampler2D halftone): COLOR
{
  //Lighting
  float3 P = IN.objPos.xyz;
  float3 N = normalize(IN.normal);
 
  float3 L = normalize(lightPosition - P);
  float diffuseLight = max(dot(N, L), 0);
  float4 diffuse = diffuseLight * tex2D(diffuseTex, IN.texCoordDiffuse.xy);
  //End of lighting

  float3 intensityConverter = {0.299, 0.587, 0.114};
  float Y = dot(intensityConverter, diffuse.xyz + lightAmbient.xyz); //Intensity from YIQ color format
 
  float H = tex2D(halftone, fmod(IN.texCoordDiffuse.xy*uvFactor.xy, 1.0)).x; //Get the halftone intensity

  float4 halfToneCol= (H > 1-Y ) ? float4(1, 1, 1, 1) : float4(0, 0, 0, 1); //Threshold function
 
  return float4(lerp(halfToneCol.rgb, diffuse.rgb, timeBlend), 1.0); //Interpolation between halftoned and phong shading.
}

uploads/200506/13_153452_sf_200568231453.jpg



本文引用地址:http://www.cgchina.com/article/2007/0724/article_10965.html


责任编辑:哈库纳马塔塔


加入收藏】 【告诉好友】 【打印本页】 【关闭窗口】 【返回顶部
 
© 2005-2006 | CGchina -All rights reserved Powerby phpcms
CG中国版权所有,此站点的任何信息包括图象、视频、音频等,未经许可,严禁传载。
www.cgchina.com | 关于我们 | 版权声明 | 广告服务 | 联系我们 | 诚聘英才 | 友情链接 | 网站公告