Render textures and lightmaps together
This commit is contained in:
parent
74f4d0e7c6
commit
b2fc789734
|
@ -108,7 +108,7 @@ public partial class Mission : Node3D
|
||||||
Image lightmap = BuildLightmap(cell, packingRects, surfaceArrays);
|
Image lightmap = BuildLightmap(cell, packingRects, surfaceArrays);
|
||||||
|
|
||||||
// !Hack: This should be somewhere else?
|
// !Hack: This should be somewhere else?
|
||||||
var materials = new List<StandardMaterial3D>();
|
var materials = new List<Material>();
|
||||||
for (var i = 0; i < maxPolyIdx; i++)
|
for (var i = 0; i < maxPolyIdx; i++)
|
||||||
{
|
{
|
||||||
var textureId = cell.RenderPolys[i].TextureId;
|
var textureId = cell.RenderPolys[i].TextureId;
|
||||||
|
@ -118,11 +118,9 @@ public partial class Mission : Node3D
|
||||||
textureId = 0;
|
textureId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var material = new StandardMaterial3D
|
var material = ResourceLoader.Load<ShaderMaterial>("res://project/materials/base.tres").Duplicate() as ShaderMaterial;
|
||||||
{
|
material.SetShaderParameter("texture_albedo", _textures[textureId]);
|
||||||
AlbedoTexture = _textures[textureId],
|
material.SetShaderParameter("lightmap_albedo", ImageTexture.CreateFromImage(lightmap));
|
||||||
TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest,
|
|
||||||
};
|
|
||||||
materials.Add(material);
|
materials.Add(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,6 +242,7 @@ public partial class Mission : Node3D
|
||||||
return surfacesArrays;
|
return surfacesArrays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This is broke?
|
||||||
private static OccluderInstance3D GenerateOccluder(List<Godot.Collections.Array> surfaceArrays)
|
private static OccluderInstance3D GenerateOccluder(List<Godot.Collections.Array> surfaceArrays)
|
||||||
{
|
{
|
||||||
var vertices = new List<Vector3>();
|
var vertices = new List<Vector3>();
|
||||||
|
@ -269,7 +268,7 @@ public partial class Mission : Node3D
|
||||||
return occluderInstance;
|
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();
|
var arrMesh = new ArrayMesh();
|
||||||
for (var i = 0; i < surfaceArrays.Count; i++)
|
for (var i = 0; i < surfaceArrays.Count; i++)
|
||||||
|
|
|
@ -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
|
|
@ -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/Mission.cs" id="1_xhqt7"]
|
||||||
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"]
|
[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="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"]
|
[sub_resource type="Environment" id="Environment_oxkvl"]
|
||||||
ambient_light_source = 2
|
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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.110309, 0.187101, -0.461656)
|
||||||
script = ExtResource("1_xhqt7")
|
script = ExtResource("1_xhqt7")
|
||||||
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
|
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
|
||||||
Dump = true
|
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="."]
|
[node name="Camera3D" type="Camera3D" parent="."]
|
||||||
script = ExtResource("2_w5otl")
|
script = ExtResource("2_w5otl")
|
||||||
|
@ -27,3 +27,6 @@ environment = SubResource("Environment_oxkvl")
|
||||||
|
|
||||||
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
|
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
material_overlay = ExtResource("4_vxwmj")
|
||||||
|
|
Loading…
Reference in New Issue