createShaderWithTextures method

FragmentShader? createShaderWithTextures({
  1. required Image daySurface,
  2. Image? nightSurface,
})

Create a shader instance with bound textures Returns a new shader instance each time to ensure fresh state

Implementation

ui.FragmentShader? createShaderWithTextures({
  required ui.Image daySurface,
  ui.Image? nightSurface,
}) {
  if (_program == null) return null;

  try {
    final shader = _program!.fragmentShader();

    // Bind the day surface texture (sampler index 0)
    shader.setImageSampler(0, daySurface);

    // Bind the night surface texture (sampler index 1)
    // If night surface is not available, use day surface as a fallback
    // (the shader will only use this when day/night cycle is enabled)
    shader.setImageSampler(1, nightSurface ?? daySurface);

    return shader;
  } catch (e) {
    debugPrint('Failed to create sphere shader with textures: $e');
    return null;
  }
}