VOXELRENDER: reduced position varying to vec3

Martin Gerhardy 2019-11-26 18:40:50 +01:00
parent aa88152251
commit 18c8c53a7b
2 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,4 @@
$in vec4 v_pos;
$in vec3 v_pos;
$in vec4 v_color;
$in float v_ambientocclusion;
uniform mat4 u_viewprojection;
@ -12,13 +12,13 @@ uniform lowp vec3 u_ambient_color;
$out vec4 o_color;
void main(void) {
vec3 fdx = dFdx(v_pos.xyz);
vec3 fdy = dFdy(v_pos.xyz);
vec3 fdx = dFdx(v_pos);
vec3 fdy = dFdy(v_pos);
vec3 normal = normalize(cross(fdx, fdy));
float ndotl1 = dot(normal, u_lightdir);
float ndotl2 = dot(normal, -u_lightdir);
vec3 diffuse = u_diffuse_color * max(0.0, max(ndotl1, ndotl2));
vec3 shadowColor = shadow(u_viewprojection, v_color.rgb, diffuse, u_ambient_color);
vec3 linearColor = shadowColor * v_ambientocclusion;
o_color = fog(v_pos.xyz, linearColor, v_color.a);
o_color = fog(v_pos, linearColor, v_color.a);
}

View File

@ -20,7 +20,7 @@ layout(std140) uniform u_materialblock {
vec4 u_materialcolor[MATERIALCOLORS];
};
$out vec4 v_pos;
$out vec3 v_pos;
$out vec4 v_color;
$out float v_ambientocclusion;
@ -33,14 +33,15 @@ void main(void) {
uint a_colorindex = a_info[1];
uint a_material = a_info[2];
#ifdef INSTANCED
v_pos = vec4(a_offset, 0.0) + u_model * vec4(a_pos, 1.0);
vec4 pos = vec4(a_offset, 0.0) + u_model * vec4(a_pos, 1.0);
#else // INSTANCED
v_pos = u_model * vec4(a_pos, 1.0);
vec4 pos = u_model * vec4(a_pos, 1.0);
#endif // INSTANCED
v_pos = pos.xyz;
int materialColorIndex = int(a_colorindex) + materialoffset;
vec3 materialColor = u_materialcolor[materialColorIndex % MATERIALCOLORS].rgb;
vec3 colornoise = texture(u_texture, abs(v_pos.xz) / 256.0 / 10.0).rgb;
vec3 colornoise = texture(u_texture, abs(pos.xz) / 256.0 / 10.0).rgb;
float alpha = u_materialcolor[a_colorindex].a;
// TODO: use $constant to check this magic number with the code
if (a_material == 1u) {
@ -51,9 +52,9 @@ void main(void) {
v_ambientocclusion = aovalues[a_ao];
#if cl_shadowmap == 1
v_lightspacepos = v_pos.xyz;
v_lightspacepos = v_pos;
v_viewz = (u_viewprojection * vec4(v_lightspacepos, 1.0)).w;
#endif // cl_shadowmap
gl_Position = u_viewprojection * v_pos;
gl_Position = u_viewprojection * pos;
}