Radiance 3.0.1

dotnet add package Radiance --version 3.0.1
                    
NuGet\Install-Package Radiance -Version 3.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Radiance" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Radiance" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Radiance" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Radiance --version 3.0.1
                    
#r "nuget: Radiance, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Radiance@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Radiance&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Radiance&version=3.0.1
                    
Install as a Cake Tool

Radiance

An OpenGL/OpenTK-based library 2D foccused to program shaders easily in C#.

Table of Contents

Overview

Radiance is a library that can generate GLSL (The language of OpenGL) automatically only using C# code. Radiance manage OpenGL to create buffers, associate variables, compile shaders and control programs. With Radiance will can use OpenGL in high level without completly lose the high performance of OpenGL and GPU renderization.

How to install

dotnet new console # Create project
dotnet add package Radiance # Install Radiance

Learn by examples

Lear all features about Radiance with examples.

Create a simple fullscreen window

using Radiance;

Window.OnKeyDown += (key, mod) => {
    if (key == Input.Escape)
        Window.Close();
};
// Or do that:
// Window.CloseOn(Input.Escape);
Window.Open();

Create your polygons

var mypolygon1 = Polygons.FromData(
    (0, 0), (300, 100), (300, 50), (200, 10)
);
var mypolygon2 = Polygons.Rect(50, 50, 0, 100, 100); // point (50, 50, 0)
var mypolygon3 = Polygons.Rect(100, 100); // point (0, 0)
var mypolygon4 = Polygons.Square; // size 1 centralized on (0, 0)
var myPolygon5 = Polygons.Ellipse(100, 200);
var myPolygon6 = Polygons.Circle;
var myPolygon7 = Polygons.Polar(angle => 10 + MathF.Sin(angle));

Draw Object using renders

using Radiance;
using static Radiance.Utils;

var myRender = render(() =>
{
    color = red;
    fill(); // fill polygon

    color = black;
    draw(5); // draw border

    color = blue;
    plot(5); // draw points 
});

var poly = Polygons.Rect(200, 200, 0, 300, 300);
Window.OnRender += () => myRender(poly);

Window.ClearColor = white; // The color of the screen.
Window.CloseOn(Input.Escape);
Window.Open();

Transfor Polygons and use many built-in functions

using Radiance;
using Radiance.Bufferings;
using static Radiance.Utils;

var myRender = render(() =>
{
    zoom(100);
    centralize();
    color = red;
    fill();
});

Polygon[] polys = [ Polygons.Square, Polygons.Circle, Polygons.Triangule ];
int i = 0;
Window.OnRender += () => myRender(polys[i]);

Window.OnKeyDown += (key, mod) => {
    if (key == Input.Up)
        i = (i + 1) % 3;
    
    if (key == Input.Down)
        i = (i + 2) % 3;
};

Window.ClearColor = white;
Window.CloseOn(Input.Escape);
Window.Open();

Transform the polygon as you want

using Radiance;
using static Radiance.Utils;

var myRender = render((val r, val g, val a, val size, val dx, val dy) => {
    zoom(size);
    move(dx, dy);
    // modify the position of polygon vertex
    pos = (pos.x, pos.y + pos.x / 5, pos.z);
    // use x, y, z, variables to define each pixel color
    color = (r, g, x / 300, a);
    fill();
});

Window.OnRender += () => myRender(
    Polygons.Square,
    red, 100, 200, 200
);

Window.CloseOn(Input.Escape);
Window.Open();

Create a render with parameters

using Radiance;
using static Radiance.Utils;

var myRender = render((vec4 myColor) => {
    color = myColor;
    fill();
});

var myPolygon = Polygons.FromData(
    (0, 0), (100, 0), (100, 100), (0, 100)
);

// red = (1, 0, 0, 1), so can be used to set 4 parameters
// you can do that too:
// Window.OnRender += () => myRender(myPolygon, 1, 0, 0, 1);
Window.OnRender += () => myRender(myPolygon, red);

Window.CloseOn(Input.Escape);
Window.Open();

Curry parameters

using Radiance;
using static Radiance.Utils;

var myRender = render((vec4 myColor) => {
    color = myColor;
    fill();
});

var myPolygon = Polygons.FromData(
    (0, 0), (100, 0), (100, 100), (0, 100)
);

// mySquareRender every is called with the myPolygon value
// but still expect a 'r', 'g', 'b' and 'a' parameters
var mySquareRender = myRender(myPolygon);

// myRedRender no fix a polygon, using Utils.skip field
// but he fix the color red for (r, g, b, a) arguments
var myRedRender = myRender(skip, red);

// now we can call myRedRender with only myPolygon
Window.OnRender += () => myRedRender(myPolygon);

Window.CloseOn(Input.Escape);
Window.Open();

Handle renders

using Radiance;
using static Radiance.Utils;

var myRender = render((val zoomForce, val rotate) =>
{
    zoom(zoomForce);
    move(
        zoomForce * sin(rotate), 
        zoomForce * cos(rotate)
    );
});

var myOtherRender = render((val speed, vec4 clr) =>
{
    val size = 100;
    myRender(size, speed * t);
    centralize(); // move (0, 0) to center of screen

    color = clr;
    fill();
});

int speed = 5;

var myCurriedRender = myOtherRender(Polygons.Square, skip, red);
Window.OnRender += () => myCurriedRender(speed);

Window.ClearColor = white;
Window.CloseOn(Input.Escape);
Window.Open();

Use buffers to draw very fast

using Radiance;
using static Radiance.Utils;

// Use N * buffer repeat data but virtually
int N = 10_000;
 // 10'000 circles.
var poly = N * Polygons.Circle;
// 100 colors repeating 100 times each
var colors = N / 100 * Buffers.Create(100, Buffers.Factories.Urand3);
// 10'000 random positions (x, y)
var positions = Buffers.Create(N, Buffers.Factories.Rand2(0, 2048));

float[] speedsY = new float[N];

var myRender = render((vec3 clr, vec2 position) =>
{
    zoom(10);
    move(position);
    color = vec(clr, 1);
    fill();
    color = black;
    draw(2);
});

Window.OnRender += () => myRender(poly, colors, positions);

Window.OnFrame += () =>
{;
    for (int i = 0; i < N; i++)
    {
        speedsY[i] -= 100f * Window.DeltaTime;
        positions[1, i] += speedsY[i] * Window.DeltaTime;
        if (positions[1, i] < 0)
        {
            positions[1, i] = 0;
            speedsY[i] *= -0.8f;
        }
    }
};

Window.ClearColor = white;
Window.CloseOn(Input.Escape);
Window.Open();

Use Clock to control time

using Radiance;
using static Radiance.Utils;

var clock = new Clock();

var myRender = render((val time) => {
    zoom(100);
    rotate(time);
    centralize();
    color = red;
    fill();
});

Window.OnRender += () => myRender(
    Polygons.Square, clock.Time
);

Window.OnKeyDown += (key, mod) =>
{
    if (key == Input.Space)
        clock.ToogleFreeze();
};

Window.CloseOn(Input.Escape);
Window.Open();

Use Utils.t to create amazing animations

using Radiance;
using static Radiance.Utils;

var myRender = render((vec4 myColor, val size, val dx, val dy) => {
    zoom(size);
    move(dx + 10 * t, dy + 10 * t);
    color = myColor;
    fill();
});

Window.OnRender += () => myRender(
    Polygons.Square,
    red, 100, 200, 200
);

Window.CloseOn(Input.Escape);
Window.Open();

Use GPU functions to create effects fast

using Radiance;
using static Radiance.Utils;

var myRender = render((val size, val dx, val dy) => {
    zoom(size);
    move(dx, dy);
    // mix recive two values and a coeficient between 0 and 1
    // and chooses a mix of the values using this coeficient
    // 0 = red, 1 = blue, 0.5 = (red + blue) / 2

    // sin is a trigonometric function that return a value
    // between -1 and 1. cos functions exists to, but
    // sin(0) = 0 and cos(0) = 1.
    var coef = (sin(5 * t) + 1) / 2;
    color = mix(red, blue, coef);
    fill();
});

Window.OnRender += () => myRender(
    Polygons.Square,
    100, 200, 200
);

Window.CloseOn(Input.Escape);
Window.Open();

Use trigonometric functions to create loop behaviours

using Radiance;
using static Radiance.Utils;

var myRender = render(() => {
    zoom(100 + 50 * sin(5 * t));
    centralize();
    move(200 * cos(2 * t), 200 * sin(2 * t));
    color = red;
    fill();
});

Window.OnRender += () => myRender(Polygons.Square);

Window.CloseOn(Input.Escape);
Window.Open();

Create amazing effects with Radiance

using Radiance;
using static Radiance.Utils;

var myRender = render(() => {
    var center = (width / 2, height / 2);
    var pixel = (x, y);
    var dist = distance(pixel, center);
    var invDist = 100 / dist;
    var light = min(invDist, 1);
    color = (light, light, light, 1f);
    fill();
});

// 1.Your polygon is the entire screen now
// 2.We using a currying operation. Now render has the
// first parameter fixed on Polygons.Screen
// this is interesting because create a polygon on OnRender
// can produce wrong behaviours or performance loss
// 3.We make the operation in OnLoad to grant that the Screen
// already be initialized when the polygon is created.
// In other case we can do myRender = myRender(Polygons.Rect(200, 200))
// outside OnLoad function.
Window.OnLoad += () => myRender = myRender(Polygons.Screen);
Window.OnRender += () => myRender();

Window.CloseOn(Input.Escape);
Window.Open();

Get FPS

using Radiance;
using Radiance.Windows;
using static Radiance.Utils;

// use custom measurer
// window size 10 = most stable and slow update speed values
// The default Window.Fps use window 1
var measurer = new FrameMeasurer(10);
Window.AddMeasurer(measurer);

var myRender = render(() => {
    zoom(100);
    centralize();
    color = red;
    fill();
});

Window.OnRender += () => myRender(Polygons.Square);

Window.OnFrame += () => Console.WriteLine($"{Window.Fps} {measurer}");

Window.CloseOn(Input.Escape);
Window.Open();

Work with text easily

using Radiance;
using static Radiance.Utils;

var photo = Textures.Open("photo.png");

var myRender = render((img photo) =>
{
    color = texture(photo, x * photo.xratio, y * photo.yratio);
    fill();
});

Window.OnRender += () => myRender(Polygons.Screen, photo);

Window.CloseOn(Input.Escape);
Window.Open();

Create amazing effect handling textures

using Radiance;
using Radiance.Primitives;
using static Radiance.Utils;

var photo = Textures.Open("photo.png");

var myRender = render((img photo, vec2 cursor, val lastClick) =>
{
    var time = t - lastClick;
    var bouceForce = 1 / (1 + t - lastClick);
    var force = 30 * sin(10 * t) * bouceForce * bouceForce * bouceForce;
    var d = distance(cursor, (x, y)) + 100;
    var dx = cursor.x - x;
    var dy = cursor.y - y;
    color = texture(
        photo,
        x * photo.xratio + force * dx / d,
        y * photo.yratio + force * dy / d
    );
    fill();
});

float lastClk = 0;
Vec2 cursor = (0, 0);
Window.OnMouseMove += p => cursor = p;
Window.OnMouseDown += b => lastClk = Clock.Shared.Time;
Window.OnRender += () => myRender(Polygons.Screen, photo, cursor, lastClk);

Window.CloseOn(Input.Escape);
Window.Open();

Versions

Radiance v3.1.0 (Coming soon)

  • alternate text is missing from this package README image Added triangulation of non-monotone polygons.
  • alternate text is missing from this package README image Added text buffers allowing draw texts easily.
  • alternate text is missing from this package README image Improve polygon initialize to avoid bugs when a polygon is created on OnRender.
  • alternate text is missing from this package README image Improve variable generation name to improve shader reutilization.
  • alternate text is missing from this package README image Avaliate dependency cycles on GLSLGenerator.

Radiance v3.0.1

  • alternate text is missing from this package README image Update OpenTK version to 4.9.3.
  • alternate text is missing from this package README image Improve the logic of changes calculation.
  • alternate text is missing from this package README image Fix bugs on currying and sub render call.
  • alternate text is missing from this package README image Fix Fps bug when app start.
  • alternate text is missing from this package README image Fix the changes bug that occurs if the last edited value.

Radiance v3.0.0

  • alternate text is missing from this package README image Now, renders can be called insine another shaders.
  • alternate text is missing from this package README image Add Vsync property on Window object to activate OpenGL Vsync.
  • alternate text is missing from this package README image Add abstractions to create animations on shaders.
  • alternate text is missing from this package README image Add more primitives to draw, like line and point.
  • alternate text is missing from this package README image Use of many buffer has parameters for renders is allowed.
  • alternate text is missing from this package README image Move RenderKit content to Utils with more renders.
  • alternate text is missing from this package README image Add more functions like rand and noise.
  • alternate text is missing from this package README image Added Scissor Test compatibility.
  • alternate text is missing from this package README image Add a Pipeline abstraction to speedup render by the union of Render objects in less calls.
  • alternate text is missing from this package README image Improve on internal abstractions and some break changes. Make Radiance more extensible.
  • alternate text is missing from this package README image Improve Window abstaction and configuration.
  • alternate text is missing from this package README image Refactor the entire buffer abstraction.
  • alternate text is missing from this package README image Now, Shader Dependencies can generate code and add other dependencies on shader generation.
  • alternate text is missing from this package README image Polygon very simplified and immutable every time.
  • alternate text is missing from this package README image Use instancing has a default method of drawing.
  • alternate text is missing from this package README image Fix a bug when we try to use dt in OnFrame and close the program abruptly.
  • alternate text is missing from this package README image Fix a bug when we try to draw many types of primitives on sabe render.
  • alternate text is missing from this package README image Remove some features on Polygon simplifying the abstraction.

Radiance v2.4.0

  • alternate text is missing from this package README image Improve the use of OpenGL Primitives to improve some operations.
  • alternate text is missing from this package README image Improve the agregation of many poligons in a unique GPU call.
  • alternate text is missing from this package README image Improve triangulation to avoid fail in more polygons.

Radiance v2.3.1 (current)

  • alternate text is missing from this package README image Fix a bug when we use 3d points and make a trinagulation.
  • alternate text is missing from this package README image Improve WindowClosedException message.
  • alternate text is missing from this package README image Add vw and vh property in Utils class to get the real number of pixel of screen.

Radiance v2.3.0

  • alternate text is missing from this package README image Fix a bug when we use x, y, z Utilities to replace pos property and we lose the BufferDependence reference.
  • alternate text is missing from this package README image Improve the diversity of operations using VecN objects.
  • alternate text is missing from this package README image Add currying using float arrays.
  • alternate text is missing from this package README image Now cursor starts in Normal Visible mode.
  • alternate text is missing from this package README image Add more render function overloads.

Radiance v2.2.0

  • alternate text is missing from this package README image Clock object to easy management of time.
  • alternate text is missing from this package README image Add Draw function in Render Kit.

Radiance v2.1.2

  • alternate text is missing from this package README image Fix a bug when render call renderization implementations with one parameter less instead make curry operation.
  • alternate text is missing from this package README image Fix a bug when the render functions is callend outside OnRender event showing the incorrect message error.

Radiance v2.1.1

  • alternate text is missing from this package README image Add More properties in Utils class.
  • alternate text is missing from this package README image Fix bug in tuple convention.
  • alternate text is missing from this package README image Fix bug in Rect function.

Radiance v2.0.0

  • alternate text is missing from this package README image Add Release Shaders to speedup production apps.
  • alternate text is missing from this package README image Add Conditional Rendering.
  • alternate text is missing from this package README image Enable Currying in renders.
  • alternate text is missing from this package README image Create Data Providers to increase the power of data structures.
  • alternate text is missing from this package README image New shader programming syntax.
  • alternate text is missing from this package README image Replace old Renders by a new and most powerfull Render abstraction.
  • alternate text is missing from this package README image Replace old Data abstraction by Polygon class and Vecs.
  • alternate text is missing from this package README image Improve generate code legibility and expression reuse.
  • alternate text is missing from this package README image Improve abstraction of shaders to improve and organization.
  • alternate text is missing from this package README image Solving bugs in triangularization.
  • alternate text is missing from this package README image Remove old ShaderFunctions, Types and Data abstractions.

Radiance v1.9.0

  • alternate text is missing from this package README image Active Blending.
  • alternate text is missing from this package README image Add texture system and multi-texture system.
  • alternate text is missing from this package README image Add more radiance utils elements.
  • alternate text is missing from this package README image Added Triangularization algorithms for x-monotone polygons.
  • alternate text is missing from this package README image Add a Zero time to know the DateTime of initial t field in RadianceUtils.
  • alternate text is missing from this package README image Update OpenTK version to 4.8.2.
  • alternate text is missing from this package README image Disable some warning from base code.
  • alternate text is missing from this package README image Solve bugs to improve reutilization of shaders and programns.
  • alternate text is missing from this package README image Solve bugs on float value string format in the code generation.
  • alternate text is missing from this package README image Solved bug that crash the shader when we use a gfloat multiple times in the FragmentShader.

Radiance v1.5.0

  • alternate text is missing from this package README image Hide Cursor Feature.
  • alternate text is missing from this package README image Add system to add and remove render functions.
  • alternate text is missing from this package README image Create a class BaseData : IData to simplify IData's implementations.
  • alternate text is missing from this package README image Change all structure about RenderFunctions and introduce a IRender interface to all renders and create a RenderQueue.
  • alternate text is missing from this package README image Create system to improve data administration and replace old system of data management.
  • alternate text is missing from this package README image Now, change data not affect the draw and data become imutable again. In next versions, Radiance will provide new ways to talk with data and the they changes.
  • alternate text is missing from this package README image Improve performance of Data Structures.

Radiance v1.4.0

  • alternate text is missing from this package README image Program reusing if shaders are same in diferent draw calls.
  • alternate text is missing from this package README image Rect and Ellip shafe functions in RadianceUtils.
  • alternate text is missing from this package README image Global system types updates.

Radiance v1.3.0

  • alternate text is missing from this package README image Cursor input events added.
  • alternate text is missing from this package README image Improve use of data turning into a mutable data and avoid regenerating buffer if the data not change.
  • alternate text is missing from this package README image Improve use of OpenGL resources and reutilizations.
  • alternate text is missing from this package README image Add modifier systems to keyboard input.
  • alternate text is missing from this package README image Improve Verbose mode outputs.

Radiance v1.2.0

  • alternate text is missing from this package README image 'dt' Delta time variable and fps control.
  • alternate text is missing from this package README image Global variables system

Radiance v1.1.0

  • alternate text is missing from this package README image Colored Vectors data type added.
  • alternate text is missing from this package README image Auto outputs and inputs betwen Shader Pipeline.
  • alternate text is missing from this package README image Data System Reworked.
  • alternate text is missing from this package README image More itens in Radiance Utils.

Radiance v1.0.0

  • alternate text is missing from this package README image Window static Class to manage screen
  • alternate text is missing from this package README image Shader object system that can converts C# to GLSL
  • alternate text is missing from this package README image Data Types like Vector, Vectors, and transformed types.
  • alternate text is missing from this package README image Methods FillTriangles and Draw (Line Loop) in render functions.
  • alternate text is missing from this package README image Many functions of GLSL like cos, sin distance, round, smoothstep and others...
  • alternate text is missing from this package README image RadianceUtils static class with all util operations and data.
  • alternate text is missing from this package README image Dependece system with auto add uniforms and variables like width, heigth and the time in the app (named t) to use in implementations.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Radiance:

Package Downloads
TheGarden

Package Description

PuzzleArena

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 191 12/28/2024
3.0.0 116 12/28/2024
3.0.0-rc1 104 12/25/2024
3.0.0-preview4 124 12/24/2024
3.0.0-preview3 99 12/8/2024
3.0.0-preview2 120 11/3/2024
3.0.0-preview1 98 10/28/2024
2.3.1 186 2/19/2024
2.3.0 170 2/17/2024
2.2.0 167 2/4/2024
2.1.2 149 2/1/2024
2.1.1 141 1/30/2024
2.0.0 136 1/29/2024
1.9.0 185 1/10/2024
1.5.0 189 9/6/2023
1.4.0 192 8/30/2023
1.3.0 192 8/24/2023
1.2.0 181 8/22/2023
1.1.0 181 8/21/2023
1.0.0 172 8/16/2023