summaryrefslogtreecommitdiff
path: root/src/shaders/unlit.c
blob: e5abdced1f3dd7f4a8a55f0a8bf55e77475ba148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "common.h"

/*uniforms*/
#define object2world UM4(0)
#define light        UV3(0)
#define maintex      UTEX(0)

/*varyings*/
#define rough reg_num_00

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, 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, Color32* color) {
	vec3_normalize(light, light);
	vec3_normalize(&in->normal, &in->normal);
	//float rough = 1- vec3_dot(&in->normal, light);
	float roughness = *reg_num_00;
	Color32 c = tex2d(maintex, in->texcoord);
	//vec3_scale(&c, roughness, &c);
	//color32_saturate(&c);
	*color = c;
	return 1;
}

Program ssr_built_in_shader_unlit = { 
	vert, frag,
	VARYING_TEXCOORD | 
	VARYING_NORMAL |
	VARYING_NUM_00
};