/* * Copyright © 2009 Eric Anholt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * Authors: * Eric Anholt * */ #define GL_GLEXT_PROTOTYPES #include #include struct revolved_object { GLuint vbo, array_obj, shadow_array_obj; int pos_offset, norm_offset, tangent_offset, texcoord_offset; int elements_offset, elements_vert_stride; int num_verts, num_steps; /* Maximum distance from center of revolution to a vertex. */ float radius; }; enum uniform_list { UNIFORM_MV, UNIFORM_MVP, UNIFORM_LIGHT_MVP, UNIFORM_LIGHT_EYE, UNIFORM_NORMAL_SAMPLER, UNIFORM_HEIGHTMAP_SAMPLER, UNIFORM_SHADOW_SAMPLER, UNIFORM_NI, UNIFORM_F0, UNIFORM_WARD_MM_INV, UNIFORM_WARD_MN_INV, UNIFORM_WARD_NN_INV, UNIFORM_MAX }; enum ground_uniform_list { GROUND_UNIFORM_MV, GROUND_UNIFORM_MVP, GROUND_UNIFORM_LIGHT_EYE, GROUND_UNIFORM_LIGHT_MVP, GROUND_UNIFORM_SHADOW_SAMPLER, GROUND_UNIFORM_MAX }; enum shadow_uniform_list { SHADOW_UNIFORM_MVP, SHADOW_UNIFORM_MAX }; struct uniform_desc { const char *name; GLint location; }; #define NUM_RINGS 27 extern struct uniform_desc uniforms[UNIFORM_MAX]; extern struct uniform_desc ground_uniforms[GROUND_UNIFORM_MAX]; extern struct uniform_desc shadow_uniforms[SHADOW_UNIFORM_MAX]; extern GLuint glass_prog, ground_prog, shadow_prog; extern GLUmat4 projection; extern GLUmat4 world_to_eye, world_to_shadow_texcoords; extern GLUvec4 light_world, light_eye; extern GLUmat4 ring_obj_to_world[NUM_RINGS]; extern struct revolved_object ring; extern GLUvec4 ring_bounding_sphere_center_world; extern float ring_bounding_sphere_radius; extern GLuint shadow_tex; extern GLUmat4 world_to_light_ndc; extern int no_multi_draw_arrays; void do_ring_drawelements(void); /* matrix.c */ void mult_m4_p4(float *result, const float *mat4, const float *point4); void mult_m4_m4(float *result, const float *a4, const float *b4); void init_m4_x_rotate(float *mat4, float x_rads); void init_m4_y_rotate(float *mat4, float y_rads); void init_m4_z_rotate(float *mat4, float z_rads); void init_m4_translate(float *mat4, float x, float y, float z); void init_m4_perspective(float *mat4, float fovy, float aspect, float near, float far); void print_m4(const float *mat4, const char *name); void print_GLUvec4(char *desc, const GLUvec4 *vec); void print_GLUmat4(char *desc, const GLUmat4 *m); void make_sphere_frustum(GLUmat4 *mat, GLUvec4 *center, float radius); /* load_texture.c */ GLuint load_texture_rgb(const char *filename); /* ground.c */ void draw_ground(void); void setup_ground(void); /* rings.c */ void draw_rings(void); void update_brdf_constants(void); void setup_rings(void); /* shadow_map.c */ void generate_rings_shadowmap(void);