summaryrefslogtreecommitdiff
path: root/src/shaders/pbr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shaders/pbr.c')
-rw-r--r--src/shaders/pbr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/shaders/pbr.c b/src/shaders/pbr.c
index 6db3d68..666f758 100644
--- a/src/shaders/pbr.c
+++ b/src/shaders/pbr.c
@@ -15,7 +15,7 @@
#define _rough reg_num_00
#define _world_pos reg_v3_00
#define _depth_pos reg_v3_01
-#define _clip_pos reg_v4_00
+#define _clip_pos reg_v2_01
#define _world_normal reg_v3_02
#define _world_tangent reg_v3_03
#define _world_bitangent reg_v3_04
@@ -34,6 +34,8 @@ static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoor
//*rough = 1 - vec3_dot(&worldnormal, light);
//*vnormal = in->vertex->normal;
*_texcoord = in->vertex->texcoord;
+ _clip_pos->x = clipcoord->z;
+ _clip_pos->y = clipcoord->w;
}
static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color32* color) {
@@ -46,11 +48,15 @@ static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color32* col
//(*color).a = 1;
//return 1;
//float rough = 1- vec3_dot(&in->normal, light);
+ float depth = _clip_pos->x / _clip_pos->y;
+ depth = (depth + 1) / 2;
+ depth = linear01depth(depth);
Color32 c = tex2d(_albedo_tex, _texcoord);
//Color32 nc = tex2d(noramltex, in->texcoord);
//vec3_scale(&c, roughness, &c);
color32_saturate(&c);
*color = c;
+ vec3_scale(color, 1 - depth, color);
return 1;
}
@@ -64,5 +70,6 @@ Program ssr_built_in_shader_pbr = {
//VARYING_V3_04 |
//VARYING_V4_00 |
VARYING_V2_00 |
- VARYING_V3_05
+ VARYING_V3_05 |
+ VARYING_V2_01
};