Jump to content

vPositionW, Custom procedural texture


unicomp21
 Share

Recommended Posts

Need help on this one, trying to create a custom procedural texture, need access to the varying vPositionW, which I'm assuming is the lerp of the world vertex position.  Thanks!

 

This is the simple case I'm trying to get working, get link errors on vPositionW.

 

"#ifdef GL_ES\n" +
"precision highp float;\n" +
"#endif\n\n" +
"varying vec3 vPositionW; \n" +
"void main(void) {\n" +
" gl_FragColor = vec4(vPositionW.x,vPositionW.y,vPositionW.z, 1.0);\n" +

 

Link to comment
Share on other sites

Hi unicomp21!

It's not common for people to work-on shaders in the Babylon Playground, so I thought I'd show you a tasty shader-playground that forum user hw3web was working-on.  (and lots of others, too)  I believe these shaders and this water effect originally came from the World Monger demo and the "How to Create a Convincing World" tutorial.

http://playground.babylonjs.com/#R894C

The "original" is at http://playground.babylonjs.com/#BHX7Q#16 but I figured I would start a fresh one for you.  The playground is a great place to do experiments and hit RUN over and over again, saving and bookmarking the new save location, every so often.  When you discover something interesting or telling, save it, and paste the new url to this thread... and tell us what you discovered.  (so everyone can learn)

Keep in mind that textures used in the playground must be CORS-clear.  Textures from wikiMedia commons or from the playground's textures/ folder will work fine.  Any CORS-clear image should work.  When an image IS BLOCKED by CORS, the playground won't report that.  The image will just silently fail to load, but maybe check your browser's dev tools.  Possibly, the failed texture load will be reported in that area.

I wish I knew more about shaders, but, sorry.  I sometimes hear things like "time is the only variable that is passed to the shaders automatically".  I'm not overly sure what that means, but maybe you or others do.

I think I have seen someone set a shader's time vary-able from within a renderLoop... which means it can be over-ridden.  In other words... just because the vary-able is named 'time' does not mean you have to let it be "fed" by scene elapsed time (the default).  MAYBE, you can make "pokes" to the shader's time vary-able with anything, and at any rate (every frame, every 4th frame, only when an event happens, etc).  YOU could control the speed of 'time'. 

Don't mark my words... I'm not shader-trained.... yet.  Maybe YOU will help me with that.  :)

Anyway, now you have seen a Babylon Playground with shaders in the code.  Try to make a playground similar to the one above... that shows your problem.  That will assist the shader experts in helping you find the problem.  Good luck, be well.

Link to comment
Share on other sites

Thanks Wingnut!

I'm clear now, here's the url.

http://playground.babylonjs.com/#24PO9L

Look at the commented lines in the shader, I need a UVW corresponding to world space  coords of vertex so I can index into more complex 3D procedural textures, and splat them to this render-to 2D texture.  The idea would be using quad patches in the mesh and rendering them into the 2D procedural texture as squares.

Make sense?

Link to comment
Share on other sites

Hell no.  :D  Oh wait, maybe.  First, you'd have a procedural texture grid... available... one of the coolest ways to make a grid that I've heard-of.  But... hmm...

 

You could make a fake heightmap grid, too, I think.  A fake mountain in the middle of a grid... that isn't really there?  A shader is making it LOOK like it's really a mountain?  (ie. more complex 3D procedural textures)

 

Yeah, I think I'm on your frequency, or in the vicinity.  I hope you're going to teach us what you learn, and show us lots of demos.  And I KNOW the BJS procedural texture library is wholeheartedly welcoming new additions.  I'm excited!  You sound determined to kick butt!  :)  You've been to CYOS, right?  Suggestions or code to add new features to CYOS... are most-welcome, too. 

 

Yeah, we're all watching, UC.  Show us everything!  :)  Oh yeah, and I hope you get your issues answered.

Link to comment
Share on other sites

Hi again!  While you are waiting for experts to reply, maybe http://urbanproductions.com/wingy/babylon/ACP/acp_pretty.js will be helpful for you someday.  This is the main code (pretti-fied) for the Assassin's Creed - Pirates game from the BJS website.

 

About 1/3 down the page... is a pile of shader code... messy, but still quite steal-able.  :)

 

This project uses structures called jsm's (apparently).  It looks a bit strange, but interesting.  That's mostly irrelevant, but DO notice the many jsm modules AFTER the shaders...  with 'Type': ["Shader"].  With a little bit of bushwhacking... you can determine which shaders bind to which scene items/mats.

 

I don't know if answers to your questions can be gotten from that, but I thought I would show it to you.  Maybe none of them use positions... I haven't investigated them at all.  I am simply collecting shaders for when unicomp21 creates our new and exciting BabylonJS Shaders Tutorial!  YAY!  It will be featured in the little help menu at CYOS.  Yay!

 

Am I being pushy?  I hope so.  heh.  Ok, now back to our show.  :)

Link to comment
Share on other sites

Hey this is clear, but I think you may want to use custom materials instead of custom procedural textures. Procedural textures are more about generating a single texture and I'm wondering if you want to simply generate a texture and then use it with a material OR just develop your own material? (BTW custom material are far more flexible)

 

For custom material:http://doc.babylonjs.com/tutorials/15._Understanding_Shaders_with_Babylon.js_and_ShaderMaterial

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...