How to create effect of depth using fragment shader?

I have a plane mesh and I wanna create a effect of ball moving under the clothe. I have achieved the effect in vertex shader but it looks flat if you look directly from front. its more like a mesh basic material rn but i want some kind of shading to give a effect of ball being under the cloth, idk if i have explained it properly but you can look at this demo it might help you to understand the issue. are there any examples for this kinda effect? I tried using position in z directon to give different colors and create a effect but did not work. Please help!

Thanks

@Bojack
You can do this in fragment shader:
gl_FragColor = vec4(mix(color * 0.25, color, shadow),1.);

Bur for proper shadows, you have to compute normals in vertex shader to process them in fragment shader.

2 Likes

Yeah, this better than what I have tried. I want something to give me result like bumb map.
Something like this where it you can feel like there are bumps in this images just because of that color shading


Idk if that’s achievable without bumpmap

Why it’s not? You’re the master of your scene :slight_smile:
Example: Edit fiddle - JSFiddle - Code Playground
Picture:

Update: and if you want to rotate it somehow Edit fiddle - JSFiddle - Code Playground

3 Likes

Damn! You’re amazing :smile: