【发布时间】:2019-09-05 00:04:42
【问题描述】:
你有一个简单的盒子,里面有一张图片。
你还有两个纹理,一个红色的,一个绿色的......
您从绿色纹理初始化您使用的纹理...
您的窗口首先显示您未更改的使用纹理:
阴影圆圈围绕鼠标显示纹理的一部分。
当你按下鼠标按钮时,阴影区域变为红色纹理,如下图所示:
到目前为止一切顺利。但是,我进行了很多搜索,但找不到将片段着色器的结果存储到显示的使用纹理的方法。总操作将加起来形成第一个和第二个纹理的混合。
这是我的相关片段着色器:
#version 120
uniform sampler2D red_texture, used_texture;
uniform bool isMouseClicked;
uniform float mousex, mousey;
uniform float radius; //the radius of the painting circle
void shadePixel(){ ... }
void main(){
//calculate the distance from mouse origin
float distance = sqrt(pow((gl_FragCoord.x - mousex), 2) + pow((gl_FragCoord.y - mousey), 2));
if(distance<=radius && isMouseClicked){
//used_texture <- red_tuxture
}
if(distance<=radius) shadePixel(); //make circle bound visible
else gl_FragColor = texture2D(used_texture, gl_TexCoord[0].xy);
}
我想稍后将纹理检索到 ram 并作为图像保存到磁盘。
那么,有没有办法通过片段着色器来操作纹理?
【问题讨论】: