Archive

Author Archive

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

Cinder to touchdesigner # 2

note: I will migrate this blog to my webpage very soon thus having a proper display of the source code.

Next step on having a kind of template for porting OFW/Cinder patches into TD. So, I have the next class called ‘Lines’:


#pragma once
#include “TOP_CPlusPlusBase.h”

class Lines
{
public:
Lines();
~Lines();

virtual void draw(int _x1, int _y1, int _x2, int _y2);

int x1,x2,y1,y2;

};

the body of the class:

#include “Lines.h”

Lines::Lines(){
x1 = x2 = y2 = y1 = 0;
}

Lines::~Lines(){

}

void Lines::draw(int _x1, int _y1, int _x2, int _y2){

x1 = _x1;
y1 = _y1;
x2 = _x2;
y2 = _y2;

::glVertex2i(x1,y1);
::glVertex2i(x2,y2);
}

then i declare a vector on the Parent class:

std::vector mLines;

body:

for(unsigned int i=0;i<amount;i++){
//starting all the lines as 0 value
mLines.push_back(Lines());
}

and the calling the drawing method within the execution loop:

::glBegin(GL_LINES);
::glLineWidth(1.0f);

for(unsigned int i=0; i < amount; i++;
int _y1 = rand()% outputFormat->height;
int _x2 = rand()% outputFormat->width;
int _y2 = rand()% outputFormat->height;

mLines[i].draw(_x1, _y1, _x2, _y2);
}
::glEnd();

::glBegin(GL_LINE_LOOP);
::glVertex2i(0,0);
::glVertex2i(outputFormat -> width, outputFormat->height);
::glEnd();

next step might be to implement containers with pointers and shared pointers.

Categories: cpp, touchdesigner

Cinder to touchdesigner # 1

When I am about to start a project I always ask myself ‘spaghetti or code?’. Indeed, choosing the correct tool for the correct job/piece/toy is, from MHO, one of the most important steps of media design. However, I often find myself willing to have the benefits of one tool available into another. That has been the reason behind porting java and processing code into jitter as I can benefit a performing tool with data management resources( just to put an example). Of course working with such idea always provides interesting insights about the tools themselves, their possibilities and limitations. It also exposes the many things that I need to learn in order to implement my ideas. In other words, turns the world slightly upside down.
Today I managed to compile my first, very simple simple, TOP object for TouchDesigner. I need to admit that the most difficult past was not to deal with the internal logic of the c++ file but to compile it: TouchDesigner is only available for the windows system, meaning that I am learning how to do all this compilation management with Visual Studio c++. So far so good although I still use too many concepts from XCode in order to deal with the new IDE( which is probably not a good idea).
The TouchDesigner gl externals are quite straight forward. Basically you are calling gl commands ‘as they are’. So for a cluster of lines you would do something like this:

::glBegin(GL_LINES);
::glLineWidth(1.0f);
for(unsigned int i=0; i<amount;i++);
int x1 = rand()% outputFormat->width;
int y1 = rand()% outputFormat->height;
int x2 = rand()% outputFormat->width;
int y2 = rand()% outputFormat->height;
::glVertex2i(x1 ,y1);
::glVertex2i(x2, y2);
}
::glEnd();

pretty direct, right?

So now to plan the proper way to port my Cinder and OFW apps into TouchDesigner. Let’s see how it goes…

Categories: cinder, cpp, touchdesigner