Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Bobboau on January 19, 2007, 09:10:23 am

Title: fun little toy I just made for the hell of it
Post by: Bobboau on January 19, 2007, 09:10:23 am
I've had this idea floating around for quite a while now for making a procedural texture maker, and after some of the things I've had to do over the last few weeks, I finally decided to give it a wurl.

I give you the first and posably last installment of prox (procedural proxy) the 2d function visualizer.
useing the long abandoned expression code I made years ago, before we had a scripting system, wich was promptly abandoned in favor of said scripting system, due to it being better, I have made a program that will  display any function of x and y you can type up into the three color chanels of red green and blue.

the syntax is incredibly assinine and unforgiving and is more likely to crash than simply not work if you do anything even remotely not perfect, speaking of wich it goes a little something like this
color_chanel: expression ;<-semicolon,
a beter example would be like this
red:255;
that will set the red chanel to full brightness, but making textures of a constant color is a bit boring, what you need are variables, all variables will be of the form :variablename:, I might add suport for defining your own variable later, but I don't feel like it now, as of this moment, there are four variables, upper and lower case x and y, upper case is centered in the middle of the screen, lower case is centered at the upper left han corner.

a specific example of how to use them

red:(sin((:X:^2+:Y:^2)*20)/2+.5)*255;
green:(sin((:X:^2+:Y:^2)*20+5)/2+.5)*255;
blue:(sin((:X:^2+:Y:^2)*20+10)/2+.5)*255;

note the colins and semicolins.
Title: Re: fun little toy I just made for the hell of it
Post by: Scuddie on January 19, 2007, 09:06:16 pm
Screenie?  And maybe try uploading a zip file that isnt broken?
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 12:26:28 am
the zip works fine for me...

fine, new zip, I've added polar coordanants in there as well ( :ang: :r: ) so I should update it anyway
Title: Re: fun little toy I just made for the hell of it
Post by: WMCoolmon on January 20, 2007, 02:44:26 am
If you're having trouble running the app due to missing DLL errors, try this:

http://www.microsoft.com/downloads/details.aspx?FamilyId=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en

If you're using a 64-bit version of Windows, you can find the appropriate links at the bottom.

EDIT: Hmm, I'm not getting the same results as you, apparently. How do I make mine look cool like yours?

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 03:46:52 am
well first off in your red row you put cost rather than cos, but it should still be comeing up as something semetrical.

maybe I should port this over to wx
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 04:35:05 am
made another one, these can be quite good as laser bolt textures

maybe I should post this elsewere, I'm sure the modders would be interested in this.

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Nuke on January 20, 2007, 04:39:59 am
not bad i will play with this for abit. this oddly reminds me winamp avs. which can be programmed quite well with its system. my main reason for wanting procedural textures would have to be for cockpit panels. but i still cant get that to work.

Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 04:49:51 am
I originally got the idea (and programed some of the code) when I was making a media player visualization. basicly all I have done is taken the code for setting the contents of a window to a particular color and spliced my expression code into it.

anyway...
and you shall tears of scarlet!
(experiment with trig functions of :ang: + :r:)
Title: Re: fun little toy I just made for the hell of it
Post by: WMCoolmon on January 20, 2007, 05:28:20 am
How rapidly could these calculations be performed on a 3D surface texture using the RTT functions? (Read: auto-scaling textures)
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 05:44:46 am
well the biggest slowdown seems to be from the loop or inedexing the array, humangus lines seem to take just about as long as simple ones, so I'd guess fairly fast, but I wouldn't dare do a 3d texture on the fly. but I very much have the idea of introducing a time variable and haveing the thing spit out sequences of images, that could very easily be made to also render to a surface of a 3d texture.

btw right now I'm woking on a way to define your own variables, and HSL output mode, actualy the HSL mode is coming first, but I'm keeping in mind the variables when I write it.

and I have got to change the syntax.

I'm thinking

:variable: = expression
useing '\' to denote that a endline should not be treated as the end of the expression

though using a special character would make it a lot easier, like maybe
@:variable: = expression

and

$output<RGB>{
:red:
:green:
:blue:
}

would define an output (were :red:, ect, were variables you defined)

I could probly do functions too, but they would need to use different brackets.

you know I could have sworn I had more functions defined...
Title: Re: fun little toy I just made for the hell of it
Post by: Trivial Psychic on January 20, 2007, 10:39:46 am
All this is quite beyond me, but you seem to be discussing textures that can change in game, like anis, but without needing the multiple frames of an ani or eff... is that anywhere near what this is leading to?  Is this kinda thing aiming towards being able to reproduce the pulsing glowmap effects of the Shivan fighters in adveffects, without needing the memory-hogging anis?  Just trying to cut through the code-talk and get something that I can relate to.
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 20, 2007, 11:11:32 am
no, but this could be used to make animated textures
Title: Re: fun little toy I just made for the hell of it
Post by: Nuke on January 20, 2007, 07:55:20 pm
if implemented perhaps we could use the eff files to store the expressions. i wouldnt mind this if i could pass it vars from scripting. might just get those working panels i wanted.
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 21, 2007, 04:02:02 am
no, this isn't going to get into FSO ever, maybe WMC and taylor can work together for script defined textures, but the expression code isn't powerfull enough or stable enough for use in FSO, it is fairly fast and simple though, and I'd like to have some app based on it as I think it was rather clever of me.

I have made some changes, I decided to do the user variables first, they are sort of function like in that placeing a instance variable will change it's value.

this is the new syntax, you define a bunch of variables, and then an output in wich you specify the variables to use

@R=1-:r:

@red=:R:

@green=:R:*1.1

@blue=:R:*.9

$output<rgb>{
:red:
:green:
:blue:
}

next up HSL output



[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 21, 2007, 05:50:51 am
@H=:r:/8

@S=(1-:r:)*2

@L=1-:r:

$output<hsl>{
:H:
:S:
:L:
}

I changed some settings so it links statically, is it still not working for anyone?

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: WMCoolmon on January 21, 2007, 08:05:35 pm
Still not quite working for me...

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 22, 2007, 02:49:00 am
is your screen running in 16bit mode, or anything other than 32bit mode?
Title: Re: fun little toy I just made for the hell of it
Post by: CP5670 on January 24, 2007, 01:21:16 pm
I tried out a few things with this. What ranges do the X and Y variables run over?

This needs to be used in the game itself for animations. You could use it make high resolution and detailed effects without using much memory.

Here's an interesting one around an essential singularity. Does this thing work with complex variables?

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Huggybaby on January 24, 2007, 06:42:18 pm
Quote
You could use it make high resolution and detailed effects without using much memory.
Exactly what I thought but was afraid to say.  :) Just like the Help/About screen in µTorrent.
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 24, 2007, 09:04:32 pm
most variables go in the range of 0-1,

:x:, :y:, :r:, and :t: go from 0 to 1 (:r: actualy goes to sqrt(2) in the corners)
:X: and :Y: (note capitalisation) go from -1 to 1
:ang: goes from 0 to 2*PI
note if you find this isn't how things are working it's a bug. I'm looking into something right now that makes me think :ang: might be between -PI and PI, I might keep it this way though, what do you think?
I figured these woulf be the most maliable ranges for these, cause if you wanted a function that changed, say, from -2 to  11, along lets say x, you'd just have to set a variable like this
@NEWX=:x:*13-2
and instead of :x: you'd use :NEWX:

make sure you use the most recent build (in the other thread, cause in addition to more functionality, I also fixed a bug with :ang:)
er... you know what, I'll atach the most recent version (posably more reacent than the other thread) you will still need the DLL pack from the other thread.

if this was used in game it would use just as much memory, because every frame would still need to be rendered, though it would save on download sizes. now on the other hand this could be a useful tool in comeing up with stuff for pixel shaders that use no texture at all, as this is effectively one big slow system memory pixel shader.

all output chanels are in the range of 0 to 1 were 0 is totaly off and 1 is totaly on (exept hue wich wraps around, 0 and 1 are red, .5 is green .75 is blue/purple, .25 is yellow/green, hsl is sort of like polar coordanants with H being equivelent to theta).
so you need to normalise your output to this, on drawing anything greater than 1 is clamped to 1, and less than 0 to 0, now this is after evaluation, so you can have negitive values, it's just that when it's drawn on screen it shows up as black. you can invoke this function in your code if you think it will be usefull (anything with a divide over (aproching) zero in it for instance, like tangent functions) with clamp().

by complex variables do you mean i? no, but I'll look into it, I don't think i would be to hard to incorporate into the code (I'd just have to add a second double and use the appropriate math in the appropriate places), I could even include output modes for it. if you promise to use it that is ;)

I was also considering adding iterative abilities (wich could allow you to fake diferentiation/integration and do series convergence) but that's going to have to wait untill after I figure out how to get user defined functions to work (and I don't mean those psudo functional variables

also a few hidden functions that use non-standard notation (because its a requierment of the odd syntax I started with)
b#x == the b'th root of x
b~x == the log base b of x
comparison opperators (>,<,=) return 1.0 for true and 0.0 for false
and modulus is %

also there are built in constants PI and E (case sensitive, I know e is suposed to be lower case but it's my screwy syntax) if there are any others you'd like I'd be happy to include them. there is also a built in variable called :srand: wich is a static random, it gets changed everytime you evaluate to something between 0 and 1 (it would be diferent in each frame of an animation)

while I'm at it here is a complete list of all unary functions currently supported:
hypsin
hypcos
hyptan
arcsin
arccos
arctan
sin
cos
tan
log
ln
sqrt
deg (degree to radian)
rad  (radian to degree)
!   (factorial, it works a bit oddly !(:var:) rather than :var:! as you would expect)
abs
ipart (returns only the whole number)
fpart (strips off whole numbers, leaveing only the less than 1 part)
sign (returns -1 or 1)
not (returns 0 if you pass it 1, zero under all other cases)
clamp (returns 1 if passed over 1, 0 if under 0)


if this starts getting used I'm likely to rework the syntax

oh and if you plan on doing animations here is a tip, evaluate at t=0 and t=1 it the two images look exactly the same it will loop seamlessly.

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 25, 2007, 08:52:01 am
while trying to figure out perlin noise I came up with this
_UNBELIEVABLY EXPENSIVE_
function

Code: [Select]
@n1=sin(2*(:x:)*PI) + sin(2*(:y:)*PI)/2
@n2=(sin(4*(:x:+:n1:)*PI) + sin(4*(:y:+:n1:)*PI))/4
@n3=(sin(8*(:x:+:n2:)*PI) + sin(8*(:y:+:n2:)*PI))/8
@n4=(sin(16*(:x:+:n3:)*PI) + sin(16*(:y:+:n3:)*PI))/16
@n5=(sin(32*(:x:+:n4:)*PI) + sin(32*(:y:+:n4:)*PI))/32
@n6=(sin(64*(:x:+:n5:)*PI) + sin(64*(:y:+:n5:)*PI))/64
@n7=(sin(128*(:x:+:n6:)*PI) + sin(128*(:y:+:n6:)*PI))/128
@n8=(sin(256*(:x:+:n7:)*PI) + sin(256*(:y:+:n7:)*PI))/256


@H=:r:/8

@S=0

@L=1-(:n1:+:n2:+:n3:+:n4:+:n5:+:n6:+:n7:+:n8:)*.8

$output<hsl>{
:H:
:S:
:L:
}
wich made this image

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 25, 2007, 10:41:50 am
I think I'm going to start over useing wxwidgets, the basic framework is simple so it shouldn't take too long to rebuild, and I'll make use to make an actual image handleing class this time, then I'll be able to do layers, and THEN it'd be easy to do things like perlin noise, on a plus it'd also be an absolute snap to get loading of images, then you could do manipulation of exsisting textures. the variable code is off in it's own little world so I can still develop it in the exsisting project without haveing to worry about porting issues.
Title: Re: fun little toy I just made for the hell of it
Post by: DaBrain on January 25, 2007, 02:18:18 pm
Wait... could this tool create tileable water animations?

That would be great! ;)
Title: Re: fun little toy I just made for the hell of it
Post by: Huggybaby on January 25, 2007, 02:19:39 pm
Does your generator support random (rnd) numbers?
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 25, 2007, 03:59:54 pm
yes and yes
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 29, 2007, 05:23:34 am
well I learned a lot about wxwidgets the last few days, maybe I can put that to use on wxfred.
anyway, this is the new interface, note the whole layer system (and the tumbnail views), it's prety unstable (cause I don't seem to fully understand the list control totaly) but you should be able to get a jist of what I've got in mind.

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Huggybaby on January 29, 2007, 06:47:16 pm
That proximus effect is the most organic, awesome looking and usable one you've yet devised. There's no hint of the spirograph look from some of the others, it is killer.  :yes:
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 29, 2007, 08:33:12 pm
that is from the new layering system, you can make perlineque noise and use that for later use you can add it to a spyrography looking thing then use that for a sine function and get cool turbulence effects.
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on January 30, 2007, 02:38:52 am
not going to be able to work on this much for a few days, but here is a better example of fractal noise at work

[attachment deleted by admin]
Title: Re: fun little toy I just made for the hell of it
Post by: Bobboau on February 01, 2007, 01:04:05 am
still haven't been able to do any work on this, but here is something I made just a little while ago

[attachment deleted by admin]