master
Miloslav Ciz 2 years ago
parent f96124b085
commit 93ed05f715

@ -31,9 +31,51 @@ The normalization is basically the only thing you have to think about, apart fro
Remember to **always use a power of two scaling factor** -- this is crucial for performance. I.e. you want to count 1/2th, 1/4th, 1/8ths etc., but NOT 1/10ths, as might be tempting. Why are power of two good here? Because computers work in binary and so the normalization operations with powers of two (division and multiplication by the scaling factor) can easily be optimized by the compiler to a mere [bit shift](bit_shift.md), an operation much faster than multiplication or division.
## Implementation Example
## Code Example
The following is an example of a simple [C](c.md) program using fixed point with 10 fractional bits, computing [square roots](sqrt.md) of numbers from 0 to 10.
For start let's compare basic arithmetic operations in [C](c.md) written with floating point and the same code written with fixed point. Consider the floating point code first:
```
float
a = 21,
b = 3.0 / 4.0,
c = -10.0 / 3.0;
a = a * b; // multiplication
a += c; // addition
a /= b; // division
a -= 10; // subtraction
a /= 3; // division
printf("%f\n",a);
```
Equivalent code with fixed point may look as follows:
```
#define UNIT 1024 // our "1.0" value
int
a = 21 * UNIT,
b = (3 * UNIT) / 4, // note the brackets, (3 / 4) * UNIT would give 0
c = (-10 * UNIT) / 3;
a = (a * b) / UNIT; // multiplication, we have to normalize
a += c; // addition, no normalization needed
a = (a * UNIT) / b; // division, normalization needed, note the brackets
a -= 10 * UNIT; // subtraction
a /= 3; // division by a number NOT in UNITs, no normalization needed
printf("%d.%d%d%d\n", // writing a nice printing function is left as an exercise :)
a / UNIT,
((a * 10) / UNIT) % 10,
((a * 100) / UNIT) % 10,
((a * 1000) / UNIT) % 10);
```
These examples output `2.185185` and `2.184`, respectively.
Now consider another example: a simple [C](c.md) program using fixed point with 10 fractional bits, computing [square roots](sqrt.md) of numbers from 0 to 10.
```
#include <stdio.h>

@ -2,11 +2,11 @@
*Information wants to be free.*
Free (as in freedom) culture is a movement aiming for the relaxation of [intellectual property](intellectual_property.md) restrictions, mainly that of [copyright](copyright.md), to allow free usage, reusing and sharing of [artworks](art.md) and other kind of [information](information.md). Free culture argues that our society has gone too far in forcefully restricting the natural freedom of information by very strict laws (e.g. by authors holding copyright even 100 years after their death) and that we're hurting art, creativity, education and progress by continuing to strengthen restrictions on using, modifying ([remixing](remix.md)) and sharing things like [books](book.md), [music](music.md) and scientific papers. The word "free" in free culture refers to freedom, not price!
Free (as in freedom) culture is a movement aiming for the relaxation of [intellectual property](intellectual_property.md) restrictions, mainly that of [copyright](copyright.md), to allow free usage, reusing and sharing of [artworks](art.md) and other kind of [information](information.md). Free culture argues that our society has gone too far in forcefully restricting the natural freedom of information by very strict laws (e.g. by authors holding copyright even 100 years after their death) and that we're hurting art, creativity, education and progress by continuing to strengthen restrictions on using, modifying ([remixing](remix.md)) and sharing things like [books](book.md), [music](music.md) and scientific papers. The word "free" in free culture refers to freedom, not just price -- free cultural works have to be more than just available gratis, they must also give its users some specific legal rights. Nevertheless free culture itself isn't against commercialization of art, it just argues for rather doing so by other means than selling legal rights to it.
The promoters of free culture want to relax intellectual property laws ([copyright](copyright.md), [patents](patent.md), [trademarks](tm.md) etc.) but also promote an ethic of sharing and remixing being good (as opposed to the demonizing anti-"[piracy](piracy.md)" propaganda of today), they sometimes mark their works with words **"some rights reserved"**, as opposed to the traditional "all rights reserved".
The promoters of free culture want to relax intellectual property laws ([copyright](copyright.md), [patents](patent.md), [trademarks](tm.md) etc.) but also promote an ethic of sharing and remixing being good (as opposed to the demonizing anti-"[piracy](piracy.md)" propaganda of today), they sometimes mark their works with words **"some rights reserved"** or even "no rights reserved", as opposed to the traditional "all rights reserved".
Free culture is kind of a sister movement to the **[free software](free_software.md)** movement, in fact it has been inspired by it (we could call it its [fork](fork.md)). While free software movement, established in 1983, was only concerned with freedoms relating to computer program source code, free culture later (around 2000) took its ideas and extended them to all information including e.g. artworks and scientific data. There are **clearly defined criteria** for a work to be considered free (as in freedom) work, i.e. part of the body of free cultural works. The criteria are very similar to those of free software (the definition is at https://freedomdefined.org/Definition) and can be summed up as follows:
Free culture is kind of a younger sister movement to the **[free software](free_software.md)** movement, in fact it has been inspired by it (we could call it its [fork](fork.md)). While free software movement, established in 1983, was only concerned with freedoms relating to computer program source code, free culture later (around 2000) took its ideas and extended them to all information including e.g. artworks and scientific data. There are **clearly defined criteria** for a work to be considered free (as in freedom) work, i.e. part of the body of free cultural works. The criteria are very similar to those of free software (the definition is at https://freedomdefined.org/Definition) and can be summed up as follows:
A free cultural work must allow anyone to (legally and practically):
@ -17,13 +17,13 @@ A free cultural work must allow anyone to (legally and practically):
Some of these conditions may e.g. further require a source code of the work to be made available (e.g. sheet music, to allow studying and modification). Some conditions may however still be imposed, as long as they don't violate the above -- e.g. if a work allows all the above but requires crediting the author, it is still considered free (as in freedom). [Copyleft](copyleft.md) (also share-alike, requirement of keeping the license for derivative works) is another condition that may be required. This means that many (probably most) free culture promoters actually rely and even support the concept of e.g. copyright, they just want to make it much less strict.
It was in 2001 when **[Lawrence Lessig](lessig.md)**, an American lawyer who can be seen as the movement's founder, created the **[Creative Commons](creative_commons.md)**, a non-profit organization which stands among the foundations of the movement as is very much connected to it. By this time he was already educating people about the twisted intellectual property laws and had a few followers. Creative Commons would create and publish a set of [licenses](license.md) that anyone could use to release their works under much less restrictive conditions than those that lawfully arise by default. For example if someone creates a song and releases it under the [CC-BY](cc_by.md) license, he allows anyone to freely use, modify and share the song as long as proper attribution is given to him. It has to be noted that **NOT all Creative Commons licenses are free culture** (those with NC and ND conditions break the above given rules)! It is also possible to use other, non Creative Commons licenses in free culture, as long as the above given criteria are respected.
It was in 2001 when **[Lawrence Lessig](lessig.md)**, an American lawyer who can be seen as the movement's founder, created the **[Creative Commons](creative_commons.md)**, a non-profit organization which stands among the foundations of the movement and is very much connected to it. By this time he was already educating people about the twisted intellectual property laws and had a few followers. Creative Commons would create and publish a set of [licenses](license.md) that anyone could use to release their works under much less restrictive conditions than those that lawfully arise by default. For example if someone creates a song and releases it under the [CC-BY](cc_by.md) license, he allows anyone to freely use, modify and share the song as long as proper attribution is given to him. It has to be noted that **NOT all Creative Commons licenses are free culture** (those with NC and ND conditions break the above given rules)! It is also possible to use other, non Creative Commons licenses in free culture, as long as the above given criteria are respected.
In 2004 Lessig published his **book** called Free Culture that summarized the topic as well as proposed solutions -- the book itself is shared under a Creative Commons license and can be downloaded for free (however the license is among the non-free CC licenses so the book itself is not part of free culture [lmao](lmao.md), big fail by Lessig).
{ I'd recommend reading the Free Culture book to anyone whose interests lie close to free culture/software, it's definitely something you should start with. ~drummyfish }
{ I'd recommend reading the Free Culture book to anyone whose interests lie close to free culture/software, it's definitely one of the essential works. ~drummyfish }
In the book Lessig gives an overview of the history of copyright -- it has been around since about the time of invention of [printing press](printing_press.md) to give some publishers exclusive rights (an artificial [monopoly](monopoly.md)) for printing and publishing certain books. The laws evolved but at first were not so restrictive, they only applied to very specific uses (printing) and for limited time, plus the copyright had to be registered. Over time corporations pressured to make it more and more restrictive -- nowadays copyright applies to basically everything and lasts for 70 years AFTER the death of the author (!!!). This is combined with the fact that in the age of computers any use of information requires making a copy (to read something you need to download it), i.e. copyright basically applies to ANY use now. I.e. both scope and term of copyright have been extended to the extreme, and this was done even AGAINST the US constitution -- Lessig himself tried to fight against it in court but lost. This form of copyright now restricts culture and only helps corporations who want to e.g. **kill the [public domain](public_domain.md)** (works that run out of copyright and are now "free for everyone") by repeatedly prolonging the copyright term so that people don't have any pool of free works that would compete (and often win simply by being gratis) with the corporate created "content". In the books Lessig also mentions many hard punishments for breaking copyright laws and a lot of other examples of corruption of the system. He then goes on to propose solutions, mainly his Creative Commons licenses.
In the book Lessig gives an overview of the history of copyright -- it has been around since about the time of invention of [printing press](printing_press.md) to give some publishers exclusive rights (an artificial [monopoly](monopoly.md)) for printing and publishing certain books. The laws evolved but at first were not so restrictive, they only applied to very specific uses (printing) and for limited time, plus the copyright had to be registered. Over time corporations pressured to make it more and more restrictive -- nowadays copyright applies to basically everything and lasts for 70 years AFTER the death of the author (!!!). This is combined with the fact that in the age of computers any use of information requires making a copy (to read something you need to download it), i.e. copyright basically applies to ANY use now. I.e. both scope and term of copyright have been extended to the extreme, and this was done even AGAINST the US constitution -- Lessig himself tried to fight against it in court but lost. This form of copyright now restricts culture and basically only serves corporations who want to e.g. **kill the [public domain](public_domain.md)** (works that run out of copyright and are now "free for everyone") by repeatedly prolonging the copyright term so that people don't have any pool of free works that would compete (and often win simply by being gratis) with the corporate created "content". In the books Lessig also mentions many hard punishments for breaking copyright laws and a lot of other examples of corruption of the system. He then goes on to propose solutions, mainly his Creative Commons licenses.
Free culture has become a relative success, the free Creative Commons licenses are now widely used -- e.g. **[Wikipedia](wikipedia.md) is part of free** culture under the [CC-BY-SA](cc_by_sa.md) license and its sister project [Wikimedia Commons](wm_commons.md) hosts over 80 million free cultural works! There are famous promoters of free culture such as [Nina Paley](nina_paley.md), webcomics, books, songs etc. In development of libre [games](game.md) free cultural licenses are used (alongside free software licenses) to liberate the game assets -- e.g. the [Freedoom](freedoom.md) project creates free culture content replacement for the game [Doom](doom.md). There are whole communities such as [opengameart](oga.md) or Blendswap for sharing free art, even sites with completely public domain stock photos, vector images, music and many other things. Many scientists release their data to public domain under [CC0](cc0.md). And of course, [LRS](lrs.md) highly advocated free culture, specifically [public domain](public_domain.md) under [CC0](cc0.md).

@ -4,7 +4,7 @@ WELCOME TRAVELER
{ Don't hesitate to contact me. ~drummyfish }
Are you tired of [bloat](bloat.md) and can't stand [shitty](shit.md) software like [Windows](windows.md) anymore? Do you hate [capitalism](capitalism.md)? Do you also hate the [fascist alternatives](tranny_software.md) you're being offered? Do you just want to create a genuinely good technology without [bullshit](bullshit.md) that would help all people? Do you just want to share knowledge freely without [censorship](censorship.md)? You have come to the right place.
Are you tired of [bloat](bloat.md) and can't stand [shitty](shit.md) software like [Windows](windows.md) anymore? Do you hate [capitalism](capitalism.md)? Do you also hate the [fascist alternatives](tranny_software.md) you're being offered? Do you just want to create a genuinely good [bullshitless](bullshit.md) technology that would help all people? Do you just want to share knowledge freely without [censorship](censorship.md)? You have come to the right place.
Firstly let us welcome you, no matter who you are, no matter your political opinions, your past and your skills, we are glad to have you here. Remember, you don't have to be a programmer to help and enjoy LRS. LRS is a lifestyle, a philosophy. Whether you are a programmer, artist, educator or just someone passing by, you are welcome, you may enjoy our culture and its fruit and if you want, you can help enrich it.

@ -8,7 +8,7 @@ Also if can somehow rip off a rich corporation and get some money for yourself,
**Is programming software the only way to make money with LRS?** No, you can do anything related to LRS and you don't even have to know [programming](programming.md). You can create [free](free_culture.md) art such as [game](game.md) assets or writings, you can educate, write articles etc.
## Making Money With FOSS
## Making Money With "FOSS"
For inspiration we can take a look at traditional ways of making money in FOSS, even if a lot of them may be unacceptable for us as the business of the big FOSS is many times not so much different from the business of big tech corporations.
@ -16,7 +16,7 @@ With [open source](open_source.md) it is relatively easy to make money and earn
Working for [free software](free_software.md) organizations such as the [FSF](fsf.md) is a better way of making living, even though still not perfect: FSF has been facing some criticism of growing corruption and from the [LRS](lrs.md) point of view they do not address many issues of software such as [bloat](bloat.md), [public domain](public_domain.md) etc.
## Way of Making Money With LRS
## Way Of Making Money With LRS
Considering all things mentioned above, here are some concrete things of making money on LRS. Keep in mind that a lot of services (PayPal, Patreon etc.) listed here may possibly be [proprietary](proprietary.md) and unethical, so always check them out and consider free alternatives such as [Liberapay](liberapay.md). The methods are following:

@ -2,7 +2,7 @@
*Love everyone, help [selflessly](selflessness.md).*
Welcome to [Less Retarded Wiki](lrs_wiki.md), an encyclopedia only I can edit. But you can [fork](fork.md) it, it is [public domain](public_domain.md) under [CC0](cc0.md) (see [wiki rights](wiki_rights.md)) :) Holy [shit](shit.md), I'm gonna get [canceled](cancel_culture.md) hard as soon as [SJWs](sjw.md) find out about this. Until then, let's enjoy the ride. THERE'S NO [MODERATION](moderation.md), I can do whatever I want here lol. I love this.
Welcome to [Less Retarded Wiki](lrs_wiki.md), an encyclopedia only I can edit. But you can [fork](fork.md) it, it is [public domain](public_domain.md) under [CC0](cc0.md) (see [wiki rights](wiki_rights.md)) :) Holy [shit](shit.md), I'm gonna get [cancelled](cancel_culture.md) hard as soon as [SJWs](sjw.md) find out about this. Until then, let's enjoy the ride. THERE'S NO [MODERATION](moderation.md), I can do whatever I want here lol. I love this.
This is a Wiki for [less retarded software](lrs.md) (LRS) and related topics, mainly those of [politics](politics.md) and [society](society.md), idealization of which LRS should help achieve. LRS Wiki is a new, refreshing wiki without [political correctness](political_correctness.md).
@ -12,7 +12,7 @@ This wiki is **NOT** a satire.
{ I no longer see any good in this world. This is my last attempt at preserving pure good, however at this point I am alone, it's just for myself in my completely isolated world. Perhaps my love will be shared with a reader far away, in space or time, even if I will never know him. This is the only way I can continue living. I wish you happy reading, my dear friend. ~drummyfish }
**Before contributing please read the [rules & style](wiki_style.md)!** {But contributions aren't really accepted RN :) ~drummyfish }
**Before contributing please read the [rules & style](wiki_style.md)! By contributing you agree to release your contribution under our [waiver](wiki_rights.md).** {But contributions aren't really accepted RN :) ~drummyfish }
We have a **[C tutorial](c_tutorial.md)**! It [rocks](rock.md).

@ -0,0 +1,45 @@
# Raycasting
In [computer graphics](graphics.md) raycasting refers to a rendering technique in which we determine which parts of the scene should be drawn according to which parts of the scene are hit by rays cast from the camera. This is based on the idea that we can trace rays of light that enter the camera by going backwards, i.e. starting from the camera towards the parts of the scene that reflected the light. The term raycasting specifically has two main meanings:
- **[3D](3d.md) raycasting**: [Algorithm](algorithm.md) that works the same as [raytracing](raytracing.md) but without [recursion](recursion.md). I.e. raycasting is simpler than raytracing and only casts primary rays (those originating from the camera), hence, unlike in raytracing, there are no shadows, reflections and refractions. Raytracing is the extension of raycasting.
- **[2D](2d.md) raycasting**: Technique for rendering so called "[pseudo3D](pseudo3D.md)" (primitive 3D) graphics, probably best known from the old [game](game.md) Wolf3D (predecessor of [Doom](doom.md)). The principle of casting the rays is the same but we only limit ourselves to casting the rays within a single 2 dimensional plane and render the environemnt by columns (unlike the 3D variant that casts rays and renders by individual pixels).
## 2D Raycasting
We have an official [LRS](lrs.md) library for advanced 2D raycasting: [raycastlib](raycastlib.md)! And also a game built on top of it: [Anarch](anarch.md).
2D raycasting can be used to relatively easily render "3Dish" looking environments (this is commonly labeled "[pseudo3D](pseudo3D.md)"), mostly some kind of right-angled labyrinth. There are limitations such as the inability for the camera to tilt up and down (which can nevertheless be faked with shearing). It used to be popular in very old games but can still be used nowadays for "retro" looking games, games for very weak hardware (e.g. [embedded](embedded.md)), in [demos](demoscene.md) etc. It is pretty cool, very [suckless](suckless.md) rendering method.
TODO: image
The method is called *2D* because even though the rendered picture looks like a 3D view, the representation of the world we are rendering is 2 dimensional (usually a grid, a top-down plan of the environment with cells of either empty space or walls) and the casting of the rays is performed in this 2D space -- unlike with the 3D raycasting which really does cast rays in fully 3D environments. Also unlike with the 3D version which casts one ray per each rendered pixel (x * y rays per frame), 2D raycasting only casts **one ray per rendered column** (x rays per frame) which actually, compared to the 3D version, drastically reduces the number of rays cast and makes this method **fast enough for [real time](real_time.md)** rendering even using [software_rendering](sw_rendering.md) (without a GPU).
The principle is following: for each column we want to render we cast a ray from the camera and find out which wall in our 2D world it hits first and at what distance -- according to the distance we use [perspective](perspective.md) to calculate how tall the wall columns should look from the camera's point of view, and we render the column. Tracing the ray through the 2D grid representing the environment can be done relatively efficiently with algorithms normally used for line rasterization. There is another advantage for weak-hardware computers: we can easily use 2D raycasting **without a [framebuffer](framebuffer.md)** (without [double_buffering](double_buffering.md)) because we can render each frame top-to-bottom left-to-right without overwriting any pixels (as we simply cast the rays from left to right and then draw each column top-to-bottom). And of course, it can be implemented using [fixed point](fixed_point.md) (integers only).
The classic version of 2D raycasting -- as seen in the early 90s games -- only renders walls with [textures](texture.md); floors and ceilings are untextured and have a solid color. The walls all have the same height, the floor and ceiling also have the same height in the whole environment. In the walls there can be sliding doors. 2D sprites ([billboards](billboard.md)) can be used with raycasting to add items or characters in the environment -- for correct rendering here we usually need a 1 dimensional [z-buffer](z_buffer.md) in which we write distances to walls to correctly draw sprites that are e.g. partially behind a corner. However we can **extend** raycasting to allow levels with different heights of walls, floor and ceiling, we can add floor and ceiling texturing and, in theory, probably also use different level geometry than a square grid (however at this point it would be worth considering if e.g. [BSP](bsp.md) rendering wouldn't be better).
### Implementation
The core element to implement is the code for casting rays, i.e. given the square plan of the environment (e.g. game level), in which each square is either empty or a wall (which can possibly be of different types, to allow e.g. different textures), we want to write a function that for any ray (defined by its start position and direction) returns the information about the first wall it hits. This information most importantly includes the distance of the hit, but can also include additional things such as the type of the wall or its direction (so that we can [shade](shading.md) differently facing walls with different brightness for better realism). The environment is normally represented as a 2 dimensional [array](array.md), but we can also use e.g. a function that [procedurally](procgen.md) generates infinite levels. For the algorithm for tracing the ray in the grid we may actually use some kind of line [rasterization](rasterization.md) algorithm, e.g. the [DDA](dda.md) algorithm (tracing a line through a grid is analogous to drawing a line in a pixel grid). This can all be implemented with [fixed point](fixed_point.md), i.e. integer only! No need for [floating point](float.md).
**Note on distance calculation and distortion**: When computing the distance of ray hit from the camera, we usually DO NOT want to use the [Euclidean](euclidean.md) distance of that point from the camera position (as is tempting) -- that would create a so called fish eye effect, i.e. looking straight into a perpendicular wall would make the wall looked warped/bowled (as the part of the wall in the middle of the screen is actually closer to the camera position so it would, by perspective, look bigger). For non-distorted rendering we have to compute the perpendicular distance of the hit point from the camera plane -- we can see the camera plane as a "canvas" onto which we project the scene, in 2D it is a line (unlike in 3D where it really is a plane) in front of the camera at a constant distance (usually conveniently chosen to be 1) from the camera position whose direction is perpendicular to the direction the camera is facing. The good news is that with a little trick this distance can be computed even more efficiently than Euclidean distance, as we don't need to compute a square root! Instead we can utilize the similarity of triangles. Consider the following situation:
```
d
/ .x
/ r.'/|
'-._ / ,' / |
P '-c_.' / |
/,'|-.e |
/' | |
V----a------b
```
In the above *V* is the position of the camera (viewer) which is facing towards the point *d*, *P* is the camera plane perpendicular to *Vd* at the distance 1 from *V*. Ray *r* is cast from the camera and hits the point *x*. The length of the line *r* is the Euclidean distance, however we want to find out the distance *ex = cd*, which is perpendicular to *P*. There are two similar triangles: *Vca* and *Vdb*; from this it follows that *1 / Va = (1 + cd) / Vb*, from which we derive that *cd = Vb / Va - 1*. This can be used to calculate the perpendicular distance just from the ratio of the distances along principal axes (i.e. along axis X or Y). However watch out for the case when *Va = Vb = 0* to not divide by zero! In such case use the other principal axis (Y).
{ I hope the above is correct lol. ~drummyfish}
TODO: code

@ -2,6 +2,6 @@
*If this is the solution, I want my problem back.*
Systemd is a pretty bad, [bloated](bloat.md), [anti-Unix](unix_philosophy.md), [free-licensed](free_software.md) "software suite" used for initialization of an [operating system](os.md) and handling services like loggging in or managing network connections. It is a so called [PID 1](pid1.md) process. Systemd has been highly criticised by the proponents of [suckless](suckless.md) and [LRS](lrs.md) and even normies for its bloat, anti-Unix-philosophy design, [feature creep](feature_creep.md), security vulnerabilities and other stuff. Unfortunately it is being adopted by many [Linux](linux.md) distributions including [Arch Linux](arch.md) and [Debian](debian.md).
Systemd is a pretty bad, [bloated](bloat.md), [anti-Unix](unix_philosophy.md), [free-licensed](free_software.md) "software suite" used for initialization of an [operating system](os.md) and handling services like loggging in or managing network connections. It is a so called [PID 1](pid1.md) process. Systemd has been highly criticised by the proponents of [suckless](suckless.md) and [LRS](lrs.md) and even normies for its bloat, anti-Unix-philosophy design, [feature creep](feature_creep.md), security vulnerabilities and other stuff. Unfortunately it is being adopted by many [GNU](gnu.md)/[Linux](linux.md) distributions including [Arch Linux](arch.md) and [Debian](debian.md).
For more detailed bashing of systemd see e.g. https://nosystemd.org/.
Loading…
Cancel
Save