游戏开发论坛

 找回密码
 立即注册
搜索
查看: 172975|回复: 0

以画点方式画2D矩形,减少数据传输量

[复制链接]

2万

主题

2万

帖子

6万

积分

论坛元老

Rank: 8Rank: 8

积分
66484
QQ
发表于 2017-11-14 19:03:41 | 显示全部楼层 |阅读模式
原文链接: http://www.hyzgame.com.cn/?p=2040

主要思想是以画点模式绘图,在一个顶点数据下保存left,top,right,bottom四个数据。在Geometry shader中转换成Triangle Strip。
Vertex Shader
#version 330 core
uniform mat4 ModelViewProjectionMatrix;
layout(location=0) in vec4 Vertex;
void main()
{
vec4 lt=vec4(Vertex.xy,vec2(0,1));
vec4 rb=vec4(Vertex.zw,vec2(0,1));
vec4 lt_fin=lt*ModelViewProjectionMatrix;
vec4 rb_fin=rb*ModelViewProjectionMatrix;
gl_Position=vec4(lt_fin.xy,rb_fin.xy);
}
Geometry Shader
#version 330 core
layout (points) in;
layout (triangle_strip,max_vertices=4) out;
void main()
{
vec2 lt=gl_in[0].gl_Position.xy;
vec2 rb=gl_in[0].gl_Position.zw;
gl_Position=vec4(lt, vec2(0,1));EmitVertex();
gl_Position=vec4(lt.x,rb.y, vec2(0,1));EmitVertex();
gl_Position=vec4(rb.x,lt.y, vec2(0,1));EmitVertex();
gl_Position=vec4(rb, vec2(0,1));EmitVertex();
EndPrimitive();
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-3-29 04:37

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表