Jump to content

Canvas2D - How do I send texture coordinate to the shaders?


Knight
 Share

Recommended Posts

I want to draw a texture on the line that user draws on the screen. Like a mouse trail, so I follow this tutorial. . The only thing that doesn't answer me is sending the custom uv to the shaders. I vaguely remember that in C++, I can create struct or something and the shader will know how to handle it. It seems that is not the case here. I can't even figure out how does "index" property in vertex shader gets there. Even so, I can't use the "index" approach as the line won't be full rectangle as in the example.

Right now, I copied & pasted the entire lines2d classes and try to customize to be able to draw texture on there, but I don't know how to send the custom uv that I've calculated to the shader. Anyone can explain that to me? Or am I looking at this a wrong way?

Link to comment
Share on other sites

14 hours ago, Deltakosh said:

Do you mind sharing a PG to repro what you are doing?

Perhaps have a look to this one as well: http://doc.babylonjs.com/overviews/gui

http://playground.babylonjs.com/#9AHTEG

I want to draw the texture on the line at the bottom left, and make it curve along with the line too.

GUI is nice, and I may change to it in the future, but that still doesn't give me what I want. And from what I see, I won't have access to shaders that way too

Aside from adding extra variable (_texture and _fillUV), I haven't changed any process from lines2d at all

Link to comment
Share on other sites

varying vec4 vColor;
   
  void main(void) {
  gl_FragColor = vColor;
  }

 

with this? i think that need have some customizable function for access to control shader after that i can help

varying vec4 vColor;

uniform sampler2D txt1;

uniform vec2 screen;

 

   
 

void main(void) {

vec3 txt = texture2D(txt1, vec2(gl_FragCoord.x/screen.x ,gl_FragCoord.y / screen.y ).rgb; 

  gl_FragColor = vColor*0.5 +0.5 * vec4(txt,1.);
  }

 

 

Link to comment
Share on other sites

8 hours ago, NasimiAsl said:
varying vec4 vColor;
   
  void main(void) {
  gl_FragColor = vColor;
  }

 

with this? i think that need have some customizable function for access to control shader after that i can help

varying vec4 vColor;

uniform sampler2D txt1;

uniform vec2 screen;

 

   
 

void main(void) {

vec3 txt = texture2D(txt1, vec2(gl_FragCoord.x/screen.x ,gl_FragCoord.y / screen.y ).rgb; 

  gl_FragColor = vColor*0.5 +0.5 * vec4(txt,1.);
  }

 

 

I have not gone to fragment shader part yet, because I am now figuring out how to sent the uv to the vertex shader. In the PG, I use the lines2d shaders because I don't know how to upload my slightly edited version of it and use in PG.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...