Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - AGP

Pages: 1 ... 3 4 [5] 6 7 ... 14
61
Support / Per-Polygon Transparency
« on: February 06, 2014, 07:21:37 pm »
I'm exporting a little particle waterfall splash from 3ds max as a sequence of OBJs. Each OBJ has several triangles with different values for visibility. I have two problems: the first, naturally, is to export these values per-polygon (a simple MaxScript should produce a companion text file describing their visibilty), and the second, of course, is to apply these visibilities per-polygon in jpct (lest I have to have an Object3D per polygon, which seems bizarre memory-wasteful). Is this possible?

62
Support / Robombs Source
« on: February 01, 2014, 11:18:59 pm »
I'm having a look at the Robombs source code. I'm trying to steal your explosions. Actually, I did steal it. :- ) I just don't understand what I'm seeing. At the center of my scene is a simple, untextured, gray sphere. That is what I pass to the simplified addExplosion (which now takes Object3Ds and no ClientEventQueue). The following is just one of several fairly incomprehensible states of the explosion:


And here I hoped for a nice particle explosion...

63
Support / Negative Y Isn't Going Up
« on: January 26, 2014, 09:57:36 pm »
I have a scene that's completely aligned with its SkyBox. Yet when I translate an object with mainGate.translate(0, -deltaTime, 0), it moves on what I think is the x/z plane. What gives?

64
Support / Shader Problem
« on: January 22, 2014, 04:58:53 pm »
Sorry about the shader question. I made a slight change to this in order to update it with the camera's position. Ray, of course, is always the center of the ocean plane. All I get is a black plane in jpct. The first method is how I update the shader (once per gameloop iteration, naturally).

Code: [Select]
     public void update(SimpleVector cameraPosition) {
shader.setUniform("iGlobalTime", (timeF+=.1f));
shader.setUniform("pos", cameraPosition);
     }

Code: [Select]
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

uniform vec3 iResolution;
uniform vec3 iChannelResolution[4];
uniform vec3 pos;
uniform vec3 ray;
uniform float iGlobalTime;
uniform float iChannelTime[4];
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;

const float tau = 6.28318530717958647692;

// Gamma correction
#define GAMMA (2.2)

vec3 ToLinear( in vec3 col ) {
// simulate a monitor, converting colour values into light values
return pow( col, vec3(GAMMA) );
}

vec3 ToGamma( in vec3 col ) {
// convert back into colour values, so the correct light will come out of the monitor
return pow( col, vec3(1.0/GAMMA) );
}

vec3 localRay;

// Set up a camera looking at the scene.
// origin - camera is positioned relative to, and looking at, this point
// distance - how far camera is from origin
// rotation - about x & y axes, by left-hand screw rule, relative to camera looking along +z
// zoom - the relative length of the lens
void CamPolar( out vec3 pos, out vec3 ray, in vec3 origin, in vec2 rotation, in float distance, in float zoom ) {
// get rotation coefficients
vec2 c = vec2(cos(rotation.x),cos(rotation.y));
vec4 s;
s.xy = vec2(sin(rotation.x),sin(rotation.y)); // worth testing if this is faster as sin or sqrt(1.0-cos);
s.zw = -s.xy;

// ray in view space
ray.xy = gl_FragCoord.xy - iResolution.xy*.5;
ray.z = iResolution.y*zoom;
ray = normalize(ray);
localRay = ray;

// rotate ray
ray.yz = ray.yz*c.xx + ray.zy*s.zx;
ray.xz = ray.xz*c.yy + ray.zx*s.yw;

// position camera
pos = origin - distance*vec3(c.x*s.y,s.z,c.x*c.y);
}

// Noise functions, distinguished by variable types

vec2 Noise( in vec3 x ) {
    vec3 p = floor(x);
    vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
// vec3 f2 = f*f; f = f*f2*(10.0-15.0*f+6.0*f2);

vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;

// hardware interpolation lacks precision
// vec4 rg = texture2D( iChannel0, (uv+0.5)/256.0, -100.0 );
vec4 rg = mix( mix(
texture2D( iChannel0, (floor(uv)+0.5)/256.0, -100.0 ),
texture2D( iChannel0, (floor(uv)+vec2(1,0)+0.5)/256.0, -100.0 ),
fract(uv.x) ),
  mix(
texture2D( iChannel0, (floor(uv)+vec2(0,1)+0.5)/256.0, -100.0 ),
texture2D( iChannel0, (floor(uv)+1.5)/256.0, -100.0 ),
fract(uv.x) ),
fract(uv.y) );
 

return mix( rg.yw, rg.xz, f.z );
}

vec4 Noise( in vec2 x ) {
    vec2 p = floor(x.xy);
    vec2 f = fract(x.xy);
f = f*f*(3.0-2.0*f);
// vec3 f2 = f*f; f = f*f2*(10.0-15.0*f+6.0*f2);

vec2 uv = p.xy + f.xy;
return texture2D( iChannel0, (uv+0.5)/256.0, -100.0 );
}

vec4 Noise( in ivec2 x ) {
return texture2D( iChannel0, (vec2(x)+0.5)/256.0, -100.0 );
}

vec2 Noise( in ivec3 x ) {
vec2 uv = vec2(x.xy)+vec2(37.0,17.0)*float(x.z);
return texture2D( iChannel0, (uv+0.5)/256.0, -100.0 ).xz;
}

float Waves( vec3 pos ) {
pos *= .2*vec3(1,1,1);

const int octaves = 6;
float f = 0.0;

// need to do the octaves from large to small, otherwise things don't line up
// (because I rotate by 45 degrees on each octave)
pos += iGlobalTime*vec3(0,.1,.1);
for ( int i=0; i < octaves; i++ ) {
pos = (pos.yzx + pos.zyx*vec3(1,-1,1))/sqrt(2.0);
f  = f*2.0+abs(Noise(pos).x-.5)*2.0;
pos *= 2.0;
}
f /= exp2(float(octaves));

return (.5-f)*1.0;
}

float WavesDetail( vec3 pos ) {
pos *= .2*vec3(1,1,1);

const int octaves = 8;
float f = 0.0;

// need to do the octaves from large to small, otherwise things don't line up
// (because I rotate by 45 degrees on each octave)
pos += iGlobalTime*vec3(0,.1,.1);
for ( int i=0; i < octaves; i++ ) {
pos = (pos.yzx + pos.zyx*vec3(1,-1,1))/sqrt(2.0);
f  = f*2.0+abs(Noise(pos).x-.5)*2.0;
pos *= 2.0;
}
f /= exp2(float(octaves));

return (.5-f)*1.0;
}

float WavesSmooth( vec3 pos ) {
pos *= .2*vec3(1,1,1);

const int octaves = 2;
float f = 0.0;

// need to do the octaves from large to small, otherwise things don't line up
// (because I rotate by 45 degrees on each octave)
pos += iGlobalTime*vec3(0,.1,.1);
for ( int i=0; i < octaves; i++ ) {
pos = (pos.yzx + pos.zyx*vec3(1,-1,1))/sqrt(2.0);
//f  = f*2.0+abs(Noise(pos).x-.5)*2.0;
f  = f*2.0+sqrt(pow(Noise(pos).x-.5,2.0)+.01)*2.0;
pos *= 2.0;
}
f /= exp2(float(octaves));

return (.5-f)*1.0;
}

float WaveCrests( vec3 ipos ) {
vec3 pos = ipos;
pos *= .2*vec3(1,1,1);

const int octaves1 = 6;
const int octaves2 = 16;
float f = 0.0;

// need to do the octaves from large to small, otherwise things don't line up
// (because I rotate by 45 degrees on each octave)
pos += iGlobalTime*vec3(0,.1,.1);
vec3 pos2 = pos;
for ( int i=0; i < octaves1; i++ ) {
pos = (pos.yzx + pos.zyx*vec3(1,-1,1))/sqrt(2.0);
f  = f*1.5+abs(Noise(pos).x-.5)*2.0;
pos *= 2.0;
}
pos = pos2 * exp2(float(octaves1));
pos.y = -.05*iGlobalTime;
for ( int i=octaves1; i < octaves2; i++ ) {
pos = (pos.yzx + pos.zyx*vec3(1,-1,1))/sqrt(2.0);
f  = f*1.5+pow(abs(Noise(pos).x-.5)*2.0,1.0);
pos *= 2.0;
}
f /= 1500.0;

f -= Noise(ivec2(gl_FragCoord.xy)).x*.01;

return pow(smoothstep(.4,-.1,f),6.0);
}


vec3 Sky( vec3 ray ) {
return vec3(.4,.45,.5);
}


float OceanDistanceField( vec3 pos ) {
return pos.y - Waves(pos);
}

float OceanDistanceFieldDetail( vec3 pos ) {
return pos.y - WavesDetail(pos);
}

vec3 OceanNormal( vec3 pos ) {
vec3 norm;
vec2 d = vec2(.01*length(pos),0);

norm.x = OceanDistanceFieldDetail( pos+d.xyy )-OceanDistanceFieldDetail( pos-d.xyy );
norm.y = OceanDistanceFieldDetail( pos+d.yxy )-OceanDistanceFieldDetail( pos-d.yxy );
norm.z = OceanDistanceFieldDetail( pos+d.yyx )-OceanDistanceFieldDetail( pos-d.yyx );

return normalize(norm);
}

float TraceOcean( vec3 pos, vec3 ray ) {
float h = 1.0;
float t = 0.0;
for ( int i=0; i < 100; i++ ) {
if ( h < .01 || t > 100.0 )
break;
h = OceanDistanceField( pos+t*ray );
t += h;
}

if ( h > .1 )
return 0.0;

return t;
}

vec3 ShadeOcean( vec3 pos, vec3 ray ) {
vec3 norm = OceanNormal(pos);
float ndotr = dot(ray,norm);

float fresnel = pow(1.0-abs(ndotr),5.0);

vec3 reflectedRay = ray-2.0*norm*ndotr;
vec3 refractedRay = ray+(-cos(1.33*acos(-ndotr))-ndotr)*norm;
refractedRay = normalize(refractedRay);

const float crackFudge = .0;

// reflection
vec3 reflection = Sky(reflectedRay);

vec3 col = vec3(0,.04,.04); // under-sea colour

col = mix( col, reflection, fresnel );

// foam
col = mix( col, vec3(1), WaveCrests(pos) );

return col;
}

void main(void) {
// vec2 camRot = vec2(.5,.5)+vec2(-.35,4.5)*(iMouse.yx/iResolution.yx);
// vec3 pos, ray;
// CamPolar( pos, ray, vec3(0), camRot, 3.0, 1.0 );

float to = TraceOcean( pos, ray );

vec3 result;
if ( to > 0.0 )
result = ShadeOcean( pos+ray*to, ray );
else result = Sky( ray );

// vignette effect
result *= 1.1*smoothstep( .35, 1.0, localRay.z );

gl_FragColor = vec4(ToGamma(result),1.0);
}

65
Support / How to move U/V Coordinates...
« on: January 21, 2014, 04:35:18 am »
...so as to animate river water? The following doesn't work, for some reason:

Code: [Select]
     public void moveRiverWater(float deltaTime) {
Matrix matrix = river.getTextureMatrix();
if (matrix == null) {
     matrix = new Matrix();
     river.setTextureMatrix(matrix);
}
matrix.translate(river.getXAxis().x*100*deltaTime, river.getXAxis().y*100*deltaTime, river.getXAxis().z*100f*deltaTime);
river.setTextureMatrix(matrix);//WITH OR WITHOUT THIS SEEMINGLY UNNECESSARY CALL, IT DOESN'T WORK
     }

I get absolutely nothing whether or not the object is compiled.

66
Support / Checking for triangle strip... and More
« on: January 20, 2014, 09:21:36 pm »
What does the following message mean?

Quote
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 35/object37 compiled to indexed data using 23997/4599 vertic
es in 46ms!

Also, what does it mean when you get

Quote
Loading file Silmaria\FastOceanShader\vertexshader.glsl
Text file Silmaria\FastOceanShader\vertexshader.glsl loaded...100 bytes
Loading file Silmaria\FastOceanShader\fragmentshader.glsl
Text file Silmaria\FastOceanShader\fragmentshader.glsl loaded...6865 bytes
Loading Texture...Silmaria\FastOceanShader\Noise.png

but then get neither a "shader compiled" nor a "failed to compile" message? I am, of course, doing the following. Alas, I'm getting no input from jpct.

Code: [Select]
shader = new GLSLShader(vertex, fragment);
shader.setUniform("iChannel0", 1);
shader.setUniform("iGlobalTime", 0f);
shader.setStaticUniform("iResolution", new SimpleVector(1024, 768, 24));
waterPlane.setRenderHook(shader);

67
Support / Vertices in Worldspace
« on: January 09, 2014, 10:06:55 pm »
Does the following method make sense? If not, how would I go about getting all vertices in worldspace?

Code: [Select]
     private SimpleVector wsVertices(Object3D obj) {
GenericVertexController vertexController = new GenericVertexController();
vertexController.init(obj.getMesh());
SimpleVector[] vertices = vertexController.getSourceMesh();
for (int i = 0; i < vertices.length; i++)
     vertices[i] *= obj.getTranslation(); //OR MAYBE obj.getTransformedCenter()?
return vertices;
     }

68
Support / Shadertoy
« on: December 12, 2013, 02:06:30 am »
I'd like to play around with Shadertoy's shaders. To start with, I would like to use this one: https://www.shadertoy.com/view/4slGRM. From what I gather, Shadertoy only has fragment shaders (am I right?). So I wrote a skeleton of a vertex shader that looks like this:

Code: [Select]
void main(void) {

}
I know, breathtaking, right? Still, GLSLShader tells me that the fragment shader (not my brilliant vertexshader, mind you) isn't compiled. How come?

Quote
[ Wed Dec 11 23:02:13 EST 2013 ] - ERROR: Attached fragment shader is not compiled.

Code: [Select]
// Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012.
//
// Attribution-ShareAlike CC License.

#ifdef GL_ES
precision highp float;
#endif

const float PI = 3.1415926535897932;

// play with these parameters to custimize the effect
// ===================================================

//speed
const float speed = 0.2;
const float speed_x = 0.3;
const float speed_y = 0.3;

// refraction
const float emboss = 0.50;
const float intensity = 2.4;
const int steps = 8;
const float frequency = 6.0;
const int angle = 7; // better when a prime

// reflection
const float delta = 60.;
const float intence = 700.;

const float reflectionCutOff = 0.012;
const float reflectionIntence = 200000.;

// ===================================================

float time = iGlobalTime*1.3;

  float col(vec2 coord)
  {
    float delta_theta = 2.0 * PI / float(angle);
    float col = 0.0;
    float theta = 0.0;
    for (int i = 0; i < steps; i++)
    {
      vec2 adjc = coord;
      theta = delta_theta*float(i);
      adjc.x += cos(theta)*time*speed + time * speed_x;
      adjc.y -= sin(theta)*time*speed - time * speed_y;
      col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity;
    }

    return cos(col);
  }

//---------- main

void main(void)
{
vec2 p = (gl_FragCoord.xy) / iResolution.xy, c1 = p, c2 = p;
float cc1 = col(c1);

c2.x += iResolution.x/delta;
float dx = emboss*(cc1-col(c2))/delta;

c2.x = p.x;
c2.y += iResolution.y/delta;
float dy = emboss*(cc1-col(c2))/delta;

c1.x += dx*2.;
c1.y = -(c1.y+dy*2.);

float alpha = 1.+dot(dx,dy)*intence;

float ddx = dx - reflectionCutOff;
float ddy = dy - reflectionCutOff;
if (ddx > 0. && ddy > 0.)
alpha = pow(alpha, ddx*ddy*reflectionIntence);

vec4 col = texture2D(iChannel0,c1)*(alpha);
gl_FragColor = col;
}

69
Bugs / ShadowHelper/Primitives Bug
« on: December 09, 2013, 10:12:25 pm »
At (1, 600) I can create a Receiver plane which successfully displays shadows. At (1, 1000), it doesn't work. (2, 1000) does. I would think that it's an issue with the way in which ShadowHelper displays its shadows. And I would be happier without the extra polygons.

70
Support / Normal Mapping with Bones
« on: December 07, 2013, 08:23:31 am »
The NormalMapping example on the wiki requires you to compile your model. But bones breaks with compiled models. So how do I go about applying a normal map to a bones-animated model?

71
Bones / How to Use Shaders
« on: December 07, 2013, 08:22:41 am »
The NormalMapping example on the wiki requires you to compile your model. But bones breaks with compiled models. So how do I go about applying a normal map to a bones-animated model?

72
Support / Shouldn't MemoryHelper.compact() Free All My RAM?
« on: December 06, 2013, 07:52:27 pm »
I wrote a little endless runner, which I tested with textures 512x512 in size, on both the Nexus 10 tablet and the Galaxy S4. It ran fine. On the Galaxy Tab 2, for which the game was actually written as that is my son's tablet, it doesn't run at all. I've even reduced the textures to 256x256. After loading all the textures I call MemoryHelper.compact(). But before even the first chunk of city is loaded (and during its loading process), the game crashes with an OutOfMemoryError. I would think that the model itself isn't so complex that it would crash for simply trying to load this chunk (it has a total of 36k triangles). Is it possible that compact isn't doing its job (at least not right away)? Any suggestions?

73
Support / What's the advantage of using OpenGL ES 2?
« on: November 28, 2013, 11:41:52 pm »
Future compatibility? Memory efficiency? Performance?

74
Support / Which Way is the Camera Looking?
« on: November 20, 2013, 02:56:02 am »
On the docs, you should put down which way the original camera (as returned by World.getCamera()) is looking. Is it facing down or is it on the X/Z plane?

75
Support / Quick-and-dirty Jirr Wrapper
« on: November 18, 2013, 08:39:23 am »
I'm trying to run a game written for Jirr. As it happens, the 5+ year old Jirr dll isn't working for me. So, how could I go about making a quick-and-dirty jirr wrapper for jpct to avoid the issue altogether? Alternatively, Egon, you wouldn't happen to have tried this yourlself already? :- )

Pages: 1 ... 3 4 [5] 6 7 ... 14