Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_decal.cpp
45991 views
1
/**************************************************************************/
2
/* test_decal.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_decal)
34
35
#ifndef _3D_DISABLED
36
37
#include "scene/3d/decal.h"
38
39
namespace TestDecal {
40
41
TEST_CASE("[SceneTree][Decal] Getters/Setters") {
42
Decal *decal = memnew(Decal);
43
AABB default_aabb{
44
Vector3(-1.0f, -1.0f, -1.0f),
45
Vector3(2.0f, 2.0f, 2.0f)
46
};
47
SUBCASE("Default values") {
48
CHECK_MESSAGE(decal->get_aabb() == default_aabb, "get_aabb() returns the expected values for the default.");
49
}
50
51
SUBCASE("Set and Get Size") {
52
Vector3 size = Vector3(2.0f, 3.0f, 4.0f);
53
54
decal->set_size(size);
55
AABB expected_aabb{
56
Vector3(-1.0f, -1.5f, -2.0f),
57
Vector3(2.0f, 3.0f, 4.0f)
58
};
59
CHECK_MESSAGE(decal->get_aabb() == expected_aabb, "get_aabb() returns the expected values after setting.");
60
//default back the size in order to use the default_aabb for future assertions
61
decal->set_size(Vector3(2.0f, 2.0f, 2.0f));
62
}
63
64
SUBCASE("Set and Get Texture") {
65
Ref<Texture2D> albedo_texture;
66
albedo_texture.instantiate();
67
decal->set_texture(Decal::TEXTURE_ALBEDO, albedo_texture);
68
CHECK_MESSAGE(decal->get_texture(Decal::TEXTURE_ALBEDO) == albedo_texture, "get_texture() returns the expected texture after setting.");
69
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting texture.");
70
}
71
72
SUBCASE("Set and Get Emission Energy") {
73
decal->set_emission_energy(2.0f);
74
CHECK_MESSAGE(decal->get_emission_energy() == 2.0, "get_emission_energy() returns the expected value after setting.");
75
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting emission energy.");
76
}
77
78
SUBCASE("Set and Get Albedo Mix") {
79
decal->set_albedo_mix(0.5);
80
CHECK_MESSAGE(decal->get_albedo_mix() == 0.5f, "get_albedo_mix() returns the expected value after setting.");
81
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting albedo mix.");
82
}
83
84
SUBCASE("Set and Get Modulate") {
85
Color new_color(0.5f, 0.5f, 0.5f, 1.0f);
86
decal->set_modulate(new_color);
87
CHECK_MESSAGE(decal->get_modulate() == new_color, "get_modulate() returns the expected value after setting.");
88
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting modulate.");
89
}
90
91
SUBCASE("Set and Get Upper Fade") {
92
decal->set_upper_fade(0.4f);
93
CHECK_MESSAGE(decal->get_upper_fade() == 0.4f, "get_upper_fade() returns the expected value after setting.");
94
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting upper fade.");
95
}
96
97
SUBCASE("Set and Get Lower Fade") {
98
decal->set_lower_fade(0.2f);
99
CHECK_MESSAGE(decal->get_lower_fade() == 0.2f, "get_lower_fade() returns the expected value after setting.");
100
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting lower fade.");
101
}
102
103
SUBCASE("Set and Get Normal Fade") {
104
decal->set_normal_fade(0.1f);
105
CHECK_MESSAGE(decal->get_normal_fade() == 0.1f, "get_normal_fade() returns the expected value after setting.");
106
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting normal fade.");
107
}
108
109
SUBCASE("Enable and Check Distance Fade") {
110
decal->set_enable_distance_fade(true);
111
CHECK_MESSAGE(decal->is_distance_fade_enabled() == true, "is_distance_fade_enabled() returns the expected value after setting.");
112
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after enabling distance fade.");
113
}
114
115
SUBCASE("Set and Get Distance Fade Begin") {
116
decal->set_distance_fade_begin(50.0f);
117
CHECK_MESSAGE(decal->get_distance_fade_begin() == 50.0f, "get_distance_fade_begin() returns the expected value after setting.");
118
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting distance fade begin.");
119
}
120
121
SUBCASE("Set and Get Distance Fade Length") {
122
decal->set_distance_fade_length(15.0f);
123
CHECK_MESSAGE(decal->get_distance_fade_length() == 15.0f, "get_distance_fade_length() returns the expected value after setting.");
124
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting distance fade length.");
125
}
126
127
SUBCASE("Set and Get Cull Mask") {
128
decal->set_cull_mask(0xFF);
129
CHECK_MESSAGE(decal->get_cull_mask() == 0xFF, "get_cull_mask() returns the expected value after setting.");
130
CHECK_MESSAGE(default_aabb == decal->get_aabb(), "get_aabb() remains unchanged after setting cull mask.");
131
}
132
133
memdelete(decal);
134
}
135
136
} // namespace TestDecal
137
138
#endif // _3D_DISABLED
139
140