Categories
3d

Molehill examples (source added)

update: this was built to run on the incubator version of the flash player so will not work on the standard fp11
I will update this demo today to run on the release version.

YO!!!

Having enjoyed playing with adobe flash’s new molehill API I though I should share some demos.

I’ve written quite a few and being a lazy boy never really uploaded many of them. So that’s what this page is for :).
I will start upload the demo’s from time to time to this post with a little description of what’s going on.

note: you need the incubator version of flash to view these download here

Demo 1 (click image or link below)
rar

glassy dinosaur demo


The shader in this demo uses a combination of reflection, refraction and cubemap sampling.
mouse wheel to zoom in and out

Shader Code:

AGAL-

VERTEX SHADER:

//vc0 is worldViewMatrix
//vc4 is worldMatrix
//vc8 is camera position
//vc9 is just a [1,1,1,1] (and yes I coulda just used the w of the position)

m44 op va0 vc0
m44 vt0 va0 vc4
m33 vt1.xyz va1 vc4
sub vt2 vc8 vt0
nrm vt2.xyz vt2
mov v0 vt1.xyz
mov v1 vt2
dp3 vt3 vt2.xyz vt1.xyz
sub vt3 vc9.w vt3
mov v2 vt3

FRAGMENT SHADER:

//fc0 is [0.9, 0.81, 0, 1].. which was roi and roi squared I think… been a while 🙂

dp3 ft0 v1 v0
add ft0 ft0 ft0
mul ft0 v0 ft0
sub ft0 v1 ft0
neg ft0 ft0
nrm ft0.xyz ft0
dp3 ft2 v1 v0
mul ft2 ft2 v0
sub ft2 ft2 v1
mul ft2 ft2 fc0.x
dp3 ft1 v1 v0
mul ft1 ft1 ft1
sub ft1 fc0.w ft1
mul ft1 fc0.y ft1
sub ft1 fc0.w ft1
sqt ft1 ft1
mul ft1 ft1 v0
sub ft1 ft2 ft1
tex ft0 ft0 fs0
tex ft1 ft1 fs0
sub ft2 ft0 ft1
mul ft2 ft2 v2
add ft2 ft2 ft1
mov oc ft2

now if you think that looks scary…. please compare it to

AGAL.m44(“op”, “va0”, “vc0”) + //output
AGAL.m44(“vt0”, “va0”, “vc4”) + //world space pos in vt0
AGAL.m33(“vt1.xyz”, “va1”, “vc4”) + //world space nrm in vt1
AGAL.view(“vt2”, “vt0”, “vc8”) + //view in vt2
AGAL.mov(“v0”, “vt1.xyz”) + //normals in v0
AGAL.mov(“v1”, “vt2”)+ //view in v1
AGAL.fresnel_inv(“vt3″,”vt2″,”vt1″,”vc9.w”)+ //fresnel in v2
AGAL.mov(“v2″,”vt3”); //output

and

AGAL.reflect(“ft0”, “v1”, “v0”) +
AGAL.refract(“ft1”, “v1”, “v0”, “ft2”, “fc0.w”, “fc0.x”, “fc0.y”)+
AGAL.tex(“ft0″,”ft0″,”fs0″,”cube”,”clamp”,”linear”)+
AGAL.tex(“ft1″,”ft1″,”fs0″,”cube”,”clamp”,”linear”)+
AGAL.lerp(“ft2”, “ft1”, “ft0”, “v2”)+
AGAL.mov(“oc”, “ft2”);

(see how much better that is…go agal helper go)

more to come 🙂

Categories
jsfl

jslf change publish settings

a little jsfl snippet to publish the swf with a new name

will add it to google code at some point as a file and with some other bits, but it will have to do till then

note: the code is a mash up of stuff I have found online and my own bits

 
var tempFileURI = "file:///C|/profile.xml";				//a temp file to store settings in
document.exportPublishProfile(tempFileURI);			//store the buggers
 
var settings = FLfile.read(tempFileURI);				//read em in
var backupSettings = settings;					//backup incase you only want a temp publish settings alteration
 
var ffnOpen = "<flashFileName>";
var ffnClose = "</flashFileName>";
var ffnOpenLength = ffnOpen.length;
 
var swfName = settings.substring(settings.indexOf(ffnOpen)+ffnOpenLength,settings.indexOf(ffnClose));
 
var newSwfName = prompt("update swf name", swfName);	//doesnt have to come from input box could be hardcoded or derived
if (newSwfName == null || newSwfName.length == 0)
{
	newSwfName = swfName;
}
 
settings = settings.split(swfName).join(newSwfName);	//replace the name	
 
//voodoo section to make it work
var from = settings.indexOf("<defaultNames>");
var to = settings.indexOf("</defaultNames>");
var delta = settings.substring(from, to);
 
settings = settings.split(delta).join("<defaultNames>0");
 
from = settings.indexOf("<flashDefaultName>");
to = settings.indexOf("</flashDefaultName>");
delta = settings.substring(from, to);
 
settings = settings.split(delta).join("<flashDefaultName>0");
//end voodoo
 
 
FLfile.write(tempFileURI, settings);					//write it back to the file now its updated
document.importPublishProfile(tempFileURI);			//import that biatchhh
 
document.testMovie();							//optional publish