diff options
author | chai <chaifix@163.com> | 2020-07-28 00:30:33 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-07-28 00:30:33 +0800 |
commit | 5dfdb6b58b2dc7bbd3348004c1fcd17e23fea48b (patch) | |
tree | a03f1a01382595ed50cc4780a728b22013f6d5a0 /src/shaders | |
parent | 690f20cdbe8dad3fce7a547934a5a8322303342d (diff) |
Diffstat (limited to 'src/shaders')
-rw-r--r-- | src/shaders/common/core.c | 10 | ||||
-rw-r--r-- | src/shaders/common/core.h | 18 | ||||
-rw-r--r-- | src/shaders/pbr.c | 26 |
3 files changed, 19 insertions, 35 deletions
diff --git a/src/shaders/common/core.c b/src/shaders/common/core.c index ffaa649..91bb6c0 100644 --- a/src/shaders/common/core.c +++ b/src/shaders/common/core.c @@ -4,7 +4,7 @@ Vec4 _proj_params; Vec2 _time; Vec4 _screen_params; -Vec3 unpacknormal(Color32 c32) { +Vec3 decode_normal(Color32 c32) { Vec3 normal = { c32.r * 2 - 1, c32.g * 2 - 1, @@ -15,16 +15,16 @@ Vec3 unpacknormal(Color32 c32) { Mat4 mat4(Vec4* c1, Vec4* c2, Vec4* c3, Vec4* c4); -Vec2 texsize(Texture* texture) { +Vec2 texture_size(Texture* texture) { Vec2 size = {texture->width, texture->height}; return size; } -float linear01Depth(float depth) { +float linear_01_depth(float depth) { float n = _proj_params.x, f = _proj_params.y; return n / ((n-f)*depth + f); } -float linearEyeDepth(float depth) { - return _proj_params.y * linear01Depth(depth); +float linear_eye_depth(float depth) { + return _proj_params.y * linear_01_depth(depth); }
\ No newline at end of file diff --git a/src/shaders/common/core.h b/src/shaders/common/core.h index ef58897..216af15 100644 --- a/src/shaders/common/core.h +++ b/src/shaders/common/core.h @@ -34,24 +34,24 @@ Vec4 _screen_params; /************************************************************************/ /*shader built in functions*/ -Vec3 unpacknormal(Color32 c32); +Vec3 decode_normal(Color32 c32); Mat4 mat4(Vec4* c1, Vec4* c2, Vec4* c3, Vec4* c4); Mat3 mat3(Vec3* c1, Vec3* c2, Vec3* c3); -Vec2 texsize(Texture* texture); +Vec2 texture_size(Texture* texture); #define discardif(cond) \ -do{ \ -if(cond) return 0; \ +do{ \ +if(cond) return 0; \ }while(0) #define discard() return 0 -#define keep() return 1 +#define put() return 1 #define MVP_PROCESS \ do{ \ -static Vec4 p; p.xyz = in->position; p.w = 1; \ -internal_mat4_mulvec4(g_uniforms->mvp, &p, clipcoord); \ +static Vec4 p; p.xyz = in->position; p.w = 1; \ +internal_mat4_mulvec4(g_uniforms->mvp, &p, clipcoord); \ }while(0) #define object2clip(pos, out) internal_mat4_mulvec4(_mvp_matrix, pos, out); @@ -66,7 +66,7 @@ out_v3->x = color.x * 2 - 1; \ out_v3->y = color.y * 2 - 1; \ out_v3->z = color.z * 2 - 1; -float linear01Depth(float depth); -float linearEyeDepth(float depth); +float linear_01_depth(float depth); +float linear_eye_depth(float depth); #endif
\ No newline at end of file diff --git a/src/shaders/pbr.c b/src/shaders/pbr.c index a917f95..9f148ee 100644 --- a/src/shaders/pbr.c +++ b/src/shaders/pbr.c @@ -24,46 +24,30 @@ static void vert( Vertex* in, Vec4* clipcoord) { object2clip(&p, clipcoord); Vec3 worldnormal = mat4_mulvec3(*_object2world, in->normal); worldnormal = vec3_normalize(worldnormal); - //*rough = 1 - internal_vec3_dot(&worldnormal, light); - //*vnormal = in->normal; *_texcoord = in->texcoord; _clip_pos->x = clipcoord->z; _clip_pos->y = clipcoord->w; } static bool frag( Vec4* color) { - //internal_vec3_normalize(light, light); - //internal_vec3_normalize(vnormal, vnormal); - //float roughness = *rough; - //(*color).r = 1; - //(*color).g = 1; - //(*color).b = 1; - //(*color).a = 1; - //return 1; - //float rough = 1- internal_vec3_dot(&in->normal, light); float depth = _clip_pos->x / _clip_pos->y; depth = (depth + 1) / 2; - depth = linear01Depth(depth); + depth = linear_01_depth(depth); Vec4 c = tex2d(_albedo_tex, _texcoord); - //Color32 nc = tex2d(noramltex, in->texcoord); - //internal_vec3_scale(&c, roughness, &c); *color = vec4_saturate(c); - //*color = vec4(1,1,1,1); - //*color = vec4(depth, depth, depth, 1); - //internal_vec3_scale(color, 1 - depth, color); - return 1; + put(); } Program ssr_built_in_shader_pbr = { vert, frag, - VARYING_NUM_00 | + //VARYING_NUM_00 | //VARYING_V3_00 | //VARYING_V3_01 | //VARYING_V3_02 | //VARYING_V3_03 | //VARYING_V3_04 | //VARYING_V4_00 | - VARYING_V2_00 | - VARYING_V3_05 | + VARYING_V2_00 | + //VARYING_V3_05 | VARYING_V2_01 }; |