static t_col shoot_ray(t_ray ray, int level_max, t_env *env) { float coef; float t; coef = 1.0; while (coef > 0.0f && level_max--) { t = 20000.0f; get_intersections(env, ray, &t); if (OBJ.cur_sphere != -1) set_val_sphere(env, t, ray); else if (OBJ.cur_tri != -1) set_val_tri(env, t, ray); else if (OBJ.cur_cyl != -1) set_val_cyl(env, t, ray); else if (OBJ.cur_cone != -1) set_val_cone(env, t, ray); else break ; if (env->br == 1) break ; calc_lighting(env, coef); coef *= OBJ.cur_mat.reflection; reflect_ray(env, &ray); } return (OBJ.col); }
void xrMU_Model::calc_lighting () { // BB Fbox BB; BB.invalidate (); for (v_vertices_it vit=m_vertices.begin(); vit!=m_vertices.end(); vit++) BB.modify ((*vit)->P); // Export CForm CDB::CollectorPacked CL (BB,(u32)m_vertices.size(),(u32)m_faces.size()); export_cform_rcast (CL,Fidentity); CDB::MODEL* M = xr_new<CDB::MODEL> (); M->build (CL.getV(),(u32)CL.getVS(),CL.getT(),(u32)CL.getTS()); calc_lighting (color,Fidentity,M,inlc_global_data()->L_static(),LP_dont_rgb+LP_dont_sun); xr_delete (M); clMsg ("model '%s' - REF_lighted.",*m_name); }
//#define TETRAHEDRON void glsl_R_DrawAlias (void) { #ifdef TETRAHEDRON static aliasvrt_t debug_verts[] = { {{ 0, 0}, {-18918,-18918,-18918}, { 0, 0, 0}}, {{ 0,300}, { 18918, 18918,-18918}, {255,255, 0}}, {{300,300}, {-18918, 18918, 18918}, { 0,255,255}}, {{300, 0}, { 18918,-18918, 18918}, {255, 0,255}}, }; static GLushort debug_indices[] = { 0, 1, 2, 0, 3, 1, 1, 3, 2, 0, 2, 3, }; #endif static quat_t color = { 1, 1, 1, 1}; static vec3_t lightvec; float ambient; float shadelight; float skin_size[2]; float blend; entity_t *ent = currententity; model_t *model = ent->model; aliashdr_t *hdr; vec_t norm_mat[9]; mat4_t mvp_mat; int skin_tex; int colormap; aliasvrt_t *pose1 = 0; // VBO's are null based aliasvrt_t *pose2 = 0; // VBO's are null based if (!(hdr = model->aliashdr)) hdr = Cache_Get (&model->cache); calc_lighting (ent, &ambient, &shadelight, lightvec); // we need only the rotation for normals. VectorCopy (ent->transform + 0, norm_mat + 0); VectorCopy (ent->transform + 4, norm_mat + 3); VectorCopy (ent->transform + 8, norm_mat + 6); // ent model scaling and offset Mat4Zero (mvp_mat); mvp_mat[0] = hdr->mdl.scale[0]; mvp_mat[5] = hdr->mdl.scale[1]; mvp_mat[10] = hdr->mdl.scale[2]; mvp_mat[15] = 1; VectorCopy (hdr->mdl.scale_origin, mvp_mat + 12); Mat4Mult (ent->transform, mvp_mat, mvp_mat); Mat4Mult (alias_vp, mvp_mat, mvp_mat); colormap = glsl_colormap; if (ent->skin && ent->skin->auxtex) colormap = ent->skin->auxtex; if (ent->skin && ent->skin->texnum) { skin_t *skin = ent->skin; skin_tex = skin->texnum; } else { maliasskindesc_t *skindesc; skindesc = R_AliasGetSkindesc (ent->skinnum, hdr); skin_tex = skindesc->texnum; } blend = R_AliasGetLerpedFrames (ent, hdr); pose1 += ent->pose1 * hdr->poseverts; pose2 += ent->pose2 * hdr->poseverts; skin_size[0] = hdr->mdl.skinwidth; skin_size[1] = hdr->mdl.skinheight; qfeglActiveTexture (GL_TEXTURE0 + 1); qfeglBindTexture (GL_TEXTURE_2D, colormap); qfeglActiveTexture (GL_TEXTURE0 + 0); qfeglBindTexture (GL_TEXTURE_2D, skin_tex); #ifndef TETRAHEDRON qfeglBindBuffer (GL_ARRAY_BUFFER, hdr->posedata); qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, hdr->commands); #endif qfeglVertexAttrib4fv (quake_mdl.colora.location, color); qfeglVertexAttrib4fv (quake_mdl.colorb.location, color); qfeglUniform1f (quake_mdl.blend.location, blend); qfeglUniform1f (quake_mdl.ambient.location, ambient); qfeglUniform1f (quake_mdl.shadelight.location, shadelight); qfeglUniform3fv (quake_mdl.lightvec.location, 1, lightvec); qfeglUniform2fv (quake_mdl.skin_size.location, 1, skin_size); qfeglUniformMatrix4fv (quake_mdl.mvp_matrix.location, 1, false, mvp_mat); qfeglUniformMatrix3fv (quake_mdl.norm_matrix.location, 1, false, norm_mat); #ifndef TETRAHEDRON set_arrays (&quake_mdl.vertexa, &quake_mdl.normala, &quake_mdl.sta, pose1); set_arrays (&quake_mdl.vertexb, &quake_mdl.normalb, &quake_mdl.stb, pose2); qfeglDrawElements (GL_TRIANGLES, 3 * hdr->mdl.numtris, GL_UNSIGNED_SHORT, 0); #else set_arrays (&quake_mdl.vertexa, &quake_mdl.normala, &quake_mdl.sta, debug_verts); set_arrays (&quake_mdl.vertexb, &quake_mdl.normalb, &quake_mdl.stb, debug_verts); qfeglDrawElements (GL_TRIANGLES, sizeof (debug_indices) / sizeof (debug_indices[0]), GL_UNSIGNED_SHORT, debug_indices); #endif if (!model->aliashdr) Cache_Release (&model->cache); }