Nathan Lamont

Notes to Self

Godot Exploration

  • Devs are committed to home-grown “GDScript”
  • Swift looked promising but:
    • Multi step process for build changes (build, then copy; could be automated?)
    • Currently sketchy x-platform support
    • Maybe worth revisiting later
    • SwiftGodotKit inverts the problem and seems to use Godot by embedding it, like a framework?
  • C# is typed and structured but suffers from garbage collection stutters; appears to be the only real alternative to GDScript

Not Godot-flavor, but educational

Additional shaders, lightning:

#define SCALE 0.85

float map(vec3 p) {
    float lat = 90. - acos(p.y / length(p)) * 180./PI;
    float lon = atan(p.x, p.z) * 180./PI;
    vec2 uv = vec2(lon/360., lat/180.) + 0.5;
    return texture(iChannel0, uv).x;
}

vec3 normal(vec3 p) {
    vec2 e = vec2(1,0)/1e3;
    p += 0.01 * vec3(
        map(p + e.xyy) - map(p - e.xyy),
        map(p + e.yxy) - map(p - e.yxy),
        map(p + e.yyx) - map(p - e.yyx))/ (2. * length(e));
    return normalize(p);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
    vec2 p = (2. * fragCoord.xy - iResolution.xy) / iResolution.y;
    float lat = 15. * sin(0.1 * iTime);
    float lon = 7.5 * iTime + 100.;
    if (iMouse.z > 0.) {
        lat = 90.  - 180. * iMouse.y/iResolution.y;
        lon = 180. - 360. * iMouse.x/iResolution.x;
    }
    vec3 camPos = 10. * vec3(sin(lon*PI/180.) * cos(lat*PI/180.), sin(lat*PI/180.), cos(lon*PI/180.) * cos(lat*PI/180.));
    vec3 w = normalize(-camPos);
    vec3 u = normalize(cross(w, vec3(0,1,0)));
    vec3 v = normalize(cross(u, w));
    mat3 camera = mat3(u, v, w);
    
    vec3 dir = normalize(camera * vec3(p / SCALE, length(camPos)));
    float dist = iSphere(camPos, dir, vec4(0,0,0,1));
    fragColor = vec4(0);
    if (dist > 0.) {
        vec3 q = camPos + dir * dist;
        float c = map(q);
        vec3 n = normal(q);
        float light = clamp(dot(n, normalize(vec3(-4,1,2))), 0., 1.);
        float heat = clamp(2. / pow(iTime, 2.), 0., 1.);
        fragColor = light * mix(vec4(0.58, 0.57, 0.55, 1), vec4(0.15, 0.13, 0.1, 1), smoothstep(0., 3., c));
        fragColor += 5. * c * heat * vec4(1., 0.15, 0.05, 1.);
    }
    fragColor.rgb = mix(fragColor.rgb, vec3(0), smoothstep(SCALE - 4./iResolution.y, SCALE + 1./iResolution.y, length(p)));
    fragColor.rgb = pow(fragColor.rgb, vec3(1./2.2));
}

This one has an atmosphere, moving clouds, and two stars with impressive eclipse effect: https://www.shadertoy.com/view/XsjGRd

Unrelated amazing water: https://www.shadertoy.com/view/wldBRf

Claude authored vertex shader for keeping mesh at constant size, untested:

shader_type spatial;
render_mode unshaded;

uniform float size_factor = 1.0;
uniform float min_distance = 1.0;
uniform float max_distance = 10.0;

void vertex() {
    // Transform the vertex to view space
    vec4 view_pos = MODELVIEW_MATRIX * vec4(VERTEX, 1.0);
    
    // Calculate the distance from the camera
    float distance = length(view_pos.xyz);
    
    // Clamp the distance between min and max values
    distance = clamp(distance, min_distance, max_distance);
    
    // Scale the vertex based on its distance from the camera
    VERTEX *= distance * size_factor;
    
    // Apply model-view-projection transformation
    POSITION = PROJECTION_MATRIX * view_pos;
}

void fragment() {
    // Set the albedo color (you can modify this or add textures as needed)
    ALBEDO = vec3(1.0, 1.0, 1.0);
}

Explosions

Trying to get some things to glow, other things to not glow

You discovered that the UI elements in your experiment (the grid in Ares) were glowing. You tried many different ways (custom shader? complicated pipeline using scary new under-documented compositing in godot?) You wanted to keep the specular highlights glowing and the “engines” glowing, but exclude the UI elements.

Answer was to keep the worldenvironment glow HDR threshold at 1 (makes sense) but to:

  1. for specular: up the “energy” of the directional light above 1 and
  2. for glowing engines: don’t know how to do it for a glow map, but for a simple emissive color (should suit our needs), in blender, set the material emission strength to a “value” and enter some high number above 1 (I assume, I used 4)

3rd person

Not that you’re doing it, but Google fair fight godot YouTube “

Image to 2D Collision Shape!

From https://youtu.be/zeYtjYPjCkg?si=KhbpY4eVneB8EG7O&t=224

func SpriteToPolygon():
  var bitmap = BitMap.new()
  bitmap.create_from_image_alpha(
    get_parent().get_texture().get_image()
  )

  polys = bitmap.opaque_to_polygons(
    Rect2(
      Vector2.ZERO,
      get_parent().get_texture().get_size()
    ),
    epsilon
  )

  for poly in polys:
    collision_polygon = CollisionPolygon2D.new()
    collision_polygon.polygon = poly
    add_child(collision_polygon)

  if get_parent().centered:
    collision_polygon.position -= Vector2 (bitmap.get_size() / 2)
    collision_polygon.position += get_parent().offset

Random recommended extensions https://www.reddit.com/r/godot/s/O2eVtikL0Z