Hello everyone,
I might have a very simple question but I am having problems with getting it to work.
In short, I want to be able to change output colour of fragment shader per its position on screen - the more in the center of the screen it is, the more transparent the result colour should be.
Use case is also quite simple - I want fog to be less dense in the middle of the screen and get more dense towards the edges.
I thought I will just use the calculation of output position in vertex shader, but it simply doesnt work well for whatever reason.
Anyone did something similar?
Thank you for your help!
Shader - change colour per position on screen
-
- Gnome
- Posts: 368
- Joined: Tue Jan 06, 2009 1:12 pm
- x 43
-
- Gnome
- Posts: 368
- Joined: Tue Jan 06, 2009 1:12 pm
- x 43
Re: Shader - change colour per position on screen
Noone knows? I thought that it must be something easy for guys working with graphics but maybe it is not?
-
- OGRE Team Member
- Posts: 2151
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1156
-
- Gnome
- Posts: 368
- Joined: Tue Jan 06, 2009 1:12 pm
- x 43
Re: Shader - change colour per position on screen
Hello paroj,
thank you for the reply. The link you sent did not help me directly because I use cg, but thanks to it I was able to find a chain or pages from which I got the solution.
I am not sure how good the solution is but here it is
Vertex shader:
Fragment shader:
or probably even better
I am not sure how good or efficient the solution is but it works. If anyone has ideas how to make it better or different way, please let me know.
thank you for the reply. The link you sent did not help me directly because I use cg, but thanks to it I was able to find a chain or pages from which I got the solution.
I am not sure how good the solution is but here it is
Vertex shader:
Code: Select all
output.screenPosition = output.position; //standard output position from vs
Code: Select all
vertex_output.screenPosition.xy /= vertex_output.screenPosition.w;
float2 texCoord = 0.5f * (float2(vertex_output.screenPosition.x, -vertex_output.screenPosition.y) + 1);
float distanceFromCenterOfScreen = 1 - max(abs(texCoord[0] - 0.5), abs(texCoord[1] - 0.5));
Code: Select all
float distanceFromCenterOfScreen = distance(texCoord.xy, float2(0.5, 0.5));