Skip to content

Commit

Permalink
v1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
diwi committed Oct 25, 2017
1 parent a76b8a3 commit abd8174
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 67 deletions.
Expand Up @@ -143,9 +143,6 @@ public void setup() {
surface.setResizable(true);
surface.setLocation(viewport_x, viewport_y);

// projection
// perspective(120 * DEG_TO_RAD, width/(float)height, 2, 6000);

// camera
peasycam = new PeasyCam(this, -4.083, -6.096, 7.000, 1300);
peasycam.setRotations(1.085, -0.477, 2.910);
Expand Down Expand Up @@ -192,15 +189,7 @@ public boolean resizeScreen(){
pg_render_gbaa = DwUtils.changeTextureSize(this, pg_render_gbaa, width, height, 0, RESIZED);

if(RESIZED[0]){
// resetMatrix();
//
// float[] rot = peasycam.getRotations();
// float[] lat = peasycam.getLookAt();
// double dis = peasycam.getDistance();
//
// peasycam.setActive(false); // unregister handler
// peasycam = new PeasyCam(this, lat[0], lat[1], lat[2], dis);
// peasycam.setRotations(rot[0], rot[1], rot[2]);
// nothing here
}
peasycam.feed();
perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
Expand Down
17 changes: 2 additions & 15 deletions examples/Miscellaneous/DepthOfField_Demo/DepthOfField_Demo.java
Expand Up @@ -87,9 +87,6 @@ public void setup() {
// camera
peasycam = new PeasyCam(this, -4.083, -6.096, 7.000, 1300);
peasycam.setRotations( 1.085, -0.477, 2.910);

// projection
// perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);

// main library context
context = new DwPixelFlow(this);
Expand All @@ -104,7 +101,6 @@ public void display(PGraphics3D canvas) {
}
};


geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);

dof = new DepthOfField(context);
Expand All @@ -129,18 +125,9 @@ public boolean resizeScreen(){
// geombuffer.resize(width, height)

if(RESIZED[0]){
// resetMatrix();
// camera();
// perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
//
// float[] rot = peasycam.getRotations();
// float[] lat = peasycam.getLookAt();
// double dis = peasycam.getDistance();
//
// peasycam.setActive(false); // unregister handler
// peasycam = new PeasyCam(this, lat[0], lat[1], lat[2], dis);
// peasycam.setRotations(rot[0], rot[1], rot[2]);
// nothing here
}

peasycam.feed();
perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);

Expand Down
20 changes: 4 additions & 16 deletions examples/Skylight/Skylight_BasicGUI/Skylight_BasicGUI.java
Expand Up @@ -109,13 +109,13 @@ public void settings() {
smooth(0);
}

public float clip_z_far;
public float clip_z_far = SCENE_SCALE * 5;

public void setup() {
surface.setLocation(viewport_x, viewport_y);
surface.setResizable(true);


// library context
context = new DwPixelFlow(this);
context.print();
Expand All @@ -129,9 +129,7 @@ public void setup() {
// peasycam.setDistance(475.257);
// peasycam.lookAt(-33.842, -38.242, 64.793);

clip_z_far = SCENE_SCALE * 5;
// perspective(60 * DEG_TO_RAD, width/(float)height, 2, clip_z_far);



// create scene
{
Expand Down Expand Up @@ -204,7 +202,6 @@ public void display(PGraphics3D canvas) {
};



// Depth of Field
dof = new DepthOfField(context);
geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
Expand Down Expand Up @@ -254,16 +251,7 @@ public boolean resizeScene(){
skylight.resize(width, height);

if(RESIZED[0]){
// resetMatrix();
// camera();
//
// float[] rot = peasycam.getRotations();
// float[] lat = peasycam.getLookAt();
// double dis = peasycam.getDistance();
//
// peasycam.setActive(false); // unregister handler
// peasycam = new PeasyCam(this, lat[0], lat[1], lat[2], dis);
// peasycam.setRotations(rot[0], rot[1], rot[2]);
// nothing here
}
peasycam.feed();
perspective(60 * DEG_TO_RAD, width/(float)height, 2, clip_z_far);
Expand Down
2 changes: 1 addition & 1 deletion src/com/thomasdiewald/pixelflow/java/DwPixelFlow.java
Expand Up @@ -38,7 +38,7 @@ public class DwPixelFlow{

static public class PixelFlowInfo{

static public final String version = "1.19";
static public final String version = "1.20";
static public final String name = "PixelFlow";
static public final String author = "Thomas Diewald";
static public final String web = "www.thomasdiewald.com";
Expand Down
64 changes: 64 additions & 0 deletions src/com/thomasdiewald/pixelflow/java/dwgl/DwGLSLProgram.java
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.Stack;

import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GL3;
Expand Down Expand Up @@ -158,6 +159,7 @@ public void begin(){

public void end(){
clearUniformTextures();
clearAttribLocations();
gl.glUseProgram(0);
}

Expand All @@ -182,6 +184,7 @@ public void end(String error_msg){
//////////////////////////////////////////////////////////////////////////////

HashMap<String, Integer> uniform_loc = new HashMap<String, Integer>();
HashMap<String, Integer> attrib_loc = new HashMap<String, Integer>();

public boolean LOG_WARNINGS = true;

Expand All @@ -207,7 +210,32 @@ private int getUniformLocation(String uniform_name){
return LOC_name;
}


private int getAttribLocation(String attrib_name){
int LOC_name = -1;
Integer loc = attrib_loc.get(attrib_name);
if(loc != null){
LOC_name = loc;
} else {
LOC_name = gl.glGetAttribLocation(HANDLE, attrib_name);
if(LOC_name != -1){
attrib_loc.put(attrib_name, LOC_name);
}
}
if(LOC_name == -1){
if(LOG_WARNINGS && warning_count < 20){
System.out.println(name+": attrib location \""+attrib_name+"\" = -1");
warning_count++;
}
}
return LOC_name;
}







public static class UniformTexture{
String name = null;;
Expand Down Expand Up @@ -258,6 +286,7 @@ public void clearUniformTextures(){
}






Expand Down Expand Up @@ -339,6 +368,41 @@ public void uniform4i(String uniform_name, int v0, int v1, int v2, int v3){




public int attributeArrayBuffer(String attrib_name, int HANDLE_buffer, int size, int type, boolean normalized, int stride, long pointer_buffer_offset){
int LOC_ATTRIB = getAttribLocation(attrib_name);
if( LOC_ATTRIB != -1 ){
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, HANDLE_buffer);
gl.glVertexAttribPointer (LOC_ATTRIB, size, type, normalized, stride, pointer_buffer_offset);
gl.glEnableVertexAttribArray(LOC_ATTRIB);
vertex_attrib_arrays.push (LOC_ATTRIB);
}
return LOC_ATTRIB;
}



public Stack<Integer> vertex_attrib_arrays = new Stack<>();
public void clearAttribLocations(){
while(!vertex_attrib_arrays.empty()){
Integer loc = vertex_attrib_arrays.pop();
if(loc != -1) gl.glDisableVertexAttribArray(loc);
}
}














//////////////////////////////////////////////////////////////////////////////
//
// DRAWING
Expand Down
Expand Up @@ -27,7 +27,6 @@
import processing.core.PVector;
import processing.opengl.PGraphics3D;
import processing.opengl.PShader;
import processing.opengl.Texture;



Expand Down Expand Up @@ -130,14 +129,12 @@ public boolean resize(int w, int h){
}
}

// resized[0] |= tex_shading.resize(context, GL2.GL_R32F, w, h, GL2.GL_RED, GL2.GL_FLOAT, GL2.GL_NEAREST, GL2.GL_CLAMP_TO_EDGE, 1, 4);
// resized[0] |= tex_shading.resize(context, GL2.GL_R32F, w, h, GL2.GL_RED, GL2.GL_FLOAT, GL2.GL_LINEAR, GL2.GL_CLAMP_TO_EDGE, 1, 4);

if(resized[0]){
reset();
}



return resized[0];
}

Expand Down Expand Up @@ -231,15 +228,17 @@ public void updateStep(){
// context.beginDraw(tex_shading.dst);
// shader_.begin();
// setUniforms();
// shader_.uniform2f ("wh" , w, h);
// shader_.uniformTexture("tex_src" , tex_shading.src);
// shader_.uniformTexture("tex_shadow" , tex_shadowmap.glName);
// shader_.uniformTexture("tex_geombuffer", tex_geombuffer.glName);
// shader_.drawFullScreenQuad();
// shader_.end();
// context.endDraw();
// tex_shading.swap();
// context.end();
//
// tex_shading.swap();
//
// DwFilter.get(context).copy.apply(tex_shading.src, pg_src);


Expand All @@ -260,7 +259,6 @@ void setUniforms() {
mat_shadow.apply(mat_modelviewInv);
mat_shadow.transpose(); // processing


PMatrix3D mat_shadow_normal = mat_shadow.get();
mat_shadow_normal.invert();
mat_shadow_normal.transpose(); // processing
Expand All @@ -275,8 +273,6 @@ void setUniforms() {
mat_shadow_normal_projection.invert();
mat_shadow_normal_projection.transpose(); // processing



// PMatrix3D mat_shadow_modelview = new PMatrix3D(shadowmap.pg_shadowmap.modelview);
// mat_shadow_modelview.apply(mat_modelviewInv);
// mat_shadow_modelview.transpose();
Expand All @@ -302,8 +298,6 @@ void setUniforms() {

// shadow_bias_mag = scene_scale/ shadow_map_size;

// float w = geombuffer.pg_geom.width;
// float h = geombuffer.pg_geom.height;

// PMatrix3D mat_screen_to_eye = new PMatrix3D();
// mat_screen_to_eye.scale(w, h, 1);
Expand All @@ -325,7 +319,6 @@ void setUniforms() {
// shader.set("mat_shadow_modelview", mat_shadow_modelview);
shader.set("dir_light", light_dir_cameraspace);
shader.set("pass_mix", pass_mix);
// shader.set("wh", w, h); // should match the dimensions of the shading buffers
shader.set("wh_shadow", w_shadow, h_shadow); // should match the dimensions of the shading buffers
shader.set("shadow_bias_mag", shadow_bias_mag);

Expand All @@ -335,16 +328,15 @@ void setUniforms() {
// getBuffer(buf_mat_shadow_normal_modelview , mat_shadow_normal_modelview , true);
// getBuffer(buf_mat_shadow_normal_projection, mat_shadow_normal_projection, true);
//
// boolean transpose = !true;
// boolean transpose = !false;
// shader_.uniformMatrix4fv("mat_projection" , 1, transpose, buf_mat_projection , 0);
// shader_.uniformMatrix4fv("mat_shadow" , 1, transpose, buf_mat_shadow , 0);
// shader_.uniformMatrix3fv("mat_shadow_normal_modelview" , 1, transpose, buf_mat_shadow_normal_modelview , 0);
// shader_.uniformMatrix3fv("mat_shadow_normal_projection", 1, transpose, buf_mat_shadow_normal_projection, 0);
// shader_.uniform3f("dir_light", light_dir_cameraspace.x, light_dir_cameraspace.y, light_dir_cameraspace.z);
// shader_.uniform1f("pass_mix", pass_mix);
// // shader_.uniform2f("wh", w, h);
// shader_.uniform2f("wh_shadow", w_shadow, h_shadow);
// shader_.uniform1f("shadow_bias_mag", shadow_bias_mag);
// shader_.uniform3f ("dir_light", light_dir_cameraspace.x, light_dir_cameraspace.y, light_dir_cameraspace.z);
// shader_.uniform1f ("pass_mix", pass_mix);
// shader_.uniform2f ("wh_shadow", w_shadow, h_shadow);
// shader_.uniform1f ("shadow_bias_mag", shadow_bias_mag);
}

float[] buf_mat_projection = new float[16];
Expand All @@ -368,6 +360,18 @@ public void getBuffer(float[] matv, PMatrix3D mat, boolean use3x3){
matv[ 8]=mat.m20; matv[ 9]=mat.m21; matv[10]=mat.m22; matv[11]=mat.m23;
matv[12]=mat.m30; matv[13]=mat.m31; matv[14]=mat.m32; matv[15]=mat.m33;
}


// if (use3x3) {
// matv[0]=mat.m00; matv[1]=mat.m10; matv[2]=mat.m20;
// matv[3]=mat.m01; matv[4]=mat.m11; matv[5]=mat.m21;
// matv[6]=mat.m02; matv[7]=mat.m12; matv[8]=mat.m22;
// } else {
// matv[ 0]=mat.m00; matv[ 1]=mat.m10; matv[ 2]=mat.m20; matv[ 3]=mat.m30;
// matv[ 4]=mat.m01; matv[ 5]=mat.m11; matv[ 6]=mat.m21; matv[ 7]=mat.m31;
// matv[ 8]=mat.m02; matv[ 9]=mat.m12; matv[10]=mat.m22; matv[11]=mat.m32;
// matv[12]=mat.m03; matv[13]=mat.m13; matv[14]=mat.m23; matv[15]=mat.m33;
// }
}


Expand Down
16 changes: 10 additions & 6 deletions src/com/thomasdiewald/pixelflow/java/utils/DwUtils.java
Expand Up @@ -725,13 +725,17 @@ static public void setLookAt(PGraphicsOpenGL dst, PVector eye, PVector center, P
}


static public void swap(PGraphics[] pg){
PGraphics tmp = pg[0];
pg[0] = pg[1];
pg[1] = tmp;
}

// static public void swap(PGraphics[] pg){
// PGraphics tmp = pg[0];
// pg[0] = pg[1];
// pg[1] = tmp;
// }

static public void swap(Object[] obj){
Object tmp = obj[0];
obj[0] = obj[1];
obj[1] = tmp;
}


static private boolean pushed_lights = false;
Expand Down

0 comments on commit abd8174

Please sign in to comment.