modify conwave
This commit is contained in:
parent
d2a724bde6
commit
e271e78200
@ -85,6 +85,17 @@ private:
|
||||
ConeWave::ConeWave() {
|
||||
osgEarth::Registry::shaderGenerator().run(this);
|
||||
currentTime_ = 0.0;
|
||||
|
||||
// 确保成员变量有合理的默认值
|
||||
height_ = 100.0f;
|
||||
radius_ = 50.0f;
|
||||
waveRadius_ = 100.0f;
|
||||
waveSpeed_ = 20.0f;
|
||||
waveCount_ = 3;
|
||||
levelCount_ = 5;
|
||||
levelHeight_ = 100.0f;
|
||||
baseColor_ = osg::Vec4(0.0f, 0.8f, 1.0f, 1.0f);
|
||||
waveColor_ = osg::Vec4(1.0f, 0.5f, 1.0f, 0.8f);
|
||||
}
|
||||
|
||||
|
||||
@ -187,17 +198,18 @@ void ConeWave::SetWaveColor(const osg::Vec4& color) {
|
||||
|
||||
void ConeWave::CreateRadarScanWave() {
|
||||
// 使用OSG内置的Cone几何体来创建雷达扫描区域
|
||||
cone_ = new osg::Cone(osg::Vec3(0, 0, 0.), waveRadius_, height_);
|
||||
cone_ = new osg::Cone(osg::Vec3(0, 0, height_/2), radius_, height_);
|
||||
|
||||
// 设置细分参数,创建更平滑的圆形底面
|
||||
osg::TessellationHints* tesselate = new osg::TessellationHints;
|
||||
tesselate->setCreateBottom(true); // 创建底面作为扫描面
|
||||
tesselate->setCreateTop(true); // 创建顶面
|
||||
tesselate->setCreateBackFace(false); // 不创建背面
|
||||
tesselate->setDetailRatio(2.0f); // 增加细分精度
|
||||
|
||||
// 创建可绘制对象
|
||||
coneDrawable_ = new osg::ShapeDrawable(cone_, tesselate);
|
||||
coneDrawable_->setColor(waveColor_);
|
||||
coneDrawable_->setColor(osg::Vec4(0.0f, 0.8f, 1.0f, 0.7f)); // 设置基础颜色
|
||||
|
||||
// 添加到几何节点
|
||||
addDrawable(coneDrawable_);
|
||||
@ -205,10 +217,11 @@ void ConeWave::CreateRadarScanWave() {
|
||||
// 设置渲染状态
|
||||
osg::StateSet* ss = coneDrawable_->getOrCreateStateSet();
|
||||
ss->setRenderBinDetails(120, "RenderBin");
|
||||
ss->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
ss->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); // 关闭面剔除以确保可见
|
||||
ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
|
||||
// 设置混合模式
|
||||
osg::ref_ptr<osg::BlendFunc> bf = new osg::BlendFunc();
|
||||
osg::ref_ptr<osg::BlendFunc> bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
|
||||
ss->setAttributeAndModes(bf, osg::StateAttribute::ON);
|
||||
ss->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||
ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
@ -232,49 +245,29 @@ void ConeWave::CreateRadarShader() {
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
"}\n";
|
||||
|
||||
// 片段着色器 - 基于高度的波纹效果
|
||||
// 片段着色器 - 明显的同心圆波纹效果
|
||||
static const char* fragmentShaderSource =
|
||||
"uniform float num;\n"
|
||||
"uniform float height;\n"
|
||||
"uniform vec4 baseColor;\n"
|
||||
"uniform vec4 waveColor;\n"
|
||||
"uniform float waveTime;\n"
|
||||
"varying vec3 pos;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" // 基于高度的层次效果\n"
|
||||
" float h = abs(pos.z) / height;\n"
|
||||
" float layer = h * num + waveTime;\n"
|
||||
" \n"
|
||||
" // 简单的波纹效果\n"
|
||||
" float wave = sin(layer * 6.28);\n"
|
||||
" float pulse = (wave + 1.0) * 0.5;\n"
|
||||
" \n"
|
||||
" // 计算边缘\n"
|
||||
" float dist = sqrt(pos.x * pos.x + pos.y * pos.y);\n"
|
||||
" float maxDist = abs(pos.z) * 1.2;\n"
|
||||
" float edge = dist / maxDist;\n"
|
||||
" \n"
|
||||
" // 层次线效果\n"
|
||||
" float layerLine = sin(h * num * 6.28 + waveTime * 4.0);\n"
|
||||
" float lineIntensity = (layerLine + 1.0) * 0.5;\n"
|
||||
" \n"
|
||||
" // 颜色选择\n"
|
||||
" if (lineIntensity > 0.7 && edge < 1.0)\n"
|
||||
" float h = abs(pos.z) / max(height, 1.0);\n"
|
||||
" float radialDist = sqrt(pos.x * pos.x + pos.y * pos.y);\n"
|
||||
" float wavePhase = radialDist * 0.3 - waveTime * 1.5;\n"
|
||||
" float ripple = sin(wavePhase);\n"
|
||||
" float heightWave = sin(h * num * 6.28 + waveTime * 1.0);\n"
|
||||
" if (ripple > 0.5)\n"
|
||||
" {\n"
|
||||
" // 黄色边框线\n"
|
||||
" gl_FragColor = vec4(1.0, 1.0, 0.0, 0.9);\n"
|
||||
" }\n"
|
||||
" else if (edge < 1.0)\n"
|
||||
" {\n"
|
||||
" // 基础锥形区域\n"
|
||||
" float intensity = pulse * 0.6 + 0.3;\n"
|
||||
" gl_FragColor = vec4(baseColor.rgb * intensity, 0.4 * intensity);\n"
|
||||
" float intensity = (heightWave + 1.0) * 0.4 + 0.6;\n"
|
||||
" gl_FragColor = vec4(baseColor.rgb, intensity);\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" // 超出边界\n"
|
||||
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
|
||||
" float intensity = (heightWave + 1.0) * 0.1 + 0.1;\n"
|
||||
" gl_FragColor = vec4(baseColor.rgb, intensity);\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
/*
|
||||
@ -326,10 +319,10 @@ void ConeWave::CreateRadarShader() {
|
||||
|
||||
// 创建uniform变量
|
||||
waveTimeUniform_ = new osg::Uniform("waveTime", 0.0f);
|
||||
baseColorUniform_ = new osg::Uniform("baseColor", osg::Vec4(0.8f, 0.2f, 0.2f, 1.0f)); // 红色基调
|
||||
baseColorUniform_ = new osg::Uniform("baseColor", osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); // 绿色雷达色调
|
||||
waveColorUniform_ = new osg::Uniform("waveColor", waveColor_);
|
||||
levelCountUniform_ = new osg::Uniform("num", 8.0f); // 增加层数
|
||||
levelHeightUniform_ = new osg::Uniform("height", height_);
|
||||
levelCountUniform_ = new osg::Uniform("num", 5.0f); // 层数
|
||||
levelHeightUniform_ = new osg::Uniform("height", height_ > 0 ? height_ : 100.0f); // 确保高度不为0
|
||||
|
||||
stateSet->addUniform(waveTimeUniform_);
|
||||
stateSet->addUniform(baseColorUniform_);
|
||||
|
Loading…
Reference in New Issue
Block a user