Render textures and lightmaps together

This commit is contained in:
Jarrod Doyle 2024-08-05 21:46:03 +01:00
parent 74f4d0e7c6
commit b2fc789734
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 31 additions and 9 deletions

View File

@ -108,7 +108,7 @@ public partial class Mission : Node3D
Image lightmap = BuildLightmap(cell, packingRects, surfaceArrays);
// !Hack: This should be somewhere else?
var materials = new List<StandardMaterial3D>();
var materials = new List<Material>();
for (var i = 0; i < maxPolyIdx; i++)
{
var textureId = cell.RenderPolys[i].TextureId;
@ -118,11 +118,9 @@ public partial class Mission : Node3D
textureId = 0;
}
var material = new StandardMaterial3D
{
AlbedoTexture = _textures[textureId],
TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest,
};
var material = ResourceLoader.Load<ShaderMaterial>("res://project/materials/base.tres").Duplicate() as ShaderMaterial;
material.SetShaderParameter("texture_albedo", _textures[textureId]);
material.SetShaderParameter("lightmap_albedo", ImageTexture.CreateFromImage(lightmap));
materials.Add(material);
}
@ -244,6 +242,7 @@ public partial class Mission : Node3D
return surfacesArrays;
}
// TODO: This is broke?
private static OccluderInstance3D GenerateOccluder(List<Godot.Collections.Array> surfaceArrays)
{
var vertices = new List<Vector3>();
@ -269,7 +268,7 @@ public partial class Mission : Node3D
return occluderInstance;
}
private static MeshInstance3D GenerateMesh(List<Godot.Collections.Array> surfaceArrays, List<StandardMaterial3D> materials)
private static MeshInstance3D GenerateMesh(List<Godot.Collections.Array> surfaceArrays, List<Material> materials)
{
var arrMesh = new ArrayMesh();
for (var i = 0; i < surfaceArrays.Count; i++)

View File

@ -0,0 +1,20 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://ck8h6dvojuegj"]
[sub_resource type="Shader" id="Shader_eumy4"]
code = "shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,unshaded;
uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform sampler2D lightmap_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform float lightmap_modulation;
void fragment() {
vec4 albedo_tex = texture(texture_albedo,UV);
vec4 lightmap_tex = texture(lightmap_albedo,UV2) * lightmap_modulation;
ALBEDO = albedo_tex.rgb * lightmap_tex.rgb;
}
"
[resource]
render_priority = 0
shader = SubResource("Shader_eumy4")
shader_parameter/lightmap_modulation = 1.0

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://boxi211q3kx6c"]
[gd_scene load_steps=6 format=3 uid="uid://boxi211q3kx6c"]
[ext_resource type="Script" path="res://project/code/Mission.cs" id="1_xhqt7"]
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"]
[ext_resource type="PackedScene" uid="uid://cekg1xb5f0ux1" path="res://project/scenes/ui/mission_selector.tscn" id="3_hwfcj"]
[ext_resource type="Material" uid="uid://ck8h6dvojuegj" path="res://project/materials/base.tres" id="4_vxwmj"]
[sub_resource type="Environment" id="Environment_oxkvl"]
ambient_light_source = 2
@ -15,7 +16,6 @@ ssao_enabled = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.110309, 0.187101, -0.461656)
script = ExtResource("1_xhqt7")
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
Dump = true
[node name="Camera3D" type="Camera3D" parent="."]
script = ExtResource("2_w5otl")
@ -27,3 +27,6 @@ environment = SubResource("Environment_oxkvl")
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
unique_name_in_owner = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_overlay = ExtResource("4_vxwmj")