@tool
extends ProcGeometryNode
## GLSL compilation test: builds a noise terrain graph, compiles to standalone GLSL function
## Expected: prints valid GLSL with proc_density(vec3 pos) function to console
func _ready():
_test_compile()
func _test_compile():
var g = ProcNodeGraph.new()
# 0: Grid (20x20m, 200x200 verts)
var grid = MeshGridNode.new()
g.add_node(grid)
var sx = ValueNode.new(); sx.value = 20.0; g.add_node(sx) # 1
var sy = ValueNode.new(); sy.value = 20.0; g.add_node(sy) # 2
var vx = ValueNode.new(); vx.value = 200.0; g.add_node(vx) # 3
var vy = ValueNode.new(); vy.value = 200.0; g.add_node(vy) # 4
# 5: Displace
var displace = DisplaceNode.new()
g.add_node(displace)
var strength = ValueNode.new(); strength.value = 2.0; g.add_node(strength) # 6
var nscale = ValueNode.new(); nscale.value = 0.3; g.add_node(nscale) # 7
var ndetail = ValueNode.new(); ndetail.value = 6.0; g.add_node(ndetail) # 8
var nrough = ValueNode.new(); nrough.value = 0.5; g.add_node(nrough) # 9
# Grid params
g.connect_sockets(1, 0, 0, 0) # sx → grid.SizeX
g.connect_sockets(2, 0, 0, 1) # sy → grid.SizeY
g.connect_sockets(3, 0, 0, 2) # vx → grid.VertsX
g.connect_sockets(4, 0, 0, 3) # vy → grid.VertsY
# Displace params
g.connect_sockets(0, 0, 5, 0) # grid → displace.geometry
g.connect_sockets(6, 0, 5, 1) # strength → displace.strength
g.connect_sockets(7, 0, 5, 2) # scale → displace.scale
g.connect_sockets(8, 0, 5, 3) # detail → displace.detail
g.connect_sockets(9, 0, 5, 4) # roughness → displace.roughness
# Set graph to render the terrain mesh visually
self.graph = g
# Compile to GLSL and verify (dc-terrain integration pathway)
var glsl = g.compile_to_glsl_function("proc_density")
if glsl.contains("proc_density") and glsl.contains("vec3 pos") and not glsl.contains("pc.param"):
print("PASS: GLSL function with inlined params")
else:
print("FAIL: GLSL missing or still has pc.param references")
print(glsl)
call_deferred("_apply_material")
func _apply_material():
var mesh_child = get_node_or_null("MeshOutput")
if mesh_child and mesh_child is MeshInstance3D:
var mat = StandardMaterial3D.new()
mat.albedo_color = Color(0.4, 0.55, 0.3)
mat.roughness = 0.8
mesh_child.material_override = mat