Jump to content

Fun with Shaders and Maths


JohnK
 Share

Recommended Posts

Have been playing around with CYOS and shaders to see how the ground can be transformed into different shapes and came across these 3D equations on Ben Joffe's site, so played around with some on this playground

 

http://www.babylonjs-playground.com/#TWH8K#1

 

Thanks to DK for CYOS and the documentation.

 

Given the danger of teaching my Grandmother to suck eggs I will still go ahead and state some obvious things:-

 

1. about the PG

 

Lines 31, 32 and 33 in the PG contain the functions to determine the height of the ground (v.y) based on the x and z positions on the ground. Comment any two of these out or replace with your own function.

 

Line 34 sets the movement within the shader comment out to stop this.

 

You can see just the effect the shader has on the height of the ground by swapping which of lines 82 and 83 are commented out. (Just using CreateGround is less fun than CreateGroundFromHeightMap imho.)

 

2. I learnt about shaders

 

When writing the functions in the BABYLON.Effect.ShadersStore["customVertexShader"]

 

  • Do not use integers, ie write 2.0 not 2
  • Maths functions are not methods of a Math object as in JS so write sin not Math.sin

The available maths function can be found on page 11 of this OpenGL pdf document

 

Enjoy

Link to comment
Share on other sites

Hi John, 

 

For me, shaders are really complex and difficult to understand. However, I did give it a try several month ago, and I did these below. Maybe it will be useful for someone (but I really doubt it :) )

 

cross-stitch : http://www.babylonjs.com/cyos/#1G3RU

 

Colorify : http://www.babylonjs.com/cyos/#USC12

 

Lens post-process: http://www.babylonjs-playground.com/#EKICU#2

 

Bleach : http://www.babylonjs.com/cyos/#LIMKT

Link to comment
Share on other sites

Given the danger of teaching my Grandmother to suck eggs

 

hahahaha.  I had to go to the dictionary of comedy with that one.  No entry.  hmm.

 

"Tie shoes" or "sweep floors"... those were in the dictionary... but not "suck eggs".  :D  That blew everyone's mind!

 

Thanks for the info/demos about coding shaders, you guys.

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