Make it look better

main
_ 2020-03-07 14:16:51 +00:00
parent 18da547bc5
commit 376b06abc3
4 changed files with 37 additions and 20 deletions

View File

@ -3,13 +3,13 @@
#define highp
#line 0
uniform lowp sampler2D uni_texture;
uniform lowp vec3 uni_object_space_light;
uniform lowp vec3 uni_min_bright;
uniform lowp vec3 uni_min_albedo;
varying lowp vec3 vary_color;
varying lowp vec3 vary_normal;
varying mediump vec2 vary_uv;
varying lowp vec3 vary_object_space_light;
void main (void) {
lowp vec3 normal = normalize (vary_normal);
@ -18,7 +18,7 @@ void main (void) {
lowp vec3 sky_color = pow (vec3 (42.0, 52.0, 109.0) / vec3 (255.0), vec3 (2.0));
lowp float sun_factor = dot (normal, uni_object_space_light);
lowp float sun_factor = dot (normal, vary_object_space_light);
lowp float sky_factor = normal.z;
lowp vec3 sun = max (sun_factor, 0.0) * (vec3 (1.0) - sky_color);

View File

@ -4,6 +4,7 @@
#line 0
uniform highp mat4 uni_mvp;
uniform lowp vec3 uni_albedo;
uniform lowp vec3 uni_object_space_light;
attribute highp vec4 attr_pos;
attribute mediump vec2 attr_uv;
@ -12,12 +13,14 @@ attribute lowp vec3 attr_normal;
varying lowp vec3 vary_color;
varying lowp vec3 vary_normal;
varying mediump vec2 vary_uv;
varying lowp vec3 vary_object_space_light;
void main (void) {
vary_uv = attr_uv;
vary_normal = attr_normal;
vary_color = uni_albedo * uni_albedo;
vary_object_space_light = normalize (uni_object_space_light);
gl_Position = uni_mvp * attr_pos;
}

View File

@ -6,13 +6,13 @@
uniform lowp float uni_dither_phase;
void main (void) {
lowp float dither_phase = uni_dither_phase;
lowp float dither_phase = 0.0;
dither_phase += 4.0 * mod (gl_FragCoord.y + 0.5, 4.0);
dither_phase += mod (gl_FragCoord.x + 0.5, 4.0);
dither_phase = mod (dither_phase, 16.0);
lowp float dither = 1.0;
if (dither_phase == 0.0) {
if (dither_phase == 0.0 || dither_phase == 10.0) {
dither = 0.0;
}

View File

@ -290,15 +290,10 @@ fn main () {
let proj_mat = Mat4::perspective_rh_gl (30.0f32.to_radians (), 1280.0 / 720.0, 0.5, 500.0);
let model_mat = Mat4::identity ();
Mat4::from_translation ((0.0, 0.0, 0.0).into ())
;
let shadow_model = {
let shadow_mat = {
let mut mat = Mat4::identity ();
mat.set_z_axis ((0.25, 0.125, 0.0, 0.0).into ());
mat * model_mat
mat
};
let view_mat = proj_mat *
@ -308,25 +303,29 @@ fn main () {
Mat4::from_translation ((0.0, 0.0, -2.7 * 0.5).into ())
;
let mvp_mat = view_mat * model_mat;
let shadow_mvp = view_mat * shadow_model;
let sky_mvp_mat = view_mat * Mat4::from_scale ((16.0, 16.0, 16.0).into ());
let light = Vec3::from ((2.0, 0.0, 5.0)).normalize ();
let object_space_light = model_mat.inverse () * Vec4::from ((light.x (), light.y (), light.z (), 0.0));
let object_space_light = Vec3::from ((object_space_light.x (), object_space_light.y (), object_space_light.z ()));
let orange = color_from_255 ((210.0, 125.0, 44.0));
let green = color_from_255 ((52.0, 101.0, 36.0));
let white = color_from_255 ((222.0, 238.0, 214.0));
let white = color_from_255 ((255.0, 255.0, 255.0));
let off_white = color_from_255 ((222.0, 238.0, 214.0));
let black = color_from_255 ((0.0, 0.0, 0.0));
let off_black = color_from_255 ((20.0, 12.0, 28.0));
glezz::clear_color (1.0f32, 1.0f32, 1.0f32, 1.0f32);
glezz::clear_color (1.0f32, 0.0f32, 1.0f32, 1.0f32);
glezz::clear (gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
glezz::enable (gl::CULL_FACE);
let pumpkin_model_mat =
Mat4::from_translation ((0.0, 0.0, 2.7 * 0.5).into ()) *
Mat4::from_scale ((0.125, 0.125, 0.125).into ()) *
Mat4::from_translation ((0.0, 0.0, -2.7 * 0.5).into ())
;
let world_model_mat = Mat4::identity ();
{
use uniforms::*;
@ -337,7 +336,11 @@ fn main () {
glezz::uniform_3fv (unis [&MIN_BRIGHT], &black);
glezz::uniform_3fv (unis [&MIN_ALBEDO], &white);
glezz::uniform_matrix_4fv (unis [&MVP], &mvp_mat);
let mvp = view_mat * pumpkin_model_mat;
glezz::uniform_matrix_4fv (unis [&MVP], &mvp);
let object_space_light = pumpkin_model_mat.inverse () * Vec4::from ((light.x (), light.y (), light.z (), 0.0));
let object_space_light = Vec3::from ((object_space_light.x (), object_space_light.y (), object_space_light.z ()));
glezz::uniform_3fv (unis [&OBJECT_SPACE_LIGHT], &object_space_light);
{
@ -348,6 +351,9 @@ fn main () {
renderable_model.draw (&attrs, 1);
}
let mvp = view_mat * world_model_mat;
glezz::uniform_matrix_4fv (unis [&MVP], &mvp);
{
for i in 0..renderable_pitch.num_meshes () {
glezz::uniform_3fv (unis [&ALBEDO], &pitch_colors [i]);
@ -357,6 +363,7 @@ fn main () {
let draw_sky = true;
if draw_sky {
glezz::front_face (gl::CCW);
glezz::uniform_matrix_4fv (unis [&MVP], &sky_mvp_mat);
glezz::uniform_3fv (unis [&ALBEDO], &white);
glezz::uniform_3fv (unis [&MIN_BRIGHT], &white);
@ -376,14 +383,21 @@ fn main () {
glezz::uniform_3fv (shadow_unis [&MIN_BRIGHT], &black);
glezz::uniform_3fv (shadow_unis [&MIN_ALBEDO], &white);
glezz::uniform_matrix_4fv (shadow_unis [&MVP], &shadow_mvp);
glezz::uniform_3fv (shadow_unis [&OBJECT_SPACE_LIGHT], &object_space_light);
let view_mat = view_mat * shadow_mat;
let mvp = view_mat * pumpkin_model_mat;
glezz::uniform_matrix_4fv (shadow_unis [&MVP], &mvp);
{
renderable_model.draw (&shadow_attrs, 0);
renderable_model.draw (&shadow_attrs, 1);
}
let mvp = view_mat * world_model_mat;
glezz::uniform_matrix_4fv (shadow_unis [&MVP], &mvp);
{
for i in 0..renderable_pitch.num_meshes () {
renderable_pitch.draw (&shadow_attrs, i);