opengl渲染YUV的波浪百叶窗效果
接上一篇---3D融合场景demo - 邗影 - 博客园
#version 330 core in vec2 TexCoord; out vec4 FragColor; uniform sampler2D yTexture; uniform sampler2D uvTexture; uniform float time;//new
// void main() { float blinds = 16.0; float stripId = floor(TexCoord.y * blinds); float stripFract = fract(TexCoord.y * blinds); float phase = stripId * 0.6; float openness = (sin(time * 1.5 + phase) + 1.0) * 0.5; // 0.0 ~ 1.0 float slatWidth = 0.2 + 0.6 * openness; if (stripFract > slatWidth) { float y = texture(yTexture, TexCoord).r; float u = texture(uvTexture, TexCoord).r - 0.5; float v = texture(uvTexture, TexCoord).g - 0.5; float r = y + 1.402 * v; float g = y - 0.344136 * u - 0.714136 * v; float b = y + 1.772 * u; FragColor = vec4(r, g, b, 1.0); return; } float tilt = (1.0 - openness) * 0.04 * (mod(stripId, 2.0) * 2.0 - 1.0); vec2 sampleUV = TexCoord + vec2(tilt, 0.0); float y = texture(yTexture, sampleUV).r; float u = texture(uvTexture, sampleUV).r - 0.5; float v = texture(uvTexture, sampleUV).g - 0.5; float r = y + 1.402 * v; float g = y - 0.344136 * u - 0.714136 * v; float b = y + 1.772 * u; float dim = 0.5 + 0.5 * openness; FragColor = vec4(r * dim, g * dim, b * dim, 1.0); }
yuvShader.setFloat("time", static_cast<float>(glfwGetTime()));
sin(time * 1.5 + phase)让每片叶片周期性开合phase = stripId * 0.6让相邻叶片错开相位,形成波浪- 缝隙处直接透出完整 YUV 视频
- 叶片上的视频随开合变暗/变亮,并有轻微倾斜
浙公网安备 33010602011771号