diff options
Diffstat (limited to 'src/shaders/default.c')
-rw-r--r-- | src/shaders/default.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/src/shaders/default.c b/src/shaders/default.c index b1345e0..49a80d1 100644 --- a/src/shaders/default.c +++ b/src/shaders/default.c @@ -1,20 +1,51 @@ -#include "common_header.h" +#include "common.h" /*uniforms*/ -#define lightdir UV3(0) -#define shinees UN(0) +#define object2world UM4(0) +#define light UV3(0) +#define maintex UTEX(0) +#define noramltex UTEX(1) +#define roughnesstex UTEX(2) +#define metalnesstex UTEX(3) -/*vertex output*/ -#define uv reg_v2_00 +/*varyings*/ +#define rough reg_num_00 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* homocoord) { +static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { static Vec4 p; p.xyz = in->vertex->position; p.w = 1; - mat4_applytovec4(uniforms->mvp, &p, homocoord); + mat4_applytovec4(uniforms->mvp, &p, clipcoord); + Vec4 normal = { + in->vertex->normal.x, + in->vertex->normal.y, + in->vertex->normal.z, + 1 + }; + Vec4 worldnormal; mat4_applytovec4(object2world, &normal, &worldnormal); + vec3_normalize(light, light); + *reg_num_00 = 1 - vec3_dot(&worldnormal, light); } -static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color* color) { - +static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color32* color) { + vec3_normalize(light, light); + vec3_normalize(&in->normal, &in->normal); + float roughness = *reg_num_00; + //(*color).r = 1; + //(*color).g = 1; + //(*color).b = 1; + //(*color).a = 1; + //return 1; + //float rough = 1- vec3_dot(&in->normal, light); + Color32 c = tex2d(maintex, in->texcoord); + //Color32 nc = tex2d(noramltex, in->texcoord); + //vec3_scale(&c, roughness, &c); + color32_saturate(&c); + *color = c; return 1; } -Program ssr_built_in_shader_default = { vert, frag };
\ No newline at end of file +Program ssr_built_in_shader_default = { + vert, frag, + VARYING_TEXCOORD | + VARYING_NORMAL | + VARYING_NUM_00 +};
\ No newline at end of file |