Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 1-Jan-15 22:38pm
v2
Comments
Richard MacCutchan 31-Dec-14 10:13am    
What are the values of dist1 and dist2?
mostwanted4 31-Dec-14 10:36am    
I don't know exactly but in the test from the pictures they're between 0 and sqrt(2) * 40. Although, I'm not sure it matters because I've tested with multiple values from that range and it doesn't produce the same results.
[no name] 31-Dec-14 11:05am    
That is great if you don't know it exactly. Does it also mean you do not know what you are doing?
Richard MacCutchan 31-Dec-14 11:39am    
:)
[no name] 31-Dec-14 11:57am    
That is from self made experience, I know this from myself....sometimes trying and playing with things I don't know/understand
:-)

1 solution

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
 
Share this answer
 
Comments
mostwanted4 2-Jan-15 4:41am    
Maybe I wasn't clear enough. Let me give you an example: The first code draws entire red circles, while the second only draws part of those red circles, and the only change is the line where I give green a value.
Sergey Alexandrovich Kryukov 2-Jan-15 10:17am    
Do you think that the miracle happened. I don't know R value you assign, because I have no information on that. I just tell you that your shown part of code does not show that you are doing it right or wrong. Just use the debugger. Have you done that?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900