Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ANARIRenderer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010 * RCS INFORMATION:
00011 *
00012 *      $RCSfile: ANARIRenderer.h,v $
00013 *      $Author: johns $      $Locker:  $               $State: Exp $
00014 *      $Revision: 1.14 $         $Date: 2021/10/29 06:04:51 $
00015 *
00016 ***************************************************************************/
00037 #ifndef LIBANARIRENDERER
00038 #define LIBANARIRENDERER
00039 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <anari/anari.h>
00043 #include "Matrix4.h"
00044 #include "ResizeArray.h"
00045 #include "WKFUtils.h"
00046 //#if !defined(ANARI_VERSION_MAJOR)
00047 //#include <anari/version.h>
00048 //#endif
00049 
00050 // Prevent interactive RT window code from being compiled when
00051 // VMD isn't compiled with an interactive GUI
00052 #if defined(VMDOPTIX_INTERACTIVE_OPENGL) && !defined(VMDOPENGL)
00053 #undef VMDOPTIX_INTERACTIVE_OPENGL
00054 #endif
00055 
00056 #if defined(VMDANARI_INTERACTIVE_OPENGL)
00057 #include "glwin.h"
00058 #endif
00059 
00061 typedef struct {
00062   ANARIMaterial mat;
00063   int isvalid;
00064   float ambient;
00065   float diffuse;
00066   float specular;
00067   float shininess;
00068   float reflectivity;
00069   float opacity;
00070   float outline;
00071   float outlinewidth;
00072   int transmode;
00073   int ind;
00074 } anr_material;
00075 
00076 typedef struct {
00077   float dir[3];
00078   float color[3];
00079 } anr_directional_light;
00080 
00081 typedef struct {
00082   float pos[3];
00083   float color[3];
00084 } anr_positional_light;
00085 
00086 
00087 typedef struct {
00088   int num;  
00089   float *v;
00090   float *n;
00091   float *c;
00092   int   *f;
00093   ANARIGeometry geom;
00094   ANARIArray1D verts;
00095   ANARIArray1D norms;
00096   ANARIArray1D cols;
00097   ANARIArray1D ind;
00098   ANARISurface surf;
00099   int matindex;
00100 } anr_trimesh_v3f_n3f_c3f;
00101 
00102 
00103 typedef struct {
00104   int num;  
00105   float *xyz;     // xyzr vec3
00106   float *radii;   // float
00107   float *colors;  // RGBA vec4
00108   ANARIGeometry geom;
00109   ANARIArray1D cents;
00110   ANARIArray1D rads;
00111   ANARIArray1D cols;
00112   ANARISurface surf;
00113   int matindex;
00114 } anr_sphere_array_color;
00115 
00116 
00117 typedef struct {
00118   int num;       // number of cylinders
00119   float *verts;  // point a, point b, 
00120   float *radii;  // radius
00121   float *colors; // rgba
00122   unsigned int *indices;
00123   ANARIGeometry geom;
00124   ANARIArray1D cyls;
00125   ANARIArray1D rads;
00126   ANARIArray1D cols;
00127   ANARIArray1D ind;
00128   ANARISurface surf;
00129   int matindex;
00130 } anr_cylinder_array_color;
00131 
00132 
00133 class ANARIRender {
00134 public: 
00135   // Use reverse rays by default rather than only when enabled interactively
00136   enum RtShadowMode { RT_SHADOWS_OFF=0,        
00137                       RT_SHADOWS_ON=1,         
00138                     };
00139   enum FogMode { RT_FOG_NONE=0, RT_FOG_LINEAR=1, RT_FOG_EXP=2, RT_FOG_EXP2=3 };
00140   enum CameraProjection { RT_PERSPECTIVE=0, 
00141                           RT_ORTHOGRAPHIC=1 
00142 // ,
00143 //                          RT_CUBEMAP=2,
00144 //                          RT_DOME_MASTER=3,
00145 //                          RT_EQUIRECTANGULAR=4,
00146 //                          RT_OCULUS_RIFT
00147                         };
00148   enum Verbosity { RT_VERB_MIN=0, RT_VERB_TIMING=1, RT_VERB_DEBUG=2 };
00149   enum BGMode { RT_BACKGROUND_TEXTURE_SOLID=0,
00150                 RT_BACKGROUND_TEXTURE_SKY_SPHERE=1,
00151                 RT_BACKGROUND_TEXTURE_SKY_ORTHO_PLANE=2 };
00152 
00153   enum Workarounds { ANARI_NONE=0, 
00154                      ANARI_OSPRAY=1, 
00155                      ANARI_OWL=2,
00156                      ANARI_NVGL=3,
00157                      ANARI_USD=4 
00158                    };
00159 
00160   enum RenderMode { ANARI_SCIVIS=0, 
00161                     ANARI_AO=1,
00162                     ANARI_PATHTRACER=2, 
00163                     ANARI_DEFAULT=3
00164                   };
00165 
00166   enum MaterialClass { ANARI_MATTE=0, 
00167                        ANARI_OBJ=1, 
00168                        ANARI_OTHER=2
00169                   };
00170 
00171 private:
00172   struct vec3 { float x, y, z; };
00173   struct rgba { float r, g, b, a; };
00174 
00175   struct Sphere {
00176     vec3  center;
00177     float radius;
00178     rgba  color;
00179     int   type;        //Material ID
00180   };
00181 
00182   int rendererworkarounds;                
00183 
00184   Verbosity verbose;                      
00185   int width;                              
00186   int height;                             
00187 
00188   wkf_timerhandle anr_timer;              
00189   double time_ctx_create;                 
00190   double time_ctx_setup;                  
00191   double time_ctx_validate;               
00192   double time_ctx_AS_build;               
00193   double time_ctx_destroy_scene;          
00194   double time_ray_tracing;                
00195   double time_image_io;                   
00196 
00197   // ANARI objects managed by VMD
00198   int context_created;                    
00199   RenderMode anari_rendermode;            
00200   MaterialClass anari_matclass;           
00201   ANARILibrary lib;                       
00202   ANARIDevice dev;                        
00203   ANARIRenderer anariRenderer;            
00204   ANARIWorld anariWorld;                  
00205   ResizeArray<ANARIInstance> anariInstances;  
00206 
00207   ResizeArray<ANARILight> anariLights;    
00208   ANARIArray1D anariLightData;               
00209   ANARICamera anariCamera;                
00210   ANARIFrame anariFrameBuffer;            
00211 
00212   int interactive_renderer;               
00213 
00214   int lasterror;                          
00215   int buffers_allocated;                  
00216   int headlight_enabled;                  
00217 
00218   char lastcommentstring[1024];           
00219   int seqgrp;                             
00220 
00221   float ao_ambient;                       
00222   float ao_direct;                        
00223 
00224   // cylinder array primitive
00225   long cylinder_array_cnt;                
00226 
00227   // color-per-cylinder array primitive
00228   long cylinder_array_color_cnt;          
00229 
00230   // color-per-ring array primitive
00231   long ring_array_color_cnt;              
00232 
00233   // sphere array primitive
00234   long sphere_array_cnt;                  
00235 
00236   // color-per-sphere array primitive
00237   long sphere_array_color_cnt;            
00238 
00239 
00240   // triangle mesh primitives of various types
00241   long tricolor_cnt;                      
00242   long trimesh_c4u_n3b_v3f_cnt;           
00243   long trimesh_n3b_v3f_cnt;               
00244   long trimesh_n3f_v3f_cnt;               
00245   long trimesh_v3f_cnt;                   
00246 
00247   // state variables to hold scene geometry
00248   int scene_created;
00249 
00250   //
00251   // ANARI shader state variables and the like
00252   //
00253 
00254   // shadow rendering mode 
00255   int shadows_enabled;                  
00256   float cam_zoom;                       
00257 
00258   float cam_stereo_eyesep;              
00259   float cam_stereo_convergence_dist;    
00260 
00261   int dof_enabled;                      
00262   float cam_dof_focal_dist;             
00263   float cam_dof_fnumber;                
00264 
00265   CameraProjection camera_projection;   
00266 
00267   int ext_aa_loops;                     
00268   int aa_samples;                       
00269   int ao_samples;                       
00270 
00271   // background color and/or gradient parameters
00272   BGMode scene_background_mode;         
00273   float scene_bg_color[3];              
00274   float scene_bg_grad_top[3];           
00275   float scene_bg_grad_bot[3];           
00276   float scene_gradient[3];              
00277   float scene_gradient_topval;          
00278   float scene_gradient_botval;          
00279   float scene_gradient_invrange;        
00280 
00281   // fog / depth cueing parameters
00282   int fog_mode;                         
00283   float fog_start;                      
00284   float fog_end;                        
00285   float fog_density;                    
00286 
00287   ResizeArray<anr_material> materialcache; 
00288 
00289   ResizeArray<anr_directional_light> directional_lights; 
00290   ResizeArray<anr_positional_light> positional_lights;   
00291 
00292   // keep track of all of the ANARI objects we create on-the-fly...
00293   int lastrepmesh;
00294   int lastrepspheres;
00295   int lastrepcyls;
00296 
00297   ResizeArray<anr_trimesh_v3f_n3f_c3f> trimesh_v3f_n3f_c3f;
00298   ResizeArray<anr_sphere_array_color> spheres_color;
00299   ResizeArray<anr_cylinder_array_color> cylinders_color;
00300   ResizeArray<ANARISurface *> surfbufs;
00301 
00302 public:
00303   static void ANARI_Global_Init(void);     
00304   static void ANARI_Global_Shutdown(void); 
00305 
00307   ANARIRender(void);
00308   ~ANARIRender(void);
00309 
00311   void check_verbose_env();
00312 
00314   void setup_context(int width, int height);
00315   
00317   void repanr_context_stats(void);
00318 
00320   void shadows_on(int onoff) { shadows_enabled = (onoff != 0); }
00321 
00323   void set_aa_samples(int cnt) { aa_samples = cnt; }
00324 
00326   void set_camera_projection(CameraProjection m) { camera_projection = m; }
00327 
00329   void set_camera_zoom(float zoomfactor) { cam_zoom = zoomfactor; }
00330 
00332   void set_camera_stereo_eyesep(float eyesep) { cam_stereo_eyesep = eyesep; }
00333   
00335   void set_camera_stereo_convergence_dist(float dist) {
00336     cam_stereo_convergence_dist = dist;
00337   }
00338 
00340   void dof_on(int onoff) { dof_enabled = (onoff != 0); }
00341 
00343   void set_camera_dof_focal_dist(float d) { cam_dof_focal_dist = d; }
00344 
00346   void set_camera_dof_fnumber(float n) { cam_dof_fnumber = n; }
00347 
00349   void set_ao_samples(int cnt) { ao_samples = cnt; }
00350 
00352   void set_ao_ambient(float aoa) { ao_ambient = aoa; }
00353 
00355   void set_ao_direct(float aod) { ao_direct = aod; }
00356 
00357   void set_bg_mode(BGMode m) { scene_background_mode = m; }
00358   void set_bg_color(float *rgb) { memcpy(scene_bg_color, rgb, sizeof(scene_bg_color)); }
00359   void set_bg_color_grad_top(float *rgb) { memcpy(scene_bg_grad_top, rgb, sizeof(scene_bg_grad_top)); }
00360   void set_bg_color_grad_bot(float *rgb) { memcpy(scene_bg_grad_bot, rgb, sizeof(scene_bg_grad_bot)); }
00361   void set_bg_gradient(float *vec) { memcpy(scene_gradient, vec, sizeof(scene_gradient)); }
00362   void set_bg_gradient_topval(float v) { scene_gradient_topval = v; }
00363   void set_bg_gradient_botval(float v) { scene_gradient_botval = v; }
00364 
00365   void set_cue_mode(FogMode mode, float start, float end, float density) {
00366     fog_mode = mode;
00367     fog_start = start;
00368     fog_end = end;
00369     fog_density = density;
00370   }
00371 
00372   void init_materials();
00373   void add_material(int matindex, float ambient, float diffuse,
00374                     float specular, float shininess, float reflectivity,
00375                     float opacity, float outline, float outlinewidth, 
00376                     int transmode);
00377   void set_material(ANARISurface &surf, int matindex, float *uniform_color);
00378   void attach_sphere_array(int numsp, int matindex,
00379                            anr_sphere_array_color &sparray);
00380   void attach_cylinder_array(int numcyl, int matindex,
00381                              anr_cylinder_array_color &cylarray);
00382   void attach_mesh(int numverts, int numfacets, int matindex,
00383                    anr_trimesh_v3f_n3f_c3f &mesh);
00384   void commit_rep();
00385 
00386 
00387   void clear_all_lights() { 
00388     headlight_enabled = 0;
00389     directional_lights.clear(); 
00390     positional_lights.clear(); 
00391   }
00392   void headlight_onoff(int onoff) { headlight_enabled = (onoff==1); };
00393   void add_directional_light(const float *dir, const float *color);
00394   void add_positional_light(const float *pos, const float *color);
00395 
00396   void update_rendering_state(int interactive);
00397 
00398   void framebuffer_config(int fbwidth, int fbheight);
00399   void framebuffer_resize(int fbwidth, int fbheight);
00400   void framebuffer_destroy(void);
00401 
00402   void render_compile_and_validate(void);
00403   void render_to_file(const char *filename); 
00404 #if defined(VMDANARI_INTERACTIVE_OPENGL)
00405   void render_to_glwin(const char *filename);
00406 #endif
00407 
00408   void destroy_scene(void);
00409 
00411   void comment(const char *);
00412 
00413 #if 1
00414   void cylinder_array(Matrix4 *wtrans, float rscale, float *uniform_color,
00415                       int cylnum, float *points, int matindex);
00416 #endif
00417 
00418   void cylinder_array_color(Matrix4 & wtrans, float rscale, int cylnum, 
00419                             float *points, float *radii, float *colors,
00420                             int matindex);
00421 
00422 #if 0
00423   void ring_array_color(Matrix4 & wtrans, float rscale, int rnum, 
00424                         float *centers, float *norms, float *radii, 
00425                         float *colors, int matindex);
00426 #endif
00427 
00428   void sphere_array(Matrix4 *wtrans, float rscale, float *uniform_color,
00429                     int spnum, float *centers, float *radii, int matindex);
00430 
00431   void sphere_array_color(Matrix4 & wtrans, float rscale, int spnum, 
00432                           float *centers, float *radii, float *colors, 
00433                           int matindex);
00434 
00435   void tricolor_list(Matrix4 & wtrans, int numtris, float *vnc, int matindex);
00436 
00437   void trimesh_c4n3v3(Matrix4 & wtrans, int numverts,
00438                       float *cnv, int numfacets, int * facets, int matindex);
00439 
00440   void trimesh_c4u_n3b_v3f(Matrix4 & wtrans, unsigned char *c, signed char *n, 
00441                            float *v, int numfacets, int matindex);
00442 
00443   void trimesh_c4u_n3f_v3f(Matrix4 & wtrans, unsigned char *c, 
00444                            float *n, float *v, int numfacets, int matindex);
00445 
00446   void trimesh_n3b_v3f(Matrix4 & wtrans, float *uniform_color, 
00447                        signed char *n, float *v, int numfacets, int matindex);
00448 
00449   void trimesh_n3f_v3f(Matrix4 & wtrans, float *uniform_color, 
00450                        float *n, float *v, int numfacets, int matindex);
00451 
00452 #if 0
00453   void trimesh_v3f(Matrix4 & wtrans, float *uniform_color, 
00454                    float *v, int numfacets, int matindex);
00455 #endif
00456 
00457   void tristrip(Matrix4 & wtrans, int numverts, const float * cnv,
00458                 int numstrips, const int *vertsperstrip,
00459                 const int *facets, int matindex);
00460 
00461 }; 
00462 
00463 #endif
00464 

Generated on Fri Oct 4 02:43:19 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002