Pixel-Composer/scripts/d3d_material/d3d_material.gml

87 lines
1.8 KiB
Plaintext
Raw Normal View History

2023-08-24 11:59:05 +02:00
function __d3dMaterial(surface = noone) constructor {
self.surface = surface;
2023-08-24 19:44:12 +02:00
2023-10-08 04:14:35 +02:00
diffuse = 1;
specular = 0;
metalic = false;
shine = 1;
2024-10-05 02:49:33 +02:00
texScale = [ 1, 1 ];
texShift = [ 0, 0 ];
2023-10-08 04:14:35 +02:00
normal = noone;
normalStr = 1;
2023-08-24 19:44:12 +02:00
2023-10-08 04:14:35 +02:00
reflective = 0;
texFilter = false;
2023-08-24 19:44:12 +02:00
static getTexture = function() {
if(!is_surface(surface)) return -1;
return surface_get_texture(surface);
}
2023-08-24 19:44:12 +02:00
2023-08-30 16:40:45 +02:00
static submitGeometry = function() {
shader_set_i("use_normal", is_surface(normal));
shader_set_surface("normal_map", normal);
shader_set_f("normal_strength", normalStr);
}
2023-08-24 19:44:12 +02:00
static submitShader = function() {
shader_set_f("mat_diffuse", diffuse );
shader_set_f("mat_specular", specular );
shader_set_f("mat_shine", shine );
shader_set_i("mat_metalic", metalic );
2024-10-05 02:49:33 +02:00
shader_set_f("mat_texScale", texScale );
shader_set_f("mat_texShift", texShift );
2023-08-24 19:44:12 +02:00
shader_set_f("mat_reflective", reflective);
2023-10-08 04:14:35 +02:00
gpu_set_tex_filter(texFilter);
}
2024-04-08 07:13:46 +02:00
static clone = function(replaceSurface = surface) {
var _mat = new __d3dMaterial(replaceSurface);
2023-10-08 04:14:35 +02:00
_mat.diffuse = diffuse;
_mat.specular = specular;
_mat.metalic = metalic;
_mat.shine = shine;
_mat.normal = normal;
_mat.normalStr = normalStr;
_mat.reflective = reflective;
2024-04-08 07:13:46 +02:00
_mat.texFilter = texFilter;
2023-10-08 04:14:35 +02:00
return _mat;
2023-08-24 19:44:12 +02:00
}
2024-04-08 07:13:46 +02:00
static serialize = function() {
var s = {
diffuse,
specular,
metalic,
shine,
normalStr,
reflective,
texFilter,
};
return json_stringify(s, false);
}
static deserialize = function(str) {
var s = json_try_parse(str, noone);
if(s == noone) return;
diffuse = s.diffuse;
specular = s.specular;
metalic = s.metalic;
shine = s.shine;
normalStr = s.normalStr;
reflective = s.reflective;
texFilter = s.texFilter;
}
}