常见特效:Cloaking, Frozen, Burn

基本贴图:TextureCube m_EnvCubeMap;

14.jpg

隐形:

额外参数:背景贴图 m_backgroundTexture;

实现基本原理:   

// invisible pervasion
    vec4 fragColor = reflectColor;
    fragColor += vec4(g_Time / 10.0);
    fragColor = min(fragColor,1.0);
    float damn = pow(fragColor.r, 50.0) * (1.0 - fragColor.r) * 120.0;
    vec4 edgeColor = abs(vec4(normalNorm.r * 0.2,normalNorm.r * 0.4 + normalNorm.g,normalNorm.r * 0.4 + normalNorm.b,0)) * damn;

    vec4 originColor = texture2D(m_originTexture, texCoord)*0.1 *(1.0-edgeColor) + edgeColor;
....

    // color of invisible part
    vec2 newUVr = (gl_FragCoord.xy / vec2(1280.0, 720.0)) - normalNorm.xy * 0.05;
    vec2 newUVg = (gl_FragCoord.xy / vec2(1280.0, 720.0)) - normalNorm.xy * 0.045;
    vec2 newUVb = (gl_FragCoord.xy / vec2(1280.0, 720.0)) - normalNorm.xy * 0.038;
    float cloakColorR = texture2D(m_backgroundTexture, newUVr).r;
    float cloakColorG = texture2D(m_backgroundTexture, newUVg).g;
    float cloakColorB = texture2D(m_backgroundTexture, newUVb).b;
   // Fresnel折射系数,cdiff和anis是光照衍射diffraction部分(详见:GPU Gems chapter8)
    vec4 cloakColor = vec4(cloakColorR, cloakColorG, cloakColorB, 1.0) * 0.75 + Fresnel * 0.4 * (cdiff + anis * 1.5) ;


    gl_FragColor = step(1.0, fragColor.r) ? cloakColor : originColor;

 

 

冰冻:

额外参数:m_BiasNormalTexture(额外法线贴图,增加颗粒感);m_SparkleTexture(雪覆盖纹理)

N002.pngH002.PNG

实现基本原理:

   

vec4 reflectColor = textureCube(m_FrozenCubeMap, utilNormal);
    vec4 threshold = reflectColor - vec4(1.0);
    threshold += 1.3;//vec4(mod(g_Time, 13.0) / 10.0);
    threshold = max(min(threshold+ 0.3, 1.0),0.0);
    //    threshold = threshold + vec4(1.5);
    threshold = pow(threshold , 2.0);

    // utilNormal 和 utilPos分别位于模型空间
    vec4 fragColor;
    fragColor = pow(utilNormal.x, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.y*0.5,1.0))) * 2.0 - 1.0)
            + pow(utilNormal.y, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.x*0.5,1.0))) * 2.0 - 1.0)
            + pow(utilNormal.z, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.x*0.5,1.0),mod(utilPos.y*0.5,1.0))) * 2.0 - 1.0)   ;
    fragColor = normalize(fragColor);
    vec3 combineNormal = normalize(fragColor.xyz + wNormal);


    float sparkle = pow(abs(utilNormal.x), 2.0) * texture2D(m_SparkleTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.y*0.5,1.0)))
            + pow(abs(utilNormal.y), 2.0) * texture2D(m_SparkleTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.x*0.5,1.0)))
            + pow(abs(utilNormal.z), 2.0) * texture2D(m_SparkleTexture, vec2(mod(utilPos.x*0.5,1.0),mod(utilPos.y*0.5,1.0)))    ;

    float spec = pow(max(dot(normalize(worldViewDirN + worldLightDir),combineNormal), 0.0), 10.0) * 0.5;
    vec4 diff = max(dot(worldLightDir,combineNormal),0.0);
    diff = vec4((diff.r + 0.2)/(1.2),(diff.r + 0.35)/(1.35),(diff.r + 0.65)/(1.65),1.0);

    vec4 originColor = texture2D(m_originTexture, texCoord);
    gl_FragColor = originColor * (1-threshold) + (vec4(0.4) + diff * 0.5 + spec * vec4(sparkle)) * threshold;

 

 

燃烧:

m_BiasNormalTexture

H003.png

实现基本原理:

vec4 burntColor = vec4(70.0 / 255.0, 54.0 / 255.0, 25.0 / 255.0, 1.0);   // 焦黄色
    vec4 ashColor1 = vec4(20.0 / 255.0, 9.0 / 255.0, 4.0 / 255.0, 1.0);      // 接近纯黑
    vec4 ashColor2 = vec4(59.0 / 255.0, 63.0 / 255.0, 67.0 / 255.0, 1.0);    // 燃烧完后的灰色
       vec4 reflectColor = textureCube(m_FrozenCubeMap, utilNormal);
    float threshold = reflectColor.r * 1.2;
    threshold += vec4(mod(g_Time, 12.0) / 15.0);
   // utilPos为模型空间坐标
    float fragColor;
    fragColor = pow(utilNormal.x, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.y*0.5,1.0))).x)
            + pow(utilNormal.y, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.z*0.5,1.0),mod(utilPos.x*0.5,1.0))).x)
            + pow(utilNormal.z, 2.0) * (texture2D(m_BiasNormalTexture, vec2(mod(utilPos.x*0.5,1.0),mod(utilPos.y*0.5,1.0))).x);


    vec4 texColor = texture2D(m_originTexture, texCoord);
    float ambientFactor = 0.2;
    float diffFactor = max(dot(worldLightDirN, wNormal), 0.0);
    vec3 R = reflect(worldLightDirN, wNormal);
    float specuFactor =  pow(max(dot(R, worldViewDirN), 0.0), 5);

    vec4 originColor = texColor * (ambientFactor + diffFactor * 0.5 + 0.3 * specuFactor);

    threshold = clamp(threshold - 0.5, 0.0, 1.0);
   // 大致功能是让燃烧后的三层区别开来,并决定大小
    float alphab = sin( threshold * 1.570796);
    float alphaa = clamp(4 * threshold - 2.4, 0.0, 1.0) * fragColor ;
    float alphad = clamp(5 * threshold - 4.5, 0.0, 1.0) * pow(fragColor, 3.0) ;


    gl_FragColor = originColor * (1-alphaa) * (1-alphab) * (1-alphad) + (ambientFactor + diffFactor * 0.5) * (burntColor * (1-alphaa) * alphab*                   (1-alphad) + ashColor1 * alphaa* (1-alphad) + ashColor2 * alphad);

 

 

雨天(NVIDIA DX10 sdk Rain例子):

基本实现方法为利用例子系统产生全屏雨滴(8中类型,8张贴图),地面采用bumpMap(加入地面法线计算)和diffuseMap(附加地面颜色)(都为Texture2DArray),随时间选择不同贴图。

转载于:https://www.cnblogs.com/ActionFG/archive/2012/09/09/2677804.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值