![]() |
[WIP] Using Lights to make any Image using only scripting - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +--- Thread: [WIP] Using Lights to make any Image using only scripting (/thread-10891.html) |
Using Lights to make any Image using only scripting - Apjjm - 10-21-2011 This isn't exactly going to be a tutorial just yet. Rather, a WIP tutorial ![]()
Spoiler below!
However, the final goal was to have an image stored in as little text as possible in my script file, and to then display it on the screen! All I needed to do here was to turn an image into a series of commands above, and supply an alphabet and token size. Luckily, this isn't too hard, and one quick program in c# later i have an image generator, and a few functions (and a few hours debugging ![]() Spoiler below!
Spoiler below!
After I finish tweaking a few things, and finish documenting the newest functions I'll be posting the tools up and a tutorial on how to use the scripting commands. If you can't wait though, here's the amnesia scripting stuff minus the image loading shenanigans - note that this was designed with the updated notepad++ files which can be found here Encoding functions HPS file: Mediafire D/L RE: Using Lights to make any Image using only scripting - Kman - 10-21-2011 YOU ARE A GOD RE: Using Lights to make any Image using only scripting - palistov - 10-21-2011 I smell an incoming new project...Minecraft: The Dark Descent? RE: Using Lights to make any Image using only scripting - Acies - 10-21-2011 Oh my god. Really cool. RE: Using Lights to make any Image using only scripting - Apjjm - 10-21-2011 Today I adjusted the system to fix a small bug and support colours. Still need to improve the int encoding routine, but pictures only require UINTs so that is low on the list of fixes right now. I also recorded a stress test with a picture using 10k lights, unsurprisingly this lagged a little bit - but it worked and looks really cool. I had to write a timer which drew half a column at a time so I could be sure the game didn't crash! If you are interested in the string that was generated for this picture: http://pastebin.com/D9yC3gbF Using the alphabet: Code: string alphabet = " !()*+,-.0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz{|}"; So, as it is, it really is only feasible for small images with less than 2k lights - but that was kind of obvious from the start. RE: Using Lights to make any Image using only scripting - Your Computer - 10-21-2011 LOL, that is epic! I saw the source code, but i was too lazy to study it, so i'll ask this here: Is the "image" size (lights boundary) based on a primitive plane, or is the dimensions of the original image being translated and adjusted in game? Also, are you able to specify the size of each pixel (light)? RE: Using Lights to make any Image using only scripting - Apjjm - 10-21-2011 To answer your question I guess I can just go for the full explanation as to how the approach is done currently: (Released Part) The decoder & Encoder This stage, as described in the first post just encodes values according to an alphabet. The "tSize" parameter represents the size of a "token" used per uint (or no. of characters of the alphabet used per uint). For example, if I were to use the hex alphabet "0123456789ABCDEF" and a tSize of 4, i'd be able to represent the numbers from "0000" to "FFFF". Each UINT will always be stored with a total tSize characters from the input alphabet so that it is actually possible to decode. Ints, Strings and Floats are just stored as UINTS with extra information / a different interpretation. At this stage we have the decoder and encoder functions as linked in the top post. Ontop of this i have two unreleased c# applications: Image converter: This tool lets you load in an image and set a down-sampling factor. This is just a glorified shrinking algorithm - it takes the image, averages out the color of a square (dimensioned specified by the down-size factor) and outputs that as 1 pixel in the new image. It repeats until the new image is a downsized copy of the old one. This is necessary on larger images (but completely optional) to keep the light count under 10k (after which it becomes unbearably slow). To output this image ready for encoding the program will then convert the RGB components of the smaller image into one 32bit UINT: Code: Bits 0-7: Red Code: U42 <--- Width Command-line encoder: This tool takes a file of the form Code: <alphabet> Decoding Firstly, before any drawing occurs I decode the string into a 2D array of uints, since the first two values decoded by the string are width and height of the image, I use this to initialise the array. I then decode each set of "tSize" characters into the array. Drawing: At this stage I have a 2D array containing uints which contain the colours. To the draw the image I iterate through the array and use AddAttachedPropToProp to attach a custom variant of the "block_box" entity containing an additional box light called "light". This creates the light. I then decode the uint for this pixel into 3 floats for the color, and call FadeLightTo(boxname + "_light",...) to set it's color. The arguments for this function specify the width of the box light in the entity used to make box lights, amongst a host of other settings. This works because I have a huge plane which intersects all the lights to give them something to illuminate in the editor. Each light is currently a standard 1x1x1 cube and drawn along XY (Y-Flipped) - but there is no reason why you couldn't change this. There is no reason why you couldn't do something else with the pixel array - like compose several pictures together and then draw, or, have an array of pixel arrays for an animation. As i said, this i just an application of the encoding and decoding tools to make an image out of box lights. Unless you want it to output some kind of password (As part of a puzzle or as a save-state for episodic releases) or perform pixel based drawing and manipulation there isn't really much of a reason why you would use it for images. RE: Using Lights to make any Image using only scripting - Your Computer - 10-21-2011 That reminds me of the xbm (X BitMap) format. |