Writing shaders and shadows

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By funkstar
:warning: Old Version Published before Godot 3 was released.

Just started to use Godot today, and the first thing I tried is writing a PBR shader. Crazy me!

This is what I have so far. Not quite there, but it’s a start.

I’m pretty sure reflections are not ok and they’re just a basic addition to albedo, this far. Cook-Torrance specular seems to be working fine, on the other hand.

The worst thing is that I’m not acoustomed to separate fragment from lighting part, and this is driving me crazy.

Now the questions (a lot):

Do I need to do a linear/gamma correction of the textures (they are sRGB)? When I do, it doesn’t look as expected.

For creating shadows, do I need to create a depth map, or can I get it somewhere and pass it as a uniform? How about shadow matrix? Could help a lot to have these as prebuilt uniforms.

I cannot access VAR1 and VAR2 varyings from the Lighting tab. I believe this is a temporary bug?

When accessing matrices, I cannot access values directly, as for instance:

INV_CAMERA_MATRIX.x.xyz

I have to do:

vec4 camMat1 = INV_CAMERA_MATRIX.x;
camMat1.xyz;

This would be a temporarily bug, as well, as I have seen it done in the documentation examples. right?

Thanks in advance. Looking forward for an improval on shader language documentation.

:bust_in_silhouette: Reply From: Calinou

Do I need to do a linear/gamma correction of the textures (they are sRGB)? When I do, it doesn’t look as expected.

Godot has a sRGB mode and supports high dynamic range. You can enable it in your WorldEnvironment. More information here.

Also, you should know that Godot 3.0 will have physically-based rendering out of the box, using OpenGL ES 3.0. But still, it’s a nice effort to implement PBR in OpenGL ES 2.0. :slight_smile: