Archive

Archive for August, 2011

WE MOVED OUT!

we moved out!
most of the blog posts have been moved here:


emmanuelflores.net

Categories: welcome

Small lesson on setters, setcell!

Another way to think setcell messages to a matrix using java. So something like this:

setcell 1 1 plane 1 val 233

can be turned into the next, a small tiny thingie to play around:

import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class SetcellBasic extends MaxObject{
JitterMatrix sc1 = new JitterMatrix(3,”char”,3,3);
int[] cells = new int[2];
int value;
int plane;

public SetcellBasic(){
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});

value = 0;
plane = 0;
}

public void setCells(int _x, int _y){
cells[0] = _x;
cells[1] = _y;

post(“the position of the cell is “+ cells[0] + ” ” + cells[1]);
}

public void setValue(int _value){
value = _value;
}

public void setPlane(int _plane){
plane = _plane;
}

public void bang(){
//remember that setcell(int[], int, int)
//also floats can be used as values
sc1.setcell(cells, plane, value);

outlet(0,”jit_matrix”, sc1.getName());
}
}

Now, if we want to port this into gl vectors we can do something like this:

import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class Gldraw extends MaxObject{

JitterMatrix l2= new JitterMatrix(3,”float32″,2);
int[] cells = new int[2];
float x, y;

public Gldraw(){
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
x = 0; y = 0;
cells[0]=0; cells[1] = 0;
}

public void setX(float _x){
x = _x;
}

public void setY(float _y){
y = _y;
}

public void resetValues(){
x = 0;
y = 0;
}

public void bang(){
int plane = 0;
l2.setcell(cells, plane, x);

plane = 1;
l2.setcell(cells, plane, y);

plane = 2;
l2.setcell(cells, plane, 0.0f);

outlet(0,”jit_matrix”, l2.getName());
}

}

Notice how each plane represents the x, y and z values. Remember that setters are our friends here!
Once in maxland we can provide the next command to our sketch object:

reset, drawmatrix [matrix name] [primitive]

A proper example very soon!

Categories: Uncategorized

Inspired slicing

Slicing geometries in jitter, very much inspired by my own work with vvvv. So the ‘getSlice’ becomes a ‘zl slice’, hlsl turns into glsl and c# into java. Pretty much back and forth on the parallel world!
I find very interesting how the same approach creates a different result depending on the system that is being used; a different view for the same mind set.

Some of these materials might find its way into the ‘worm songs’…

join all the parts

join all the parts

join all the parts

Categories: glsl, java, jitter

Phongy depth

Made variation to Natan Sinigaglia’s ‘DOF’ patch: implemented a phong light model for the depth pass. It makes the image ‘crunchier’.
Notice that there are several techniques. In those with a ‘viewmatrix depth’ I found a kind of discontinuity with the shading interpolation. In the case of the ‘distance to camera’ techniques I used the next formula:

float4 interpolation = lerp(input, col, pow(Interpolation,2));

Remember to place the “PhongDirectional.fxh” file on the same root folder as the shader. You can find the original file on the effects folder inside vvvv.

I like the result, next step would be to explore more light models and, perhaps, to implement a crepuscular ray model on top of the depth!


//transform
float4x4 tW: WORLD;
float4x4 tV: VIEW;
float4x4 tWV: WORLDVIEW;
float4x4 tVP: VIEWPROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;
float4x4 tP: PROJECTION;

#include “PhongDirectional.fxh”

float dNear = 1;
float dFocus = 0;
float dFar = 2;
float clampFar = .9;
float3 camPos;

//textures
//not used but feasible to implement
texture Tex;
sampler Samp = sampler_state{
Texture = (Tex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float4x4 tTex: TEXTUREMATRIX;
float4x4 tColor: COLOR;

//struct
struct vs2ps{
float4 Pos: POSITION;
float4 TexCd: TEXCOORD0;
float3 LightDirV: TEXCOORD1;
float3 NormV: TEXCOORD2;
float3 ViewDirV: TEXCOORD3;
float4 col: COLOR;
};

vs2ps VS(
float4 Pos: POSITION)
{
vs2ps Out = (vs2ps) 1;

Pos = mul(Pos, tW);
float depth = distance(Pos, camPos);

if(depth<dFocus){
depth = (depth-dNear)/(dFocus-dNear)/2;
}else{
depth = (depth-dFocus)/(dFar – dFocus)/2 + 0.5;
//optional:
depth = clamp(depth, 0 , clampFar);
}

Out.Pos = mul(Pos, tVP);
Out.col.rgb = depth;

return Out;
}

vs2ps VS2(
float4 Pos: POSITION)
{
vs2ps Out = (vs2ps) 1;

Out.Pos = mul(Pos, tWVP);

float depth = Out.Pos.z;

if (depth < dFocus)
{
depth = (depth – dNear)/(dFocus – dNear)/2;
}

else
{
depth = (depth-dFocus)/(dFar – dFocus)/2 + 0.5;
//OPTIONAL:
depth = clamp (depth, 0, clampFar) ;
}

Out.col.rgb = depth;

return Out;
}

////
vs2ps VS_PHONG_DCD(
float4 Pos: POSITION,
float3 NormO: NORMAL,
float4 TexCd : TEXCOORD0
)
{
vs2ps Out = (vs2ps) 1;

//depth stuff
Pos = mul(Pos, tW);
float depth = distance(Pos, camPos);

if (depth < dFocus)
{
depth = (depth – dNear)/(dFocus – dNear)/2;
}

else
{
depth = (depth-dFocus)/(dFar – dFocus)/2 + 0.5;
//OPTIONAL:
depth = clamp (depth, 0, clampFar) ;
}

//phong stuff
//inverse light direction in view space
Out.LightDirV = normalize(-mul(lDir, tV));

//normal in view space
Out.NormV = normalize(mul(NormO, tWV));

Out.Pos = mul(Pos, tVP);
Out.TexCd = mul(TexCd, tTex);
Out.ViewDirV = -normalize(mul(Pos, tWV));

Out.col.rgb = depth;

return Out;
}

////
vs2ps VS_PHONG_VMD(
float4 Pos: POSITION,
float3 NormO: NORMAL,
float4 TexCd : TEXCOORD0
)
{
vs2ps Out = (vs2ps) 1;

//depth stuff
Out.Pos = mul(Pos, tWVP);

float depth = Out.Pos.z;

if (depth < dFocus)
{
depth = (depth – dNear)/(dFocus – dNear)/2;
}

else
{
depth = (depth-dFocus)/(dFar – dFocus)/2 + 0.5;
//OPTIONAL:
depth = clamp (depth, 0, clampFar) ;
}

//phong stuff
//inverse light direction in view space
Out.LightDirV = normalize(-mul(lDir, tV));

//normal in view space
Out.NormV = normalize(mul(NormO, tWV));

Out.Pos = mul(Pos, tWVP);
Out.TexCd = mul(TexCd, tTex);
Out.ViewDirV = -normalize(mul(Pos, tWV));

Out.col.rgb = depth;

return Out;
}

///////////////////////////////////////////////////////
//pixel
float4 PS(vs2ps In): COLOR{
return In.col;
}

float Alpha = 1;

float4 PS_PHONG(vs2ps In):COLOR{
//In.TexCd = In.TexCd / In.TexCd.w; // for perpective texture projections (e.g. shadow maps) ps_2_0

//orthodox phong!
//here we can implement the texture
//float4 col = tex2D(Samp, In.TexCd);

float4 input = In.col;
float4 col = In.col;

col.rgb *= PhongDirectional(In.NormV, In.ViewDirV, In.LightDirV);
col = col * input;
col.a *= Alpha;

return mul(col, tColor);
}

//softer interpolation
float Interpolation = 0.1f;
float4 PS_PHONG2(vs2ps In):COLOR{
float4 input = In.col;
float4 col = In.col;

col.rgb *= PhongDirectional(In.NormV, In.ViewDirV, In.LightDirV);

//float4 interpolation = lerp(input, col, Interpolation);
float4 interpolation = lerp(input, col, pow(Interpolation,2));

col.a *= Alpha;

return col;

}

//techniques
//distance camera depth
technique DCD{
pass P0{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}
}

//view matrix depth
technique VMD{
pass P0{
VertexShader = compile vs_2_0 VS2();
PixelShader = compile ps_2_0 PS();
}
}

//phong + DCD
technique phDCDInter{
pass P0{
VertexShader = compile vs_2_0 VS_PHONG_DCD();
PixelShader = compile ps_2_0 PS_PHONG2();
}
}

//phong + VMD
technique phVMD{
pass P0{
VertexShader = compile vs_2_0 VS_PHONG_VMD();
PixelShader = compile ps_2_0 PS_PHONG();
}
}

//phong + VMD + interpolation
technique phVMDInter{
pass P0{
VertexShader = compile vs_2_0 VS_PHONG_VMD();
PixelShader = compile ps_2_0 PS_PHONG2();
}
}

The final result looks like this, once the DOF is implemented:

phong depth with HLSL

Categories: HLSL, vvvv

Feeling good with HLSL

Imagine things and then make them move…

testing god rays

testing god rays

hlsl experiments

hlsl experiments

Categories: HLSL