opengl水波纹效果 纯色背景 问题?

wensefu 2013-07-18 04:42:24
我用glsl弄的水波纹效果,
但是现在发现当背景是纯色的时候就看不出水波效果了,
有没有大神给个解决思路啊!!

GLSL:




#pragma version(1)

#pragma rs java_package_name(com.android.systemui)

#include "rs_graphics.rsh"

// Things we need to set from the application
float g_glWidth;
float g_glHeight;
float g_meshWidth;
float g_meshHeight;
float g_xOffset;
float g_rotate;

rs_program_vertex g_PVWater;
rs_program_vertex g_PVSky;

rs_program_fragment g_PFSky;
rs_program_fragment g_PFBackground;

rs_allocation g_TRiverbed;

rs_mesh g_WaterMesh;


typedef struct Constants {
float4 Drop01;
float4 Drop02;
float4 Drop03;
float4 Drop04;
float4 Drop05;
float4 Drop06;
float4 Drop07;
float4 Drop08;
float4 Drop09;
float4 Drop10;
float4 Offset;
float Rotate;
} Constants_t;

Constants_t *g_Constants;
rs_program_store g_PFSBackground;

//float skyOffsetX;
//float skyOffsetY;
static float g_DT;
static int64_t g_LastTime;

typedef struct Drop {
float ampS;
float ampE;
float spread;
float x;
float y;
} Drop_t;
static Drop_t gDrops[10];
static int gMaxDrops;


void init() {
int ct;
gMaxDrops = 10;
for (ct=0; ct<gMaxDrops; ct++) {
gDrops[ct].ampS = 0;
gDrops[ct].ampE = 0;
gDrops[ct].spread = 1;
}
g_LastTime = rsUptimeMillis();
g_DT = 0.1f;
}

static void updateDrop(int ct) {
gDrops[ct].spread += 30.f * g_DT;
gDrops[ct].ampE = gDrops[ct].ampS / gDrops[ct].spread;
}

static void drop(int x, int y, float s) {
int ct;
int iMin = 0;
float minAmp = 3000.f;
for (ct = 0; ct < gMaxDrops; ct++) {
if (gDrops[ct].ampE < minAmp) {
iMin = ct;
minAmp = gDrops[ct].ampE;
}
}
gDrops[iMin].ampS = s;
gDrops[iMin].spread = 0;
gDrops[iMin].x = x;
gDrops[iMin].y = g_meshHeight - y - 1;
updateDrop(iMin);
}


static void generateRipples() {
int ct;
for (ct = 0; ct < gMaxDrops; ct++) {
Drop_t * d = &gDrops[ct];
float *v = (float*)&g_Constants->Drop01;
v += ct*4;
*(v++) = d->x;
*(v++) = d->y;
*(v++) = d->ampE * 0.22f;
*(v++) = d->spread;
}
g_Constants->Offset.x = g_xOffset;

for (ct = 0; ct < gMaxDrops; ct++) {
updateDrop(ct);
}
}

//绘制水中的倒影
static void drawRiverbed() {
rsgBindProgramFragment(g_PFBackground);
rsgBindProgramStore(g_PFSBackground);
rsgBindTexture(g_PFBackground, 0, g_TRiverbed);
rsgDrawMesh(g_WaterMesh);
}


void addDrop(int x, int y) {
drop(x, y, 6);
}


int root(void) {
rsgClearColor(0.f, 0.f, 0.f, 2.f);

// Compute dt in seconds.
int64_t newTime = rsUptimeMillis();
g_DT = (newTime - g_LastTime) * 0.001f;
g_DT = min(g_DT, 0.2f);
g_LastTime = newTime;

g_Constants->Rotate = (float) g_rotate;


rsgBindProgramVertex(g_PVWater);
generateRipples();
rsgAllocationSyncAll(rsGetAllocation(g_Constants));
drawRiverbed();

return 50;
}

...全文
330 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xvqian2 2015-01-21
  • 打赏
  • 举报
回复
没人知道,我也想知道哎

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧