Skip to content

Commit 3e9b93f

Browse files
author
Jiang Feng
committed
code clean up; one more shader toy
1 parent f4dcbeb commit 3e9b93f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

hmiios2014/OpenglWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool OpenglWindow::event(QEvent* event)
238238
|| l_keyevent->key() == Qt::Key_9
239239
|| l_keyevent->key() == Qt::Key_0)
240240
{
241-
selectShader((l_keyevent->key() - Qt::Key_1) + 1);
241+
selectShader(l_keyevent->key() - Qt::Key_0);
242242
}
243243
return true;
244244
}

hmiios2014/TSDWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ void TSDWindow::render()
578578

579579
m_program->bind();
580580
m_program->setUniformValue(m_matrixUniform, matrix);
581-
m_program->setUniformValue(m_mouse, mouse[0] * devicePixelRatio(), -mouse[1] * devicePixelRatio() + resolution[1]/2);
582-
m_program->setUniformValue(m_mouseDelta, mouseDelta[0] * devicePixelRatio(), -mouseDelta[1] * devicePixelRatio());
581+
m_program->setUniformValue(m_mouse, mouse[0] * retinaScale, -mouse[1] * retinaScale + resolution[1]/2);
582+
m_program->setUniformValue(m_mouseDelta, mouseDelta[0] * retinaScale, -mouseDelta[1] * retinaScale);
583583
m_program->setUniformValue(m_resolution, resolution[0], resolution[1]);
584584
m_program->setUniformValue(m_time, time);
585585
m_program->setUniformValue(m_shaderId, m_shader);

hmiios2014/fshader.glsl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@ void main() {
186186
}
187187
gl_FragColor = vec4(o.xyz, 1.0);
188188
}
189+
else if(shader_id == 6)
190+
{
191+
const int complexity = 3; // More points of color.
192+
const float mouse_factor = 56.0; // Makes it more/less jumpy.
193+
const float mouse_offset = 40.0; // Drives complexity in the amount of curls/cuves. Zero is a single whirlpool.
194+
const float fluid_speed = 108.0; // Drives speed, higher number will make it slower.
195+
const float color_intensity = 0.8;
196+
197+
vec2 p=(2.0*(gl_FragCoord.xy - mouseDelta.xy)-resolution)/max(resolution.x,resolution.y);
198+
for(int i=1;i<complexity;i++)
199+
{
200+
vec2 newp=p + time*0.1;
201+
newp.x+=0.6/float(i)*sin(float(i)*p.y+time/fluid_speed+0.3*float(i)) + 0.5; // + mouse.y/mouse_factor+mouse_offset;
202+
newp.y+=0.6/float(i)*sin(float(i)*p.x+time/fluid_speed+0.3*float(i+10)) - 0.5; // - mouse.x/mouse_factor+mouse_offset;
203+
p=newp;
204+
}
205+
vec3 col=vec3(color_intensity*sin(3.0*p.x)+color_intensity,color_intensity*sin(3.0*p.y)+color_intensity,color_intensity*sin(p.x+p.y)+color_intensity);
206+
gl_FragColor=vec4(col, 1.0);
207+
}
189208
else
190209
{
191210
gl_FragColor =vec4(.0, .6, .0,1.);

0 commit comments

Comments
 (0)