Jump to content

[shader] Internal reflection / intersection with geometry given a point and a vector


MinZe
 Share

Recommended Posts

Hi, I want to do an internal reflection shader, and I need to check two things:

1. Check if with a given point, vector and maximum distance there is a face of my geometry in which the vector intersects with.

2. the face's normal.

Is there a way to do this?

Thanks.

Link to comment
Share on other sites

#1. https://doc.babylonjs.com/babylon101/raycasts

var ray = new BABYLON.Ray(origin, direction, length);
var hit = scene.pickWithRay(ray);

You may need to do a multipick, if you want to go past meshes occluding.

#2.  I think you need to use the hit.faceId to get the normal of the face.  The normal of the hit is, I think, for the ray.

var normal = pickInfo.getNormal(...);

edit: Welcome to the forum!

Link to comment
Share on other sites

I've only used the reflection probe:
https://doc.babylonjs.com/how_to/how_to_use_reflection_probes

That's generating a reflection cube map texture.  With just a point, vector, and normal (reflection angle) - you still need to account for other light sources and shadows as well. There are some shader gurus in the forum, but it would be helpful if you had a playground.

Link to comment
Share on other sites

Thanks! generating a cubemap in realtime it's something that I needed too!

For the intersection with geometry, I think that If I pass the array of the geometry to the shader I can calculate the intersection between a point with a vector and a plane.

But If someone knows any method to do it, feel free to post it, as It's gonna help for sure.

Link to comment
Share on other sites

for step 1 : i just can make fake inner reflect ( i don't calculate inner position for yet )

so i use this pic

XmwL004.png

** if we can make some  real image from inside and make dark and white face ( calculate by normal direction )   we can close to real

for step 2 : make refract from this pic

http://www.babylonjs-playground.com/#7AIII8#45

step 3 : make reflect from last refract ( like 2 reflect  notice in real diamond we have infinity reflact but we do just some level)

https://www.babylonjs-playground.com/#7AIII8#46

step 4 : broke refract with  last result and use main environment map 

https://www.babylonjs-playground.com/#7AIII8#47

sdfsdfsdfs.thumb.jpeg.f35a723e914146283e400ea51439246e.jpeg

it is starter solution for make diamond  

add specular reflect 

https://www.babylonjs-playground.com/#7AIII8#48

 

 

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