modify effects conwav alple
This commit is contained in:
parent
e271e78200
commit
52c20bd297
@ -11,6 +11,7 @@
|
|||||||
#include <osg/Program>
|
#include <osg/Program>
|
||||||
#include <osg/Uniform>
|
#include <osg/Uniform>
|
||||||
#include <osg/Depth>
|
#include <osg/Depth>
|
||||||
|
#include <osg/Cullface>
|
||||||
#include <osgEarth/Registry>
|
#include <osgEarth/Registry>
|
||||||
|
|
||||||
class WaveSurfaceCallback : public osg::NodeCallback {
|
class WaveSurfaceCallback : public osg::NodeCallback {
|
||||||
@ -96,6 +97,11 @@ ConeWave::ConeWave() {
|
|||||||
levelHeight_ = 100.0f;
|
levelHeight_ = 100.0f;
|
||||||
baseColor_ = osg::Vec4(0.0f, 0.8f, 1.0f, 1.0f);
|
baseColor_ = osg::Vec4(0.0f, 0.8f, 1.0f, 1.0f);
|
||||||
waveColor_ = osg::Vec4(1.0f, 0.5f, 1.0f, 0.8f);
|
waveColor_ = osg::Vec4(1.0f, 0.5f, 1.0f, 0.8f);
|
||||||
|
|
||||||
|
// 初始化透明度值
|
||||||
|
ringBrightAlpha_ = 0.8f;
|
||||||
|
ringDarkAlpha_ = 0.3f;
|
||||||
|
coneAlpha_ = 0.7f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +120,7 @@ void ConeWave::InitGeode() {
|
|||||||
getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
|
getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||||
getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||||
getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
|
getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
|
||||||
setCullingActive(false);
|
setCullingActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConeWave::Destory() {
|
void ConeWave::Destory() {
|
||||||
@ -196,6 +202,31 @@ void ConeWave::SetWaveColor(const osg::Vec4& color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 透明度控制方法实现
|
||||||
|
void ConeWave::SetRingBrightAlpha(float alpha) {
|
||||||
|
ringBrightAlpha_ = alpha;
|
||||||
|
if (ringBrightAlphaUniform_.valid()) {
|
||||||
|
ringBrightAlphaUniform_->set(alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConeWave::SetRingDarkAlpha(float alpha) {
|
||||||
|
ringDarkAlpha_ = alpha;
|
||||||
|
if (ringDarkAlphaUniform_.valid()) {
|
||||||
|
ringDarkAlphaUniform_->set(alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConeWave::SetConeAlpha(float alpha) {
|
||||||
|
coneAlpha_ = alpha;
|
||||||
|
// 更新锥形的基础颜色透明度
|
||||||
|
if (coneDrawable_.valid()) {
|
||||||
|
osg::Vec4 currentColor = coneDrawable_->getColor();
|
||||||
|
currentColor.a() = alpha;
|
||||||
|
coneDrawable_->setColor(currentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ConeWave::CreateRadarScanWave() {
|
void ConeWave::CreateRadarScanWave() {
|
||||||
// 使用OSG内置的Cone几何体来创建雷达扫描区域
|
// 使用OSG内置的Cone几何体来创建雷达扫描区域
|
||||||
cone_ = new osg::Cone(osg::Vec3(0, 0, height_/2), radius_, height_);
|
cone_ = new osg::Cone(osg::Vec3(0, 0, height_/2), radius_, height_);
|
||||||
@ -209,7 +240,7 @@ void ConeWave::CreateRadarScanWave() {
|
|||||||
|
|
||||||
// 创建可绘制对象
|
// 创建可绘制对象
|
||||||
coneDrawable_ = new osg::ShapeDrawable(cone_, tesselate);
|
coneDrawable_ = new osg::ShapeDrawable(cone_, tesselate);
|
||||||
coneDrawable_->setColor(osg::Vec4(0.0f, 0.8f, 1.0f, 0.7f)); // 设置基础颜色
|
coneDrawable_->setColor(osg::Vec4(0.0f, 0.8f, 1.0f, coneAlpha_)); // 使用coneAlpha_设置基础颜色
|
||||||
|
|
||||||
// 添加到几何节点
|
// 添加到几何节点
|
||||||
addDrawable(coneDrawable_);
|
addDrawable(coneDrawable_);
|
||||||
@ -225,6 +256,7 @@ void ConeWave::CreateRadarScanWave() {
|
|||||||
ss->setAttributeAndModes(bf, osg::StateAttribute::ON);
|
ss->setAttributeAndModes(bf, osg::StateAttribute::ON);
|
||||||
ss->setMode(GL_BLEND, osg::StateAttribute::ON);
|
ss->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||||
ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||||
|
ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK));
|
||||||
|
|
||||||
// 创建雷达扫描波着色器
|
// 创建雷达扫描波着色器
|
||||||
CreateRadarShader();
|
CreateRadarShader();
|
||||||
@ -245,29 +277,28 @@ void ConeWave::CreateRadarShader() {
|
|||||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
// 片段着色器 - 明显的同心圆波纹效果
|
// 片段着色器 - 可控透明度的同心圆波纹效果
|
||||||
static const char* fragmentShaderSource =
|
static const char* fragmentShaderSource =
|
||||||
"uniform float num;\n"
|
"uniform float num;\n"
|
||||||
"uniform float height;\n"
|
"uniform float height;\n"
|
||||||
"uniform vec4 baseColor;\n"
|
"uniform vec4 baseColor;\n"
|
||||||
"uniform float waveTime;\n"
|
"uniform float waveTime;\n"
|
||||||
|
"uniform float ringBrightAlpha;\n"
|
||||||
|
"uniform float ringDarkAlpha;\n"
|
||||||
"varying vec3 pos;\n"
|
"varying vec3 pos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float h = abs(pos.z) / max(height, 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 radialDist = sqrt(pos.x * pos.x + pos.y * pos.y);\n"
|
||||||
" float wavePhase = radialDist * 0.3 - waveTime * 1.5;\n"
|
" float wavePhase = radialDist * 3.2 - waveTime * 30.0;\n"
|
||||||
" float ripple = sin(wavePhase);\n"
|
" float ripple = sin(wavePhase);\n"
|
||||||
" float heightWave = sin(h * num * 6.28 + waveTime * 1.0);\n"
|
" if (ripple > 0.3)\n"
|
||||||
" if (ripple > 0.5)\n"
|
|
||||||
" {\n"
|
" {\n"
|
||||||
" float intensity = (heightWave + 1.0) * 0.4 + 0.6;\n"
|
" gl_FragColor = vec4(baseColor.rgb, ringBrightAlpha);\n"
|
||||||
" gl_FragColor = vec4(baseColor.rgb, intensity);\n"
|
|
||||||
" }\n"
|
" }\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" float intensity = (heightWave + 1.0) * 0.1 + 0.1;\n"
|
" gl_FragColor = vec4(baseColor.rgb, ringDarkAlpha);\n"
|
||||||
" gl_FragColor = vec4(baseColor.rgb, intensity);\n"
|
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
/*
|
/*
|
||||||
@ -324,11 +355,17 @@ void ConeWave::CreateRadarShader() {
|
|||||||
levelCountUniform_ = new osg::Uniform("num", 5.0f); // 层数
|
levelCountUniform_ = new osg::Uniform("num", 5.0f); // 层数
|
||||||
levelHeightUniform_ = new osg::Uniform("height", height_ > 0 ? height_ : 100.0f); // 确保高度不为0
|
levelHeightUniform_ = new osg::Uniform("height", height_ > 0 ? height_ : 100.0f); // 确保高度不为0
|
||||||
|
|
||||||
|
// 创建透明度控制uniform变量
|
||||||
|
ringBrightAlphaUniform_ = new osg::Uniform("ringBrightAlpha", ringBrightAlpha_);
|
||||||
|
ringDarkAlphaUniform_ = new osg::Uniform("ringDarkAlpha", ringDarkAlpha_);
|
||||||
|
|
||||||
stateSet->addUniform(waveTimeUniform_);
|
stateSet->addUniform(waveTimeUniform_);
|
||||||
stateSet->addUniform(baseColorUniform_);
|
stateSet->addUniform(baseColorUniform_);
|
||||||
stateSet->addUniform(waveColorUniform_);
|
stateSet->addUniform(waveColorUniform_);
|
||||||
stateSet->addUniform(levelCountUniform_);
|
stateSet->addUniform(levelCountUniform_);
|
||||||
stateSet->addUniform(levelHeightUniform_);
|
stateSet->addUniform(levelHeightUniform_);
|
||||||
|
stateSet->addUniform(ringBrightAlphaUniform_);
|
||||||
|
stateSet->addUniform(ringDarkAlphaUniform_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConeWave::CreateTexturedCone(osg::Geode* geode) {
|
void ConeWave::CreateTexturedCone(osg::Geode* geode) {
|
||||||
|
@ -60,6 +60,16 @@ public:
|
|||||||
return levelHeight_;
|
return levelHeight_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 透明度控制方法
|
||||||
|
void SetRingBrightAlpha(float alpha);
|
||||||
|
float GetRingBrightAlpha() const { return ringBrightAlpha_; }
|
||||||
|
|
||||||
|
void SetRingDarkAlpha(float alpha);
|
||||||
|
float GetRingDarkAlpha() const { return ringDarkAlpha_; }
|
||||||
|
|
||||||
|
void SetConeAlpha(float alpha);
|
||||||
|
float GetConeAlpha() const { return coneAlpha_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateTexturedCone(osg::Geode* geode);
|
virtual void CreateTexturedCone(osg::Geode* geode);
|
||||||
|
|
||||||
@ -82,12 +92,22 @@ private:
|
|||||||
osg::ref_ptr<osg::Uniform> waveCountUniform_;
|
osg::ref_ptr<osg::Uniform> waveCountUniform_;
|
||||||
osg::ref_ptr<osg::Uniform> waveColorUniform_;
|
osg::ref_ptr<osg::Uniform> waveColorUniform_;
|
||||||
|
|
||||||
|
// 透明度控制uniform变量
|
||||||
|
osg::ref_ptr<osg::Uniform> ringBrightAlphaUniform_;
|
||||||
|
osg::ref_ptr<osg::Uniform> ringDarkAlphaUniform_;
|
||||||
|
osg::ref_ptr<osg::Uniform> coneAlphaUniform_;
|
||||||
|
|
||||||
float waveRadius_{ 100.0f }; // 扫描波最大半径
|
float waveRadius_{ 100.0f }; // 扫描波最大半径
|
||||||
float waveSpeed_{ 20.0f }; // 扫描波速度
|
float waveSpeed_{ 20.0f }; // 扫描波速度
|
||||||
int waveCount_{ 30 }; // 同时存在的波纹数量
|
int waveCount_{ 30 }; // 同时存在的波纹数量
|
||||||
osg::Vec4 baseColor_{ 1.0f, 0.2f, 0.5f, 1.f };
|
osg::Vec4 baseColor_{ 1.0f, 0.2f, 0.5f, 1.f };
|
||||||
osg::Vec4 waveColor_{ 0.0f, 0.5f, 1.0f, 0.8f }; // 扫描波颜色(蓝色)
|
osg::Vec4 waveColor_{ 0.0f, 0.5f, 1.0f, 0.8f }; // 扫描波颜色(蓝色)
|
||||||
double currentTime_{ 0.0 }; // 当前时间
|
double currentTime_{ 0.0 }; // 当前时间
|
||||||
|
|
||||||
|
// 透明度值
|
||||||
|
float ringBrightAlpha_{ 0.8f }; // 亮环透明度
|
||||||
|
float ringDarkAlpha_{ 0.3f }; // 暗环透明度
|
||||||
|
float coneAlpha_{ 0.7f }; // 锥形透明度
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user