1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
#ifndef _MATERIAL_H
#define _MATERIAL_H
#include "graphics/grinternal.h"
#include "model/model.h"
#include <array>
enum class ComparisionFunction
{
Never,
Always,
Less,
Greater,
Equal,
NotEqual,
LessOrEqual,
GreaterOrEqual
};
enum class StencilOperation {
Keep,
Zero,
Replace,
Increment,
IncrementWrap,
Decrement,
DecrementWrap,
Invert
};
class material
{
public:
struct clip_plane
{
bool enabled;
vec3d normal;
vec3d position;
};
enum texture_type {
TEX_TYPE_NORMAL,
TEX_TYPE_XPARENT,
TEX_TYPE_AABITMAP,
TEX_TYPE_INTERFACE
};
struct StencilFunc {
ComparisionFunction compare = ComparisionFunction::Always;
int ref = 1;
uint32_t mask = 0xFFFFFFFF;
};
struct StencilOp {
StencilOperation stencilFailOperation = StencilOperation::Keep;
StencilOperation depthFailOperation = StencilOperation::Keep;
StencilOperation successOperation = StencilOperation::Keep;
};
static const size_t NUM_BUFFER_BLENDS = 8;
private:
shader_type Sdr_type;
int Texture_maps[TM_NUM_TYPES];
texture_type Tex_type;
clip_plane Clip_params;
int Texture_addressing;
gr_zbuffer_type Depth_mode;
gr_alpha_blend Blend_mode;
bool Has_buffer_blends = false;
std::array<gr_alpha_blend, NUM_BUFFER_BLENDS> Buffer_blend_mode;
bool Cull_mode;
int Fill_mode;
vec4 Clr;
float Clr_scale;
int Depth_bias;
bvec4 Color_mask;
bool Stencil_test = false;
uint32_t Stencil_mask = 0xFF;
StencilFunc Stencil_func;
StencilOp Front_stencil_op;
StencilOp Back_stencil_op;
protected:
void set_shader_type(shader_type init_sdr_type = SDR_TYPE_NONE);
public:
material();
int get_shader_handle() const;
// get_shader_flags should return a full set of all flags set for this shader
virtual uint get_shader_flags() const;
void set_texture_map(int tex_type, int texture_num);
int get_texture_map(int tex_type) const;
bool is_textured() const;
void set_texture_type(texture_type t_type);
int get_texture_type() const;
bool is_clipped() const;
void set_clip_plane(const vec3d &normal, const vec3d &position);
void set_clip_plane();
const clip_plane& get_clip_plane() const;
void set_texture_addressing(int addressing);
int get_texture_addressing() const;
void set_depth_mode(gr_zbuffer_type mode);
gr_zbuffer_type get_depth_mode() const;
void set_cull_mode(bool mode);
bool get_cull_mode() const;
void set_fill_mode(int mode);
int get_fill_mode() const;
void set_color_mask(bool red, bool green, bool blue, bool alpha);
const bvec4& get_color_mask() const;
void set_blend_mode(gr_alpha_blend mode);
void set_blend_mode(int buffer, gr_alpha_blend mode);
bool has_buffer_blend_modes() const;
gr_alpha_blend get_blend_mode(int buffer = 0) const;
void set_depth_bias(int bias);
int get_depth_bias() const;
void set_color(float red, float green, float blue, float alpha);
void set_color(int r, int g, int b, int a);
void set_color(const color &clr_in);
const vec4& get_color() const;
void set_color_scale(float scale);
float get_color_scale() const;
void set_stencil_test(bool stencil);
bool is_stencil_enabled() const;
void set_stencil_mask(uint32_t mask);
uint32_t get_stencil_mask() const;
void set_stencil_func(ComparisionFunction compare, int ref, uint32_t mask);
const StencilFunc& get_stencil_func() const;
void set_stencil_op(StencilOperation stencilFailOperation,
StencilOperation depthFailOperation,
StencilOperation successOperation);
void set_front_stencil_op(StencilOperation stencilFailOperation,
StencilOperation depthFailOperation,
StencilOperation successOperation);
const StencilOp& get_front_stencil_op() const;
void set_back_stencil_op(StencilOperation stencilFailOperation,
StencilOperation depthFailOperation,
StencilOperation successOperation);
const StencilOp& get_back_stencil_op() const;
};
class model_material : public material
{
public:
struct fog
{
bool enabled = false;
int r = 0;
int g = 0;
int b = 0;
float dist_near = -1.0f;
float dist_far = -1.0f;
};
private:
bool Desaturate = false;
bool Shadow_casting = false;
bool Shadow_receiving = false;
bool Batched = false;
bool Deferred = false;
bool HDR = false;
bool lighting = false;
float Light_factor = 1.0f;
int Center_alpha = 0;
int Animated_effect = -1;
float Animated_timer = 0.0f;
float Thrust_scale = -1.0f;
bool Team_color_set = false;
team_color Tm_color;
fog Fog_params;
float Outline_thickness = -1.0f;
bool Use_alpha_mult = false;
float Alpha_mult = 1.0f;
public:
model_material();
void set_desaturation(bool enabled);
bool is_desaturated() const;
void set_shadow_casting(bool enabled);
bool is_shadow_casting() const;
void set_shadow_receiving(bool enabled);
bool is_shadow_receiving() const;
void set_light_factor(float factor);
float get_light_factor() const;
void set_lighting(bool mode);
bool is_lit() const;
void set_deferred_lighting(bool enabled);
bool is_deferred() const;
void set_high_dynamic_range(bool enabled);
bool is_hdr() const;
void set_center_alpha(int center_alpha);
int get_center_alpha() const;
void set_thrust_scale(float scale = -1.0f);
float get_thrust_scale() const;
void set_team_color(const team_color &Team_clr);
void set_team_color();
const team_color& get_team_color() const;
bool is_team_color_set() const;
void set_animated_effect(int effect, float time);
void set_animated_effect();
int get_animated_effect() const;
float get_animated_effect_time() const;
void set_outline_thickness(float thickness = -1.0f);
float get_outline_thickness() const;
bool uses_thick_outlines() const;
void set_batching(bool enabled);
bool is_batched() const;
uint get_shader_flags() const override;
int get_shader_runtime_early_flags() const;
int get_shader_runtime_flags() const;
void set_fog(int r, int g, int b, float near, float far);
void set_fog();
bool is_fogged() const;
const fog& get_fog() const;
float get_alpha_mult() const;
bool is_alpha_mult_active() const;
void set_alpha_mult(float alpha);
void reset_alpha_mult();
};
class particle_material : public material
{
bool Point_sprite;
public:
particle_material();
void set_point_sprite_mode(bool enabled);
bool get_point_sprite_mode();
uint get_shader_flags() const override;
};
class distortion_material: public material
{
bool Thruster_render;
public:
distortion_material();
void set_thruster_rendering(bool enabled);
bool get_thruster_rendering();
};
class shield_material : public material
{
matrix Impact_orient;
vec3d Impact_pos;
float Impact_radius;
public:
shield_material();
void set_impact_transform(matrix &orient, vec3d &pos);
void set_impact_radius(float radius);
const matrix& get_impact_orient();
const vec3d& get_impact_pos();
float get_impact_radius();
};
class movie_material : public material {
int Ytex = -1;
int Utex = -1;
int Vtex = -1;
public:
movie_material();
int getYtex() const;
int getUtex() const;
int getVtex() const;
void setYtex(int _Ytex);
void setUtex(int _Utex);
void setVtex(int _Vtex);
};
class batched_bitmap_material : public material {
public:
batched_bitmap_material();
};
class nanovg_material : public material {
public:
nanovg_material();
};
class decal_material : public material {
public:
decal_material();
uint get_shader_flags() const override;
};
class interface_material : public material {
vec2d offset;
float horizontalSwipeOff = -1.0f;
public:
interface_material();
void set_offset(const vec2d& new_offset);
vec2d get_offset() const;
void set_horizontal_swipe(float hor_offset);
float get_horizontal_swipe() const;
};
gr_alpha_blend material_determine_blend_mode(int base_bitmap, bool is_transparent);
gr_zbuffer_type material_determine_depth_mode(bool depth_testing, bool is_transparent);
void material_set_interface(material* mat_info, int texture, bool blended, float alpha);
void material_set_rocket_interface(interface_material* mat_info,
int texture,
const vec2d& offset,
float horizontal_swipe);
void material_set_unlit(material* mat_info, int texture, float alpha, bool blending, bool depth_testing);
void material_set_unlit_emissive(material* mat_info, int texture, float alpha, float color_scale);
void material_set_unlit_color(material* mat_info, int texture, color *clr, bool blending, bool depth_testing);
void material_set_unlit_color(material* mat_info, int texture, color *clr, float alpha, bool blending, bool depth_testing);
void material_set_unlit_volume(particle_material* mat_info, int texture, bool point_sprites);
void material_set_distortion(distortion_material *mat_info, int texture, bool thruster);
void material_set_movie(movie_material *mat_info, int y_bm, int u_bm, int v_bm, float alpha = 1.0f);
void material_set_batched_bitmap(batched_bitmap_material* mat_info, int base_tex, float alpha, float color_scale);
void material_set_batched_opaque_bitmap(batched_bitmap_material* mat_info, int base_tex, float color_scale);
void material_set_nanovg(nanovg_material* mat_info, int base_tex);
void material_set_decal(material* mat_info, int diffuse_tex, int glow_tex, int normal_tex);
#endif
|