Glass Material without Texture

Is it possible to create a glass effect without having either a texture or using reflection?
Basically a shiny sphere that is transparent.

Use-case: Just having a very basic glass. Like in older games.

1 Like

Welcome on board! :slight_smile:
What about this example:



Two very different but working solutions, thank you so much! :hugs::hugs::hugs:

@nasimiasl is that the appropriate way of writing a shader or is it more of a quick-fix solution? Just so I know for future code, because it looks different than what I find in the docs about shaders.

if you like i can explain it

you most use min(1. ,max(0. , … )) for keep value in correct range

for calculate Fresnel :
1. - dot( normal , normalize(( camera ) - world position ))

so that explain all this line
float fs = min(1.,max(0.,1.-pow(dot(vNormalW,normalize(( vEyePosition) - vPositionW)),1.0)));

for have the reflection we have 2 kind of method
first is reflect and second is refract
in this code i calculate a reflact value by 2 direction
camera and {100,100,100 }
i attach some mathematical code for have dark and light on the refract
**sin(length(f1*0.1)1.2+min( (f1.y+(abs(f1.x))),min(sin(f1.y),cos(0.01f1.x)))0.5+1.5 )0.5;
you can change that and have different result

now for make reality light effect just need a bit specular
pow( a , 2 ) *2. ( make light more ) if you use pow( a , 50.)*60. that make it point light
if we use pow(a , 0.5)*0.5 that keep around light effect too

  l1 = pow(l1,5.)+   pow(l2*0.83+(1.-fs),12.)*0.5;
  l2 = pow(l1,33.)*58. + pow(l1,0.6)*0.8;
  l2 = (pow(l2,33.)*58. + pow(l2,0.6)*0.8)*0.5+l1*.5;

the finalize step you can choose your color and attach light for that

vec3(1.)*l2 + and select l2 as transparency

it is customMaterial that help you have all shadow and fog and other standard material settings


Hi @schoening and welcome to the forum from me. You should know that nasimiasl is a shader genius and, I believe, the author of CustomMaterial - Babylon.js Documentation. Using custommaterial is an alternative to the standard way described in the docs. If you have a good understanding of shaders, and I don’t, then custommaterial gives you a direct way of using their power in Babylon.js.


I also need to mention the new Node material editor :slight_smile:


@nasimiasl thanks for the explanation, bit over my head but in time it’ll make sense :grin:

@JohnK thank you, and yeah, while I was browsing for answers I did get the impression that he is that :stuck_out_tongue: Shaders are a bit out of scope for me at the moment, good to have so many clever people here to learn from :smile:

@Deltakosh thanks! Looks impressive!

1 Like

This is dated but I was looking for the same thing. Found this PG great: It looks nice in the PG but was not working with my scene’s lighting. I ended up with something this: Note that these are really simple materials but they might be good enough depending on what you need.

Hope this will be useful to the next person :slight_smile: