调试osgEarth的Rex引擎原理分析(十三)选择信息的作用--传递渐变参数给shader

这篇博客介绍了如何在3D渲染中通过shader传递渐变参数来融合高程和地表影像。在tileNode创建时设置参数,利用统一变量`oe_tile_morph`在着色器`RexEngine.Morphing.vert.glsl`中实现顶点变形,根据距离和高度计算融合因子,从而实现地形的平滑过渡效果。
摘要由CSDN通过智能技术生成

感谢 @hankern
学习链接https://blog.csdn.net/hankern/article/details/84160758

这节主要是说明如何将渐变参数传给shader,用于融合高程和地表影像。传递时机是在tileNode创建时
设置断点截图如下
在这里插入图片描述

可知,通过_tileMorphUniform传递过去的
在这里插入图片描述

跟踪oe_tile_morph,
在这里插入图片描述

可见在文件RexEngine.Morphing.vert.glsl里。
拷贝进来
#version $GLSL_VERSION_STR

#pragma vp_name REX Engine - Morphing
#pragma vp_entryPoint oe_rexEngine_morph
#pragma vp_location vertex_model
#pragma vp_order 0.5
#pragma vp_define OE_REX_VERTEX_MORPHING

// stage
vec3 vp_Normal; // up vector

vec4 oe_layer_texc;
vec4 oe_layer_tilec;

out float oe_rex_morphFactor;

uniform sampler2D oe_tile_elevationTex;
uniform mat4 oe_tile_elevationTexMatrix;
uniform vec2 oe_tile_morph;
uniform float oe_tile_size;
uniform vec4 oe_tile_key;

// SDK functions:
float oe_terrain_getElevation(in vec2 uv);

// Vertex Markers:
#define MASK_MARKER_DISCARD 0.0
#define MASK_MARKER_NORMAL 1.0
#define MASK_MARKER_SKIRT 2.0
#define MASK_MARKER_BOUNDARY 3.0

// Morphs a vertex using a neighbor.
void oe_rex_MorphVertex(inout vec3 position, inout vec2 uv, in vec3 neighborPosition)
{
float halfSize = (0.5*oe_tile_size)-0.5;
float twoOverHalfSize = 2.0/(oe_tile_size-1.0);

vec2 fractionalPart = fract(uv * halfSize) * twoOverHalfSize;
uv = clamp(uv - (fractionalPart * oe_rex_morphFactor), 0.0, 1.0);
//uv = clamp(uv, 0, 1);

vec3 morphVector = neighborPosition.xyz - position.xyz;
position.xyz = position.xyz + morphVector*oe_rex_morphFactor;
}

// Compute a morphing factor based on model-space inputs:
float oe_rex_ComputeMorphFactor(in vec4 position, in vec3 up)
{
// Find the “would be” position of the vertex (the position the vertex would
// assume with no morphing)
vec4 wouldBePosition = position;

#ifdef OE_REX_VERTEX_MORPHING
    float elev = oe_terrain_getElevation( oe_layer_tilec.st );
	wouldBePosition.xyz += up*elev;
#endif

vec4 wouldBePositionView = gl_ModelViewMatrix * wouldBePosition;

float fDistanceToEye = length(wouldBePositionView.xyz); // or just -z.
float fMorphLerpK  = 1.0f - clamp( oe_tile_morph[0] - fDistanceToEye * oe_tile_morph[1], 0.0, 1.0 );
return fMorphLerpK;

}

void oe_rexEngine_morph(inout vec4 vertexModel)
{
// compute the morphing factor to send down the pipe.
// we need this even if vertex-morphing is off since we use it for
// other things (like image blending)
if (oe_layer_tilec.z == MASK_MARKER_NORMAL)
{
oe_rex_morphFactor = oe_rex_ComputeMorphFactor(vertexModel, vp_Normal);

#ifdef OE_REX_VERTEX_MORPHING
vec3 neighborVertexModel = gl_MultiTexCoord1.xyz;
oe_rex_MorphVertex(vertexModel.xyz, oe_layer_tilec.st, neighborVertexModel.xyz);
#endif
}
else
{
oe_rex_morphFactor = 0.0;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值