赋予绿色价值以某种方式清除红色 [英] Giving green a value somehow clears red

查看:104
本文介绍了赋予绿色价值以某种方式清除红色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像素着色器,其中我有以下部分

 imgcolor.b = 0; 
imgcolor.r = 1 - dist1 / 5;
imgcolor.g = 0;



如果我进行以下更改

 imgcolor.b = 0 ; 
imgcolor.r = 1 - dist1 / 5;
imgcolor.g = 1 - min(1,max(0,dist2));



其中dist1和dist2都是浮点数,红色值变为0 in不应该的部分。为什么会这样?我该如何预防呢?



第一种情况: https://www.dropbox.com/s/bq2irg4nsjarne2/good.jpg?dl=0 [ ^ ]

第二种情况: https://www.dropbox.com/s/jy0z2zk56h9jl96/wrong.jpg?dl=0 [ ^ ]

链接到着色器的源代码(带注释) : http://pastebin.com/3128bpkC [ ^ ]





更新:谢谢你的建议。我最终做的是重写计算dist1&的代码。 dist2和问题以某种方式消失了。

解决方案

这是纯粹而且非常简单的算法。例如,如果 dist1 变为5,则 r 将为零。请注意,实际上它可能是接近零的非零值。使用调试器并找到原因。根据您的有限信息,这一切都可以说。



祝你好运,

-SA

I have a pixel shader in which I have the following part

imgcolor.b = 0;
imgcolor.r = 1 - dist1 / 5;
imgcolor.g = 0;


if I make the following change

imgcolor.b = 0;
imgcolor.r = 1 - dist1 / 5;
imgcolor.g = 1 - min(1,max(0,dist2));


where both dist1 and dist2 are float the red value becomes 0 in parts where it shouldn't be. Why does this happen? How do I prevent it?

First case: https://www.dropbox.com/s/bq2irg4nsjarne2/good.jpg?dl=0[^]
Second case: https://www.dropbox.com/s/jy0z2zk56h9jl96/wrong.jpg?dl=0[^]
Link to shader's source(with comments): http://pastebin.com/3128bpkC[^]


UPDATE: Thank you al for your suggestions. What I ended up doing was to rewrite the code that calculates dist1 & dist2 and the issue somehow dissapeared.

解决方案

This is pure and very simple arithmetic. If, for example dist1 becomes 5, your r will be zero. Note that actually it could be non-zero value close to zero. Use the debugger and find the reason. This is all to be said based on your limited information.

Good luck,
—SA


这篇关于赋予绿色价值以某种方式清除红色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆