G
Gun_Goose
Guest
Hi, I am trying to write a shader in which I pass it a point and a radius, and the shader fades objects to black the farther you get from the point. I am having a little trouble understanding how to compare this location to every pixel on the screen. (i am working in 3d, so I would like to try to grab the z value of each pixel as well.) My code looks something like this: (pos is the position I am passing in and 300 is just a radius value I am testing with.)
//vertex
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); v_vWorld = (gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos).xyz;
// fragment
vec4 base_col = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord); gl_FragColor = vec4(base_col.rgb, base_col.a*(distance(pos,v_vWorld)/300.0));
Does anyone know how I could make my distance comparison to every pixel on the screen?
//vertex
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); v_vWorld = (gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos).xyz;
// fragment
vec4 base_col = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord); gl_FragColor = vec4(base_col.rgb, base_col.a*(distance(pos,v_vWorld)/300.0));
Does anyone know how I could make my distance comparison to every pixel on the screen?