Skip to content

Instantly share code, notes, and snippets.

View Eideren's full-sized avatar

Eideren Eideren

View GitHub Profile
@Eideren
Eideren / SeparatingAxisTheorem.cs
Created June 21, 2022 20:11
Separating Axis Theorem C#
namespace YOUR_NAMESPACE
{
using System;
using UnityEngine;
public static class SeparatingAxisTheorem
{
static Plane[] _cameraPlanesTemp = new Plane[6];
@Eideren
Eideren / MoveToZeroExp.cs
Last active October 19, 2021 04:43
A replacement for the very common ``v = lerp(v, t, deltaTime)``, this one fixes the framerate dependant issue of the former while still providing easing in when close to target. Or just look at https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ instead
// Example usage:
float dist = MathF.Abs( target - current );
current = Lerp( target, current, MoveToZeroEased( dist, deltaTime ) / dist );
/// <summary>
/// Moves <paramref name="distance"/> towards zero, the further away it is the larger the displacement.
/// Framerate independent.
/// </summary>
/// <param name="distance">The value you want to move towards zero</param>
/// <param name="timeDelta">The time between last and current call, multiply it to go faster</param>
@Eideren
Eideren / OnStrideUI.md
Last active April 28, 2024 21:26
Stride UI discussion

Editor UI

Issues:

  • WPF is windows only
  • It's a pain to maintain;
    • The logic behind it is not very flexible, loads of encapsulation and abstractions away from the raw types, tons of spaghetti logic.
  • Plugins are pretty much impossible to implement
    • The UI and system around scene management does not expect changes outside of editor-specific paths, see point #1.
  • I.E.: if a plugin were to change any value in a scene, that change would not be reflected in the editor or in the saved scene.
@Eideren
Eideren / TessCustom.sdsl
Created October 21, 2020 16:31
Stride, charly's tessellation issues
#ifndef InputControlPointCount
# define InputControlPointCount 3
#endif
#ifndef OutputControlPointCount
# define OutputControlPointCount 3
#endif
shader TessCustom : ShaderBase, TransformationBase, MaterialDomainStream, Camera, Transformation, NormalBase
{
namespace Project.Effects
{
using Stride.Rendering;
using Stride.Rendering.Materials;
using Stride.Rendering.Materials.ComputeColors;
using System.ComponentModel;
using Stride.Core;
using Stride.Core.Annotations;
using Stride.Core.Mathematics;
using Stride.Graphics;
@Eideren
Eideren / YourGameDefinition.cs
Last active April 28, 2024 21:29
How to setup async shader compilation in stride, note that the game will still freeze initially to compile the fallback
public class YourGameDefinition : Stride.Engine.Game
{
protected override void BeginRun()
{
base.BeginRun();
foreach( var feature in SceneSystem.GraphicsCompositor.RenderFeatures )
{
if( feature is MeshRenderFeature meshRf )
{
meshRf.ComputeFallbackEffect += FallbackForAsyncCompilation;

Graphics Library

  • Skia/Cairo
    • Extremely barebone, might as well fix stride's ui system ?

Retained

  • Eto, Windows Forms-like, c#
    • BSD-3
    • Fairly limited styling
  • Avalonia, WPF-like, c#|xml
    • MIT
@Eideren
Eideren / StrideExporter.cs
Last active March 13, 2023 02:20
A small class to export/save a scene or a group of entities within a running stride game
namespace Project
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using Stride.Core;
using Stride.Core.Annotations;
using Stride.Core.Mathematics;
using Stride.Core.Yaml;
@Eideren
Eideren / stride_and_transparency.md
Last active July 20, 2020 16:52
Ramblings on stride, alpha, transparency and premultiply

Multiple file formats embeds their alpha in the standard, non-premultiplied, format leading to ugly edges around transparent areas when the engine interprets those as premultiplied. There's a couple of reasons to use premultiplied alpha, you can google about this subject if you want to read if/why you should do so.

PSD outputs standard alpha out of the box, to have decent premultiplied results with that format you'll have to create an explicit alpha channel and use it as a global mask for the whole picture, if you have multiple layers with different alphas it becomes really tedious to manage that channel for every changes that you make.

TIFF on the other hand outputs premultiplied alpha and, for photoshop, converting PSDs to TIFF is mostly non-destructive as the format itself can be lossless and embeds all of the photoshop layers, groups, masks and such in the file.


Stride's texture transparency block has an Alpha property which describes how the alpha is interpreted and compressed when stored in GPU