Skip to content

Commit

Permalink
Fixed Cube Mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
orangeduck committed Feb 16, 2013
1 parent 5f6818c commit f101c7a
Show file tree
Hide file tree
Showing 26 changed files with 66 additions and 367,314 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,5 +6,6 @@ libcorange.a
*~
*.o
*.log
*.exe
stdout.txt
stderr.txt
Binary file added core_assets/resources/cube_field.dds
Binary file not shown.
Binary file modified core_assets/resources/sea.bmf
Binary file not shown.
Binary file modified core_assets/resources/skydome.bmf
Binary file not shown.
Binary file modified core_assets/resources/sphere.bmf
Binary file not shown.
6 changes: 2 additions & 4 deletions core_assets/shaders/deferred/compose.fs
Expand Up @@ -18,7 +18,7 @@ uniform sampler2D shadows_texture0;
uniform sampler2D shadows_texture1;
uniform sampler2D shadows_texture2;
uniform sampler2D ssao_texture;
uniform sampler2D env_texture;
uniform samplerCube env_texture;

uniform vec3 camera_position;

Expand Down Expand Up @@ -139,9 +139,7 @@ void main() {
(material == MAT_LEAF)) {

float env_factor = (material == MAT_REFLECT_MAJOR) ? 1.0 : 0.5;

vec3 reflected = normalize(reflect(eye_dir, normal));
vec3 env = texture2D(env_texture, vec2(reflected.x, -reflected.y)).rgb * ambient * env_factor * 3.0;
vec3 env = textureCube(env_texture, reflect(-eye_dir, normal)).rgb * ambient * env_factor * 5.0;
float env_amount = (1.0 - dot(eye_dir, normal)) * spec * env_factor * shadow;

diffuse = mix(diffuse, env, clamp(env_amount, 0.0, 0.5));
Expand Down
32 changes: 17 additions & 15 deletions core_assets/shaders/deferred/sea.fs
Expand Up @@ -7,7 +7,7 @@ uniform sampler2D bump2;
uniform sampler2D bump3;
uniform samplerCube cube_sea;

uniform vec4 bump_factor;
uniform float time;

uniform float light_power;
uniform vec3 light_direction;
Expand All @@ -18,8 +18,9 @@ uniform vec3 light_specular;
uniform float clip_near;
uniform float clip_far;

uniform vec3 camera_direction;
uniform vec3 camera_position;

varying vec3 fPosition;
varying vec2 fTexcoord;
varying vec3 fNormal;
varying vec4 fScreen;
Expand All @@ -40,38 +41,39 @@ void main() {

if (transparency == 0) { discard; }

vec4 bump0_norm = texture2D(bump0, fTexcoord);
vec4 bump1_norm = texture2D(bump1, fTexcoord);
vec4 bump2_norm = texture2D(bump2, fTexcoord);
vec4 bump3_norm = texture2D(bump3, fTexcoord);
vec4 bump0_norm = texture2D(bump0, (fTexcoord + time * 0.1 * vec2( 0.1, 0.11)) * 1.0);
vec4 bump1_norm = texture2D(bump1, (fTexcoord + time * 0.1 *vec2( 0.3, -0.91)) * 2.0);
vec4 bump2_norm = texture2D(bump2, (fTexcoord + time * 0.1 *vec2(-0.8, 0.02)) * 4.0);
vec4 bump3_norm = texture2D(bump3, (fTexcoord + time * 0.1 *vec2(-0.4, -0.61)) * 8.0);

vec3 bump =
(bump0_norm.xyz * bump_factor.r +
bump1_norm.xyz * bump_factor.g +
bump2_norm.xyz * bump_factor.b +
bump3_norm.xyz * bump_factor.a);
(bump0_norm.xyz * 0.33 +
bump1_norm.xyz * 0.33 +
bump2_norm.xyz * 0.16 +
bump3_norm.xyz * 0.16);

vec3 normal = normalize(fNormal + 0.1 * vec3(bump.x-0.5, 0, bump.y-0.5));
vec3 normal = normalize(fNormal + 1.0 * vec3(bump.x-0.5, 0, bump.y-0.5));

vec3 camera_direction = normalize(fPosition - camera_position);
vec3 light_half = normalize(light_direction + camera_direction);

float n_dot_l = max(dot(normal, light_direction), 0.0);
float n_dot_h = pow(max(dot(normal, light_half), 0.0), 1500);
float n_dot_h = pow(max(dot(normal, light_half), 0.0), 3000);
float n_dot_c = 1 - clamp(dot(normal, camera_direction), 0, 1);

float fresnel = 0.0204 + 0.9796 * (n_dot_c * n_dot_c * n_dot_c * n_dot_c * n_dot_c);

const vec3 albedo_sky = 0.1 * vec3(1.0, 4.0, 06.0);
const vec3 albedo_sky = 0.1 * vec3(1.0, 5.0, 7.00);
const vec3 albedo_down = 0.1 * vec3(1.0, 4.0, 06.0);
const vec3 albedo_up = 0.1 * vec3(1.0, 5.0, 7.00);
vec3 albedo = (0.1 * fresnel * albedo_sky) + mix( albedo_down, albedo_up, n_dot_c);
vec3 albedo = (0.25 * fresnel * albedo_sky) + mix( albedo_down, albedo_up, n_dot_c);

vec3 env = 1.0 * textureCube(cube_sea, reflect(camera_direction, normal)).rgb;
vec3 ambient = 2.0 * albedo * light_power * light_ambient;
vec3 specular = 100 * light_power * light_specular * n_dot_h;
vec3 diffuse = 0.5 * albedo * light_power * light_diffuse * n_dot_l;

diffuse = mix(diffuse, env, clamp(n_dot_c, 1.0, 1.0));
diffuse = mix(diffuse, env, clamp(n_dot_c, 0.4, 0.6));

gl_FragColor.rgb = diffuse + ambient + specular;
gl_FragColor.a = transparency;
Expand Down
6 changes: 4 additions & 2 deletions core_assets/shaders/deferred/sea.vs
Expand Up @@ -8,6 +8,7 @@ uniform mat4 view;
uniform mat4 proj;
uniform float time;

varying vec3 fPosition;
varying vec2 fTexcoord;
varying vec3 fNormal;
varying vec4 fScreen;
Expand All @@ -26,15 +27,16 @@ void main() {
vec4 world_pos = world * vec4(vPosition, 1);
world_pos = world_pos / world_pos.w;

fTexcoord = world_pos.xz * 0.3;
fPosition = world_pos.xyz;
fTexcoord = world_pos.xz * 0.1;

vec4 wave = vec4(0,0,0,0);
wave += 0.40 * spike_wave( normalize(vec2(1.00, 0.00)) , world_pos.xz * 0.912 + time * 3.211 , 3.30, 3 );
wave += 0.15 * spike_wave( normalize(vec2(1.00, 0.62)) , world_pos.xz * 0.932 + time * 2.971 , 2.85, 3 );
wave += 0.05 * spike_wave( normalize(vec2(0.41, 1.00)) , world_pos.xz * 1.112 + time * 3.314 , 3.21, 3 );
wave += 0.40 * spike_wave( normalize(vec2(0.10, 0.51)) , world_pos.xz * 1.321 + time * 2.823 , 4.12, 3 );

fNormal = vec3( 1 * wave.x, -1.0, 1 * wave.z);
fNormal = vec3( 0.3 * wave.x, -1.0, 0.3 * wave.z);
fScreen = proj * view * vec4(world_pos + wave);
gl_Position = fScreen;
}
Expand Down
4 changes: 2 additions & 2 deletions demos/noise/Makefile
Expand Up @@ -12,14 +12,14 @@ PLATFORM = $(shell uname)

ifeq ($(findstring Linux,$(PLATFORM)),Linux)
OUT=$(DEMO)
LFLAGS= $(LIBS) -lcorange -lGL -lSDLmain -lSDL
LFLAGS= $(LIBS) -lcorange -lGL -lSDLmain -lSDL -lSDL_net -lSDL_mixer
CORANGE= ./lib/libcorange.a
CORANGE_LIB= ../../libcorange.a
endif

ifeq ($(findstring Darwin,$(PLATFORM)),Darwin)
OUT=$(DEMO)
LFLAGS= $(LIBS) -lcorange -lGL -lSDLmain -lSDL
LFLAGS= $(LIBS) -lcorange -lGL -lSDLmain -lSDL -lSDL_net -lSDL_mixer
CORANGE= ./lib/libcorange.a
CORANGE_LIB= ../../libcorange.a
endif
Expand Down
Binary file removed demos/noise/SDL.dll
Binary file not shown.
7 changes: 5 additions & 2 deletions demos/noise/src/noise.c
Expand Up @@ -58,6 +58,7 @@ void noise_render() {
static bool currently_saving = false;
static int save_noise_to_file_thread(void* unused) {

/*
image* noise = perlin_noise_generate(512, 512, 8);
tga_save_file(noise, "./perlin_noise.tga");
debug("Noise saved as perlin_noise.tga");
Expand All @@ -70,13 +71,15 @@ static int save_noise_to_file_thread(void* unused) {
spinner_box->border_color = vec4_new(1,1,1,0);
currently_saving = false;
*/

return 0;
}

static SDL_Thread* save_thread = NULL;
static void save_noise_to_file(ui_button* b, SDL_Event event) {

/*
if (currently_saving) {
return;
}
Expand All @@ -100,6 +103,7 @@ static void save_noise_to_file(ui_button* b, SDL_Event event) {
}
}
*/

}

Expand All @@ -122,11 +126,10 @@ int main(int argc, char **argv) {
ui_button_set_label(info_button, "Procedural texture from perlin noise and feedback functions.");

ui_button* save_button = ui_elem_new("save_button", ui_button);
save_button->bottom_right = vec2_new(860, 35);
ui_button_move(save_button, vec2_new(480, 10));
ui_button_resize(save_button, vec2_new(380,25));
ui_button_set_label(save_button, "Click Here to save tileable perlin noise to file.");
ui_elem_add_event("save_button", save_noise_to_file);
//ui_elem_add_event("save_button", save_noise_to_file);

ui_rectangle* spinner_box = ui_elem_new("spinner_box", ui_rectangle);
spinner_box->color = vec4_black();
Expand Down
Binary file modified demos/sea/assets/corvette/corvette.bmf
Binary file not shown.

0 comments on commit f101c7a

Please sign in to comment.