Skip to content

Commit 9201da5

Browse files
committed
add emission
1 parent cf2a1ea commit 9201da5

10 files changed

Lines changed: 73 additions & 14 deletions

File tree

addons/libmaszyna/e3d/e3d_instancer.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func _get_material_override(target_node: E3DModelInstance, submodel: E3DSubModel
4747

4848
# TODO: handle more material options here (selfillum, diffuse_color, etc)
4949
options.force_transparent = submodel.material_transparent
50+
options.selfillum_energy = options.selfillum_color.a # legacy renderer
51+
options.selfillum_color = submodel.self_illumination
52+
options.selfillum_enabled = options.selfillum_energy > 0.0 and submodel.lights_on_threshold >= 1.0 # legacy renderer logic
5053

5154
if submodel.dynamic_material:
5255
if target_node.skins.size() < submodel.dynamic_material_index + 1:

addons/libmaszyna/materials/material_factory.gd

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ func _apply(
146146
if property_name == "shader" or property_name == "render_priority" or property_name.begins_with("shader_parameter/"):
147147
target_shader_material.set(property_name, source_shader_material.get(property_name))
148148

149-
shader_meta.factory.call(mmat, variant, material, texture_map, model_path, options.diffuse_color)
149+
shader_meta.factory.call(mmat, variant, material, texture_map, model_path, options)
150150
var transparency: MaterialManager.Transparency = MaterialManager.Transparency.Disabled
151151
if mmat.transparent or options.force_transparent:
152152
transparency = MaterialManager.Transparency.AlphaScissor
153153
target_shader_material.set_shader_parameter("transparency", transparency)
154154
target_shader_material.set_shader_parameter("alpha_scissor_threshold", 0.5)
155+
target_shader_material.set_shader_parameter("emission_enabled", options.selfillum_enabled)
156+
target_shader_material.set_shader_parameter("emission_color", options.selfillum_color if options.selfillum_color else Color(1.0, 1.0, 1.0, 1.0))
157+
target_shader_material.set_shader_parameter("emission_energy", options.selfillum_energy)
155158

156159

157160
func _apply_default_material(
@@ -160,7 +163,7 @@ func _apply_default_material(
160163
material: ShaderMaterial,
161164
texture_map: TextureMap,
162165
model_path: String,
163-
diffuse_color: Color,
166+
options: MaterialManager.MaterialOptions,
164167
) -> void:
165168
var diffuse_texture: String = variant.get_texture_path(texture_map.albedo)
166169
var normalmap_texture: String = variant.get_texture_path(texture_map.normalmap)
@@ -178,7 +181,7 @@ func _apply_default_material(
178181
1.0
179182
))
180183
else:
181-
material.set_shader_parameter("albedo", diffuse_color)
184+
material.set_shader_parameter("albedo", options.diffuse_color)
182185

183186
if normalmap_texture:
184187
material.set_shader_parameter("texture_normal", MaterialManager.load_texture(model_path, normalmap_texture, true))
@@ -192,14 +195,17 @@ func _apply_default_material(
192195

193196
if variant.has_parameter("reflection"):
194197
material.set_shader_parameter("metallic", variant.get_parameter("reflection"))
198+
material.set_shader_parameter("emission_enabled", options.selfillum_enabled)
199+
material.set_shader_parameter("emission_color", options.selfillum_color)
200+
material.set_shader_parameter("emission_energy", options.selfillum_energy)
195201

196202
func _apply_parallax(
197203
mmat: MaszynaMaterial,
198204
variant: MaszynaMaterial.MaszynaMaterialVariant,
199205
material: ShaderMaterial,
200206
texture_map: TextureMap,
201207
model_path: String,
202-
diffuse_color: Color,
208+
options: MaterialManager.MaterialOptions,
203209
) -> void:
204210
var diffuse_texture_path: String = variant.get_texture_path(texture_map.albedo)
205211
var normalmap_texture_path: String = variant.get_texture_path(texture_map.normalmap)
@@ -223,7 +229,7 @@ func _apply_parallax(
223229

224230
var albedo_multiplier:Color = Color(1.0, 1.0, 1.0, 1.0)
225231
if not diffuse_texture_path:
226-
albedo_multiplier = diffuse_color
232+
albedo_multiplier = options.diffuse_color
227233

228234
if variant.has_parameter("diffuse"):
229235
albedo_multiplier = Color(
@@ -262,7 +268,7 @@ func _apply_water(
262268
material: ShaderMaterial,
263269
texture_map: TextureMap,
264270
model_path: String,
265-
diffuse_color: Color,
271+
options: MaterialManager.MaterialOptions,
266272
) -> void:
267273
var diffuse_texture_path: String = variant.get_texture_path(texture_map.albedo)
268274
var normalmap_texture_path: String = variant.get_texture_path(texture_map.normalmap)

addons/libmaszyna/materials/types/default.gdshader

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ uniform float metallic : hint_range(0.0, 1.0, 0.01);
2121
uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
2222
uniform float normal_scale : hint_range(-16.0, 16.0);
2323

24+
uniform bool emission_enabled = false;
25+
uniform vec4 emission_color;
26+
uniform float emission_energy : hint_range(0.0, 16.0);
27+
2428
uniform vec3 uv1_scale;
2529
uniform vec3 uv1_offset;
2630
uniform vec3 uv2_scale;
@@ -50,4 +54,9 @@ void fragment() {
5054
// Normal Map: Enabled
5155
NORMAL_MAP = texture(texture_normal, base_uv).rgb;
5256
NORMAL_MAP_DEPTH = normal_scale;
57+
58+
if(emission_enabled) {
59+
EMISSION = emission_color.rgb * albedo_tex.rgb * emission_energy;
60+
}
61+
5362
}

addons/libmaszyna/materials/types/normalmap.gdshader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ uniform float metallic : hint_range(0.0, 1.0, 0.01);
2121
uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
2222
uniform float normal_scale : hint_range(-16.0, 16.0);
2323

24+
uniform bool emission_enabled = false;
25+
uniform vec4 emission_color;
26+
uniform float emission_energy : hint_range(0.0, 16.0);
27+
2428
uniform vec3 uv1_scale;
2529
uniform vec3 uv1_offset;
2630
uniform vec3 uv2_scale;
@@ -50,4 +54,10 @@ void fragment() {
5054
// Normal Map: Enabled
5155
NORMAL_MAP = texture(texture_normal, base_uv).rgb;
5256
NORMAL_MAP_DEPTH = normal_scale;
57+
58+
if(emission_enabled) {
59+
EMISSION = emission_color.rgb * albedo_tex.rgb * emission_energy;
60+
}
61+
62+
5363
}

addons/libmaszyna/materials/types/normalmap_specgloss.gdshader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ uniform float metallic : hint_range(0.0, 1.0, 0.01);
2121
uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
2222
uniform float normal_scale : hint_range(-16.0, 16.0);
2323

24+
uniform bool emission_enabled = false;
25+
uniform vec4 emission_color;
26+
uniform float emission_energy : hint_range(0.0, 16.0);
27+
2428
uniform vec3 uv1_scale;
2529
uniform vec3 uv1_offset;
2630
uniform vec3 uv2_scale;
@@ -50,4 +54,10 @@ void fragment() {
5054
// Normal Map: Enabled
5155
NORMAL_MAP = texture(texture_normal, base_uv).rgb;
5256
NORMAL_MAP_DEPTH = normal_scale;
57+
58+
if(emission_enabled) {
59+
EMISSION = emission_color.rgb * albedo_tex.rgb * emission_energy;
60+
}
61+
62+
5363
}

addons/libmaszyna/materials/types/parallax.gdshader

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,6 @@ void fragment() {
149149

150150
NORMAL_MAP = decode_normal_from_rg(normal_sample);
151151
NORMAL_MAP_DEPTH = 1.0;
152+
152153
}
153154
}

addons/libmaszyna/materials/types/shadowlessnormalmap.gdshader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, re
1818
uniform float specular : hint_range(0.0, 1.0, 0.01);
1919
uniform float metallic : hint_range(0.0, 1.0, 0.01);
2020

21+
uniform bool emission_enabled = false;
22+
uniform vec4 emission_color;
23+
uniform float emission_energy : hint_range(0.0, 16.0);
24+
25+
2126
uniform vec3 uv1_scale;
2227
uniform vec3 uv1_offset;
2328
uniform vec3 uv2_scale;
@@ -43,4 +48,10 @@ void fragment() {
4348
vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
4449
float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
4550
ROUGHNESS = roughness_tex * roughness;
51+
52+
if(emission_enabled) {
53+
EMISSION = emission_color.rgb * albedo_tex.rgb * emission_energy;
54+
}
55+
56+
4657
}

addons/libmaszyna/materials/types/sunlessnormalmap.gdshader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ uniform float metallic : hint_range(0.0, 1.0, 0.01);
2121
uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
2222
uniform float normal_scale : hint_range(-16.0, 16.0);
2323

24+
uniform bool emission_enabled = false;
25+
uniform vec4 emission_color;
26+
uniform float emission_energy : hint_range(0.0, 16.0);
27+
28+
2429
uniform vec3 uv1_scale;
2530
uniform vec3 uv1_offset;
2631
uniform vec3 uv2_scale;
@@ -50,4 +55,10 @@ void fragment() {
5055
// Normal Map: Enabled
5156
NORMAL_MAP = texture(texture_normal, base_uv).rgb;
5257
NORMAL_MAP_DEPTH = normal_scale;
58+
59+
if(emission_enabled) {
60+
EMISSION = emission_color.rgb * albedo_tex.rgb * emission_energy;
61+
}
62+
63+
5364
}

demo/demo_3d.tscn

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ glow_enabled = true
5353
fog_enabled = true
5454
fog_sky_affect = 0.4
5555
volumetric_fog_enabled = true
56-
volumetric_fog_density = 0.01
56+
volumetric_fog_density = 0.003
5757
volumetric_fog_anisotropy = 0.0
58-
volumetric_fog_length = 55.89
58+
volumetric_fog_length = 6.5
5959
volumetric_fog_detail_spread = 1.0
6060
volumetric_fog_sky_affect = 0.405
6161
adjustment_enabled = true
@@ -233,8 +233,6 @@ visible = null
233233
[node name="MaszynaEnvironmentNode" type="Node" parent="." unique_id=1464463242]
234234
script = ExtResource("2_py6pt")
235235
world_environment = NodePath("../WorldEnvironment")
236-
season = 2
237-
weather = 0
238236
sky_texture_offset = Vector2(0.49, 0.005)
239237
sky_texture_scale = Vector2(0.547, 0.865)
240238
sky_energy = 0.85
@@ -250,9 +248,8 @@ size = Vector3(5000, 0.1, 5000)
250248

251249
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=786641912]
252250
transform = Transform3D(-0.846557, 0.01871, 0.531969, 0.393589, 0.694835, 0.601906, -0.358369, 0.718925, -0.595582, 5.83027, -6.14961, 0)
253-
visible = false
254251
light_color = Color(0.929688, 0.848771, 0.817108, 1)
255-
light_energy = 1.12
252+
light_energy = 1.2
256253
light_indirect_energy = 2.0
257254
light_volumetric_fog_energy = 11.811
258255
shadow_enabled = true

src/parsers/e3d_parser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ namespace godot {
8989
result.first_vertex_idx = u32s(p_file->get_32());
9090
result.material_idx = u32s(p_file->get_32());
9191
result.is_material_colored = (result.material_idx == 0);
92-
result.lights_on_threshold = p_file->get_float();
93-
result.visibility_light_threshold = p_file->get_float();
92+
p_file->get_float(); // offset 40 UNUSED
93+
result.lights_on_threshold = p_file->get_float(); // offset 44
94+
// result.visibility_light_threshold = p_file->get_float();
9495
// ReSharper disable once CppExpressionWithoutSideEffects
9596
p_file->get_buffer(16); // skip unused RGBA ambient
9697
const float diffuse_r = p_file->get_float();

0 commit comments

Comments
 (0)