Skip to content

Commit 84a0f62

Browse files
authored
Patch/v2.2.3 (#69)
* VMT context menu: Fix VTF generation * VMF: Fix displacements processing * Bump: v2.2.2 * VTF: Add conversion to SRGB * FGD Generator: Fix markers handling * Update readme.md * Fix duplicate sentence in legality section Removed duplicate sentence about contacting Valve for commercial use of the Source Engine SDK. * VMF: Fix displacement vertex generation for precised vertex data
1 parent 063480e commit 84a0f62

File tree

12 files changed

+108
-46
lines changed

12 files changed

+108
-46
lines changed

addons/godotfgd/main.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,9 @@ func get_prop_decorators(script: Script, property_name: String):
287287
for line in lines:
288288
line = line.trim_prefix(" ").trim_suffix(" ");
289289
if not line.begins_with("@"): continue;
290-
line = line.trim_prefix("@");
291290

292-
var name = line.split(" ")[0];
293-
var value = line.split(name)[1].trim_prefix(" ").trim_suffix(" ");
291+
var name = line.split(" ")[0].trim_prefix("@");
292+
var value = line.split("@" + name)[1].trim_prefix(" ").trim_suffix(" ");
294293

295294
if name in decorators:
296295
decorators[name] += "\n" + value;

addons/godotfgd/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="GodotVMF - FGD Generator"
44
description="Generates FGD file based on implemented entities"
55
author="H2xDev"
6-
version="1.0.0"
6+
version="1.0.1"
77
script="main.gd"

addons/godotvmf/godotvmt/vmt_material_conversion_context_menu.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,3 @@ func generate_vtf_file(texture: Texture2D) -> PackedByteArray:
150150
bytes += image.get_data()
151151

152152
return bytes;
153-

addons/godotvmf/godotvmt/vmt_transformer.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@ func basetexturetransform(material: Material, value: Variant):
116116
var transform = VMTLoader.parse_transform(value);
117117
material.uv1_scale = Vector3(transform.scale.x, transform.scale.y, 1);
118118
material.uv1_offset = Vector3(transform.translate.x, transform.translate.y, 0);
119+
120+
func blendmodulatetexture(material: Material, value: Variant):
121+
if not "blend_modulate_texture" in material: return;
122+
var texture: Texture = VTFLoader.get_texture(value);
123+
124+
if texture:
125+
var process_srgb: bool = texture.get_meta("srgb_conversion_method", 0) == VTFLoader.SRGBConversionMethod.PROCESS_IN_SHADER;
126+
material.set("convert_to_srgb", process_srgb);
127+
128+
material.set("blend_modulate_texture", VTFLoader.get_texture(value));

addons/godotvmf/godotvmt/vtf_import.gd

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@ func _get_import_order(): return 0;
1111
func _get_priority(): return 1;
1212
func _can_import_threaded(): return false;
1313

14-
func _get_import_options(str, int): return [];
14+
func _get_import_options(str, int): return [
15+
{
16+
name = "srgb_conversion_method",
17+
default_value = 1,
18+
type = TYPE_INT,
19+
property_hint = PROPERTY_HINT_ENUM,
20+
hint_string = "Disabled, During import, Process in shader",
21+
description = "Perform conversion from SRGB to Linear"
22+
}
23+
];
24+
1525
func _get_option_visibility(path: String, optionName: StringName, options: Dictionary): return true;
1626

17-
func _import(path: String, save_path: String, _a, _b, _c):
27+
func _import(path: String, save_path: String, options: Dictionary, _b, _c):
1828
var path_to_save = save_path + '.' + _get_save_extension();
1929
var vtf = VTFLoader.create(path, 0.033); # 30 FPS
2030

2131
if !vtf: return ERR_FILE_UNRECOGNIZED;
2232

23-
var texture = vtf.compile_texture();
33+
var texture = vtf.compile_texture(options.srgb_conversion_method);
2434
if not texture: return ERR_FILE_CORRUPT;
35+
texture.set_meta("srgb_conversion_method", options.srgb_conversion_method);
2536

2637
return ResourceSaver.save(texture, path_to_save, ResourceSaver.FLAG_COMPRESS);

addons/godotvmf/godotvmt/vtf_loader.gd

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
class_name VTFLoader extends RefCounted
2+
enum SRGBConversionMethod {
3+
DISABLED,
4+
DURING_IMPORT,
5+
PROCESS_IN_SHADER
6+
}
7+
28
enum ImageFormat {
39
IMAGE_FORMAT_RGBA8888,
410
IMAGE_FORMAT_ABGR8888,
@@ -203,7 +209,7 @@ static func create(path: String, duration: float = 0):
203209

204210
func done(): file.close();
205211

206-
func compile_texture():
212+
func compile_texture(srgb_conversion_method: SRGBConversionMethod):
207213
if width == 0 or height == 0:
208214
push_error("Corrupted file: {0}".format([file.get_path()]));
209215
return null;
@@ -215,11 +221,11 @@ func compile_texture():
215221
tex.frames = frames;
216222

217223
for frame in range(0, frames):
218-
tex.set_frame_texture(frame, _read_frame(frame));
224+
tex.set_frame_texture(frame, _read_frame(frame, srgb_conversion_method));
219225
tex.set_frame_duration(frame, frame_duration);
220226

221227
else:
222-
tex = _read_frame(0);
228+
tex = _read_frame(0, srgb_conversion_method);
223229

224230
if not tex:
225231
push_error("Texture not loaded: {0}".format([path]));
@@ -230,13 +236,12 @@ func compile_texture():
230236
static var normal_conversion_shader: Shader;
231237
static var shader_material: ShaderMaterial;
232238

233-
func _read_frame(frame):
239+
func _read_frame(frame, srgb_conversion_method: SRGBConversionMethod):
234240
var data = PackedByteArray();
235241
var byteRead = 0;
236242
var is_dxt_1 = hires_image_format == ImageFormat.IMAGE_FORMAT_DXT1;
237243
var format = format_map[str(hires_image_format)];
238244
var use_mipmaps = not (flags & Flags.TEXTUREFLAGS_NOMIP);
239-
240245
frame = frames - 1 - frame;
241246

242247
for i in range(mipmap_count):
@@ -251,7 +256,11 @@ func _read_frame(frame):
251256

252257
byteRead += mip_size + mip_size * (frames - 1);
253258

254-
var img = Image.create_from_data(width, height, use_mipmaps, format, data);
259+
var img := Image.create_from_data(width, height, use_mipmaps, format, data);
260+
261+
if srgb_conversion_method == SRGBConversionMethod.DURING_IMPORT:
262+
img.decompress();
263+
img.compress(Image.COMPRESS_S3TC);
255264

256265
alpha = flags & Flags.TEXTUREFLAGS_ONEBITALPHA or flags & Flags.TEXTUREFLAGS_EIGHTBITALPHA;
257266

@@ -266,7 +275,6 @@ func _init(path, duration):
266275
self.frame_duration = duration;
267276

268277
file = FileAccess.open(path, FileAccess.READ);
269-
prints('VTFFLAGS', flags);
270278

271279
static func get_texture(texture: String):
272280
texture = texture.to_lower();

addons/godotvmf/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="GodotVMF"
44
description="Allows use VMF files in Godot"
55
author="H2xDev"
6-
version="2.2.2"
6+
version="2.2.3"
77
script="godotvmf.gd"

addons/godotvmf/shaders/WorldVertexTransitionMaterial.gd

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
@tool
22
class_name WorldVertexTransitionMaterial extends ShaderMaterial
33

4-
@export_category("Albedo")
4+
@export var blend_modulate_texture: Texture = null:
5+
set(value):
6+
set_shader_parameter("blend_modulate_texture", value);
7+
blend_modulate_texture = value;
8+
emit_changed();
9+
10+
@export var convert_to_srgb: bool = false:
11+
set(value):
12+
set_shader_parameter("convert_to_srgb", value);
13+
convert_to_srgb = value;
14+
emit_changed();
15+
16+
@export_group("Albedo")
517
@export var albedo_texture: Texture = null:
618
set(value):
719
set_shader_parameter("albedo_texture", value);
@@ -14,7 +26,7 @@ class_name WorldVertexTransitionMaterial extends ShaderMaterial
1426
albedo_texture2 = value;
1527
emit_changed();
1628

17-
@export_category("Normal")
29+
@export_group("Normal")
1830
@export var normal_texture: Texture = null:
1931
set(value):
2032
set_shader_parameter("normal_texture", value);
@@ -27,7 +39,7 @@ class_name WorldVertexTransitionMaterial extends ShaderMaterial
2739
normal_texture2 = value;
2840
emit_changed();
2941

30-
@export_category("Displacement")
42+
@export_group("Displacement")
3143
@export var displacement_texture: Texture = null:
3244
set(value):
3345
set_shader_parameter("displacement_texture", value);
@@ -40,8 +52,7 @@ class_name WorldVertexTransitionMaterial extends ShaderMaterial
4052
displacement_texture2 = value;
4153
emit_changed();
4254

43-
@export_category("Metallic")
44-
55+
@export_group("Metallic")
4556
@export_range(0, 1, 0.01) var metallic: float = 0.0:
4657
set(value):
4758
set_shader_parameter("metallic", value);
@@ -66,7 +77,7 @@ class_name WorldVertexTransitionMaterial extends ShaderMaterial
6677
metallic_texture2 = value;
6778
emit_changed();
6879

69-
@export_category("Roughness")
80+
@export_group("Roughness")
7081
@export_range(0, 1, 0.01) var roughness: float = 0.0:
7182
set(value):
7283
set_shader_parameter("roughness", value);

addons/godotvmf/shaders/WorldVertexTransitionMaterial.gdshader

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ uniform vec4 metallic_texture_channel;
2121
uniform sampler2D roughness_texture : hint_roughness_r,filter_linear_mipmap,repeat_enable;
2222
uniform sampler2D roughness_texture2 : hint_roughness_r,filter_linear_mipmap,repeat_enable;
2323

24+
uniform sampler2D blend_modulate_texture: source_color, filter_linear_mipmap, repeat_enable;
25+
2426
uniform float specular;
2527
uniform vec3 uv1_scale = vec3(1.0);
2628
uniform vec3 uv1_offset = vec3(0.0);
2729
uniform vec3 uv2_scale = vec3(1.0);
2830
uniform vec3 uv2_offset = vec3(0.0);
31+
uniform bool convert_to_srgb = true;
32+
33+
vec4 from_linear(vec4 linearRGB) {
34+
bvec3 cutoff = lessThan(linearRGB.rgb, vec3(0.0031308));
35+
vec3 higher = vec3(1.055)*pow(linearRGB.rgb, vec3(1.0/2.4)) - vec3(0.055);
36+
vec3 lower = linearRGB.rgb * vec3(12.92);
2937

38+
return vec4(mix(higher, lower, cutoff), linearRGB.a);
39+
}
3040

3141
void vertex() {
3242
UV = UV * uv1_scale.xy + uv1_offset.xy;
@@ -37,8 +47,19 @@ void vertex() {
3747
void fragment() {
3848
vec4 albedo_tex1 = texture(albedo_texture, UV);
3949
vec4 albedo_tex2 = texture(albedo_texture2, UV);
40-
vec4 albedo_tex = mix(albedo_tex1, albedo_tex2, COLOR.r);
41-
vec4 albedo = mix(albedo_color, albedo_color2, COLOR.r);
50+
51+
vec4 modulate_value = convert_to_srgb
52+
? from_linear(texture(blend_modulate_texture, UV))
53+
: texture(blend_modulate_texture, UV);
54+
55+
float minb = max(modulate_value.g - modulate_value.r, 0.0);
56+
float maxb = min(modulate_value.g + modulate_value.r, 1.0);
57+
58+
float blendfactor = COLOR.r;
59+
blendfactor = smoothstep(minb, maxb, blendfactor);
60+
61+
vec4 albedo = mix(albedo_color, albedo_color2, blendfactor);
62+
vec4 albedo_tex = mix(albedo_tex1, albedo_tex2, blendfactor);
4263

4364
ALBEDO = albedo_tex.rgb * albedo.rgb;
4465

addons/godotvmf/src/structs/vmf_side.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ func _init(raw: Dictionary, _solid: VMFSolid) -> void:
4141
## Called automatically from VMFSolid
4242
func calculate_vertices() -> void:
4343
# Already calculated
44-
if vertices.size() > 0: return;
44+
if vertices.size() > 0:
45+
if is_displacement:
46+
dispinfo.calculate_vertices();
47+
return;
4548

4649
var raw_vertices: Array[Vector3] = [];
4750
var cache = {};

0 commit comments

Comments
 (0)