1
\$\begingroup\$

I'm beginning with shader. I wonder what if i apply shader for single node, what'll happen?

The gl_FragCoord = (0.5,0.5) is the bottom left of the screen or the bottom left of the node?

I get some wrong caculations while wanting to draw something in the center of the node (not the screen).

Many shader tutorias with sample code to draw at center using gl_FragCoord.xy / resolution.xy, if it's 0.5, it's center. In this case, it might be wrong because i want to draw in center of the node.

Finally, how's about texture2D i use texture2D instead of texture, are they the same?

I've applied this code on the node and it prints out the whole screen with stretch version (resolution = device resolution)

vec2 xy = gl_FragCoord.xy / resolution.xy;
vec4 texColor = texture2D(CC_Texture0,xy);
gl_FragColor = texColor;
\$\endgroup\$
6
  • \$\begingroup\$ Shader code doesn't know about nodes or scenes - it is run on the GPU. Therefore you need to calculate the proper position of your pixels (which every proper tutorial should show) \$\endgroup\$ Commented Mar 8, 2017 at 7:35
  • \$\begingroup\$ @UnholySheep Thanks, because i don't know why if i test the shader code on ShaderToy, it works. But i apply it to the node, it's wrong. So i though using gl_FragCoord.xy / resolution.xy is wrong in this case to get position of pixel on the node? \$\endgroup\$
    – TomSawyer
    Commented Mar 8, 2017 at 8:06
  • \$\begingroup\$ gl_FragCoord.xy / resolution.xy is the center of the viewport (assuming that resolution is the viewport resolution like it is in ShaderToy). To get the center of the node you need to either pass the node's coordinates into the shader and calculate the screen pixels from that or do the calculation CPU side and pass the coordinates into the shader \$\endgroup\$ Commented Mar 8, 2017 at 8:26
  • \$\begingroup\$ Thank. So it means applying shader to screen or node makes no difference here? Every opengl function applies for the whole screen? I have to ask because if the node (drawNode) is small, i can't see what has been rendering outside of it until it become larger, so i though shader apply to the node layer only. If i remove this node, i can't see the shader result? \$\endgroup\$
    – TomSawyer
    Commented Mar 8, 2017 at 8:39
  • \$\begingroup\$ Shaders are run on the GPU which doesn't know anything about nodes. However if a node is considered to be invisible (e.g.: outside the camera's view) by the engine it will never run it's shader code \$\endgroup\$ Commented Mar 8, 2017 at 8:42

0

You must log in to answer this question.

Browse other questions tagged .