ParallaxMap

实际案例:bullet holes

 

基本原理就是偏移当前像素UV,形成高度差。

基本公式:UV + ViewDir.xy *( depth * scale + bias) / viewDir.z;

(ViewDir是贴图空间, depth为深度图中储存值,scale看实际的最大深度,比如(贴图覆盖2*2M的范围,并且最大高度差为0.02M,则scale为0.02/2 = 0.01), bias不固定,得看实际情况,一般情况下,-0.01会看起来下陷一些,而+0.01就抬高一些。)

reliefMap是指NormalMap中w值为depth。

steepMap技术是指更细微的搜索实际深度。(其中currPoint即为上公式所求值,currHeight为1.0, tStep为currPoint / 25, hStep = 1 / 25, iStep = 25)

float TraceLinear(sampler2D m_HeightMap, inout vec2 CurrPoint, inout float CurrHeight, vec2 tStep, float hStep, float mipLevel, float iSteps, inout float Intersected) {
    float tHeight = 0.0;
    for(float i = 0.0; i < iSteps; i+= 1.0)   {
        // The trace will stop at the point before the actuall intersection with m_HeightMap field happens
        tHeight = 1.0f - texture2DLod( m_HeightMap, CurrPoint - tStep, mipLevel ).x;

        if( (CurrHeight - hStep > tHeight) && (CurrHeight > 0) ) {
            CurrHeight -= hStep;
            CurrPoint  -= tStep;
        }
        else {
            Intersected = 1.0f;
            i = iSteps;
        }
    }
    return tHeight;
}

 

JME3 lighting.frag例子

    

float h;
         h = texture2D(m_ParallaxMap, texCoord).r;
          h = texture2D(m_NormalMap, texCoord).a;
       float heightScale = 0.05;
       float heightBias = heightScale * -0.5;
       vec3 normView = normalize(vViewDir);      // vViewDir为贴图空间

       h = (h * heightScale + heightBias) * normView.z;

       newTexCoord = texCoord + (h * -normView.xy);

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值