Post-Processing Levels for Away3D4

Software: Away3D 4.x

Jean Carlo Deconto, Newbie
Posted: 17 February 2012 04:38 AM   Total Posts: 29

Hi!

A small contribution. Based on the algorithm http://www.anttikupila.com/flash/my-take-on-hydra/.

away3d.filters.LevelsFilter3D.as

package away3d.filters
{
 import away3d
.filters.tasks.Filter3DLevelsTask;
 
 
import flash.geom.Point;

 public class 
LevelsFilter3D extends Filter3DBase
 {
  
private var _levels Filter3DLevelsTask;

  public function 
LevelsFilter3D(red:Point=nullgreen:Point=nullblue:Point=nullrgb:Point=null)
  
{
   super
();
   
_levels = new Filter3DLevelsTask(red,green,blue,rgb);
   
addTask(_levels);   
  
}
  
  
public function set red(value:Point):void
  {
   _levels
.red value;
  
}
  
  
public function get red():Point
  {
   
return _levels.red;
  
}
  
  
public function set green(value:Point):void
  {
   _levels
.green value;
  
}
  
  
public function get green():Point
  {
   
return _levels.green;
  
}
  
  
public function set blue(value:Point):void
  {
   _levels
.blue value;
  
}
  
  
public function get blue():Point
  {
   
return _levels.blue;
  
}
  
  
public function set rgb(value:Point):void
  {
   _levels
.rgb value;
  
}
  
  
public function get rgb():Point
  {
   
return _levels.rgb;
  
}
 }

away3d.filters.tasks.Filter3DLevelsTask.as

package away3d.filters.tasks
{
 import away3d
.cameras.Camera3D;
 
import away3d.core.managers.Stage3DProxy;
 
 
import flash.display3D.Context3DProgramType;
 
import flash.display3D.textures.Texture;
 
import flash.geom.Point;

 public class 
Filter3DLevelsTask extends Filter3DTaskBase
 {
  
private var _data Vector.<Number>;
  
  public function 
Filter3DLevelsTask(red:Point=nullgreen:Point=nullblue:Point=nullrgb:Point=null)
  
{
   super
();
   
_data = new Vector.<Number>(16,true);
   
this.red red red : new Point(0,1);
   
this.green green green : new Point(0,1);
   
this.blue blue blue : new Point(0,1);
   
this.rgb rgb rgb : new Point(0,1);
  
}
 
  
public function set red(value:Point):void
  {
   _data[0] 
value.x;
   
_data[1] value.y;
   
_data[2] value.value.x;
  
}
  
  
public function get red():Point
  {
   
return new Point(_data[0]_data[1]);
  
}
  
  
public function set green(value:Point):void
  {
   _data[4] 
value.x;
   
_data[5] value.y;
   
_data[6] value.value.x;
  
}
  
  
public function get green():Point
  {
   
return new Point(_data[4]_data[5]);
  
}
  
  
public function set blue(value:Point):void
  {
   _data[8] 
value.x;
   
_data[9] value.y;
   
_data[10] value.value.x;
  
}
  
  
public function get blue():Point
  {
   
return new Point(_data[8]_data[9]);
  
}
  
  
public function set rgb(value:Point):void
  {
   _data[12] 
value.x;
   
_data[13] value.y;
   
_data[14] value.value.x;
  
}
  
  
public function get rgb():Point
  {
   
return new Point(_data[12]_data[13]);
  
}
  
  override 
protected function getFragmentCode() : String
  {
   
return ["tex ft0, v0, fs0 <2d,linear,clamp>",
     
getLevelFragmentCode(0"x"),
     
getLevelFragmentCode(1"y"),
     
getLevelFragmentCode(2"z"),
     
getLevelFragmentCode(3"xyz"),
     
"mov oc, ft0"].join("\n");
  
}
  
  
private function getLevelFragmentCode(inputAt:intcolor:String):String
  {
   
var input:String "fc" inputAt.toString() + ".";
   
color "." color;   
   return 
["sub ft1"+color+", "+("ft0"+color)+", "+(input+"x"),
     
"div ft0"+color+", "+("ft1"+color)+", "+(input+"z")].join("\n");      
  
}
  
  override 
public function activate(stage3DProxy Stage3DProxycamera3D Camera3DdepthTexture Texture) : void
  {    
   stage3DProxy
.context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT0_data4);
  
}
 }

How to use?

import away3d.filters.LevelsFilter3D;
...

var 
levels:LevelsFilter3D = new LevelsFilter3D();
levels.red = new Point(0,1);
levels.green = new Point(0,1);
levels.blue = new Point(0,1);
levels.rgb = new Point(0,.7);

_view = new View3D(_scene_camera);
_view.filters3d [levels]

Last update 17/02/1012

LevelsFilter3D
ColorTransformFilter3D
ColorMatrixFilter3D

Included in the zip file.

 

File Attachments
filters3d.zip  (File Size: 5KB - Downloads: 270)
   

Avatar
theMightyAtom, Sr. Member
Posted: 17 February 2012 07:45 AM   Total Posts: 669   [ # 1 ]

Very nice, thanks for that :O)
You might want to include a zip file of your classes

Cheers!

 

   

Jean Carlo Deconto, Newbie
Posted: 17 February 2012 09:50 AM   Total Posts: 29   [ # 2 ]

Thank you for your appreciation!
I’ll be posting more post-processing shaders this week. =)

Cheers!

 

   

Jean Carlo Deconto, Newbie
Posted: 18 February 2012 04:25 PM   Total Posts: 29   [ # 3 ]

This is my favorite effect! Color Balance.
Based on the code of http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=2206023

import away3d.filters.ColorBalanceFilter3D;
...

var 
colors:ColorBalanceFilter3D = new ColorBalanceFilter3D();
colors.shadows = new Vector3D(-.6,-.8,.3);
colors.midtones = new Vector3D(0,.1,.1);
colors.highlights = new Vector3D(.6,.3,.3);
colors.amount 1;

_view = new View3D(_scene_camera);
_view.filters3d [colors]

Including the modification of the file .pkb (Pixel Bender) in the zip file.

 

File Attachments
colorbalance.zip  (File Size: 3KB - Downloads: 243)
   

oh_meeeeee, Newbie
Posted: 18 September 2012 12:38 PM   Total Posts: 7   [ # 4 ]

Hi guys, Hi Jean,

Is it possible to apply a filter to a particular mesh or material maybe?

I tried colorTransform but that doesnt look nice as it colors the shadows as well.

Basically I have a plane with a bitmap texture loaded on it. Now I want a user to select a desired color and preview it on this wall. So he can preview a wall in red, blue, yellow or what ever color he chooses with the same texture.

btw the filers work on view nicely.

Cheers,
ak

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X