Fermat
MeshView.h
1 /*
2  * Fermat
3  *
4  * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #pragma once
31 
32 #include <texture_reference.h>
33 
36 
39 
40 #ifndef SUTILCLASSAPI
41 #define SUTILCLASSAPI
42 #endif
43 
44 #ifndef SUTILAPI
45 #define SUTILAPI
46 #endif
47 
48 #define TEX_COORD_COMPRESSION_FIXED 0
49 #define TEX_COORD_COMPRESSION_HALF 1
50 #define TEX_COORD_COMPRESSION_MODE TEX_COORD_COMPRESSION_HALF
51 
55 struct SUTILCLASSAPI MeshMaterial
56 {
57  float4 diffuse;
58  float4 diffuse_trans;
59  float4 ambient;
60  float4 specular;
61  float4 emissive;
62  float4 reflectivity;
63  float roughness;
64  float index_of_refraction;
65  float opacity;
66  int flags;
67 
68  TextureReference ambient_map;
69  TextureReference diffuse_map;
70  TextureReference diffuse_trans_map;
71  TextureReference specular_map;
72  TextureReference emissive_map;
73  TextureReference bump_map;
74 
75  FERMAT_HOST_DEVICE
76  static MeshMaterial zero_material()
77  {
78  MeshMaterial material;
79  material.diffuse = make_float4(0.0f,0.0f,0.0f,0.0f);
80  material.diffuse_trans = make_float4(0.0f,0.0f,0.0f,0.0f);
81  material.ambient = make_float4(0.0f,0.0f,0.0f,0.0f);
82  material.specular = make_float4(0.0f,0.0f,0.0f,0.0f);
83  material.emissive = make_float4(0.0f,0.0f,0.0f,0.0f);
84  material.reflectivity = make_float4(0.0f,0.0f,0.0f,0.0f);
85  material.roughness = 0.0f;
86  material.index_of_refraction = 1.0f;
87  material.opacity = 1.0f;
88  material.flags = 0;
89  return material;
90  }
91 };
92 
96 struct SUTILCLASSAPI MeshView
97 {
98  static const uint32 VERTEX_TRIANGLE_SIZE = 4;
99  static const uint32 NORMAL_TRIANGLE_SIZE = 4;
100  static const uint32 TEXTURE_TRIANGLE_SIZE = 4;
101  static const uint32 LIGHTMAP_TRIANGLE_SIZE = 4;
102 
103  typedef int4 vertex_triangle;
104  typedef int4 normal_triangle;
105  typedef int4 texture_triangle;
106  typedef int4 lightmap_triangle;
107 
108  typedef float4 vertex_type;
109  typedef float3 normal_type;
110  typedef float2 texture_coord_type;
111 
112  int num_vertices;
113  int num_normals;
114  int num_texture_coordinates;
115  int num_triangles;
116  int num_groups;
117  int num_materials;
118 
119  int vertex_stride;
120  int normal_stride;
121  int texture_stride;
122  //int padding;
123 
124  float2 tex_bias;
125  float2 tex_scale;
126  float2 lm_bias;
127  float2 lm_scale;
128 
129  int* vertex_indices;
130  int* normal_indices;
131  int* normal_indices_comp;
132  int* material_indices;
133  int* texture_indices;
134  int* texture_indices_comp;
135  int* group_offsets;
136  float* vertex_data;
137  float* normal_data;
138  uint32* normal_data_comp;
139  float* texture_data;
140  int* lightmap_indices;
141  int* lightmap_indices_comp;
142  float* lightmap_data;
143 
144  MeshMaterial* materials;
145 };
146 
149 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
150 const MeshView::vertex_type& fetch_vertex(const MeshView& mesh, const uint32 vert_idx)
151 {
152  return reinterpret_cast<const MeshView::vertex_type*>(mesh.vertex_data)[vert_idx];
153 }
154 
157 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
158 const MeshView::normal_type& fetch_normal(const MeshView& mesh, const uint32 vert_idx)
159 {
160  return reinterpret_cast<const MeshView::normal_type*>(mesh.normal_data)[vert_idx];
161 }
162 
165 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
166 const MeshView::texture_coord_type& fetch_tex_coord(const MeshView& mesh, const uint32 vert_idx)
167 {
168  return reinterpret_cast<const MeshView::texture_coord_type*>(mesh.texture_data)[vert_idx];
169 }
170 
Definition: texture_reference.h:41
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE const MeshView::normal_type & fetch_normal(const MeshView &mesh, const uint32 vert_idx)
Definition: MeshView.h:158
Definition: MeshView.h:55
Definition: MeshView.h:96
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE const MeshView::vertex_type & fetch_vertex(const MeshView &mesh, const uint32 vert_idx)
Definition: MeshView.h:150
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE const MeshView::texture_coord_type & fetch_tex_coord(const MeshView &mesh, const uint32 vert_idx)
Definition: MeshView.h:166