Sunday 21 October 2018

Cellular automata in JPCT

I was looking for a diversion this week so i decided to attempt to recreate Conways Game of Life using shaders in JPCT for Android:

I wanted to see if it could be done, and figure implementing to run in a shader in the GPU will be a lot faster than running it on a device CPU.

This is because Conways Game of Life could be called an "embarrassingly parallel" problem, as long as all cell calculations are completed by the next tick of course.

I reused code i wrote while attempting to create a fluid dynamics effect (failed project) as some of the methods to implement it, were similar, ie. passing the comutations back and forth between two textures.

The four basic rules of Conways Game of Life (taken from wikipedia) are:

  1. Any live cell with fewer than two live neighbors dies, as if by underpopulation.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
 I was able to implement this using the GLSL step function in two lines as show below.
I used step functions native to GLSL to avoid IF statements, as branching can slow down shaders.

float newval = ( step(neighbourcells.x,3.0) * step(  2.0 ,  neighbourcells.x)) * cell.x;newval += step(neighbourcells.x, 3.0)*step(  3.0 ,  neighbourcells.x); /

Below is a screen shot of this running on my android device. 

Because it's running at the device screen resolution you really have to zoom in to make out the cells.

I plan to keep going back to this to allow users to draw to the screen and make cosmetic changes etc.

Sunday 28 January 2018

A procedural world.

I decided before Christmas ,after learning just a bit more about shaders that i would attempt to make world at the centre of this game procedural instead of relying on textures.

The reasoning for this being :

  • Reduce the number of textures stored in the app and in memory while it's running.
  • Have a greater variety or worlds.
  • Free myself partially from content creation(still an issue as i keep tweaking things)
  • Build up a repertoire of techniques i can return to for later games, projects
  • Expand my own learning of GLSL.

Some of the cons so far:
  • What i sacrifice in memory usage is taken from GPU power and more device power usage
  • The algorithms require a lot of tweaking to looking plausible and pleasing(this becomes a time sink, but at least i'm learning) 
  • Testing all this slow.
  • There maybe future unforeseen consequences, due to GPU changes that cause the code to behave incorrectly or simply not work at all.

To do this i initially started by working with a GLSL plasma function, i modified this ( )function to produce 3d noise instead of 2d based on the location of the point that is being drawn within the 3d space, as opposed to the points location on the texture. The reasoning for this is that it creates more seamless realistic textures on 3d objects such as a sphere.

  1. By layering a few of these functions , having the results from some subtract and results from others add i created float representing height between 0.0 and 1.0. 
  2. Using that i then set a cut off at 0.5,. Anything below is water anything above is land.
  3. From there i can subdivide it further into, deep water, shallows, lowlands, mountains etc (citiy lights are just a texture so far)

Will updates this tomorrow with changes to this. 

Thursday 22 June 2017

Switching to Unity

After a few years of grappling with JPCT and learning a bit about game loops and shaders along the way i have decided to attempt to move to Unity.

The reasons being:

1.JPCT is a graphics framework, not a games development on, so it doesn't cover many things like audio, etc that i need.

2.Unity would allow me to write something for multiple types of devices with less worry about compatibility.

3.Unity is developing much faster and has much more tools, assets etc available. Not to mention many tutorials.

JPCT was useful however and i learned at lot from it that i would not have learnt from using Unity.

Unity was great but unsuitable for my project.

Monday 2 May 2016

A specular earth

Made changes to the GLSL shaders for the planet surface in my game.
It now reflective oceans on the day side and a glowing city light effect on the darkside.

Still not happy with this as it doesn't look as sharp as i would like it to, and the only way i can think of improving this is at the moment by increasing texture resolutions, which seems far too much like a brute force solution.

This video also demos the signed distance field buttons i intend to use instead of the Android UI buttons.

They currently all require a double tap, i may change this to a single as it get's tedious.

Other things i need to work on are the backround (which now looks relatively bad compared to the high res planet texture)

Fragment Shader for the planet. Is based on this specular example for OpenGL at this link  but modified to suite my needs and to work with JPCT. This shader isn't final.

uniform vec3 uAmbient;//should alwasy be black in this space game?uniform vec3 uDiffuse; // the texture?uniform vec3 uSpecular; // the strong reflected lightuniform float uSpecIntensity;uniform float uTransparency;
uniform vec3 lightPositions[8];
varying vec3 N;varying vec3 v;varying vec2 texCoord;

uniform sampler2D textureUnit0;//main textureuniform sampler2D textureUnit1;//specular map?uniform sampler2D textureUnit2;//night/glowing texture.

uniform lowp  int glow_on;

vec4 allsidesGlow()
return texture2D(textureUnit2, texCoord);}

vec4 darksideGlow()

      vec4 color = vec4(0.0,0.0,0.0,1.0);      vec4 base = texture2D(textureUnit2, texCoord);      vec4 shinytex = texture2D(textureUnit1, texCoord);      float shine = (shinytex.x +shinytex.y +shinytex.z) /3.0;
      vec3 L = normalize(lightPositions[0] - v);      L.x=-L.x;      L.y=-L.y;      L.z=-L.z;
      vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)      vec3 R = normalize(-reflect(L,N));      //calculate Ambient Term:      vec4 Iamb = vec4(uAmbient,1);
      //calculate Diffuse Term:      vec4 Idiff =  vec4(uDiffuse,1 )* max(dot(N,L), 0.0);      Idiff = clamp(Idiff, 0.0, 1.0);

      if(shine < 0.1)
      {  //This is landmass        color = (vec4(uAmbient,1.0) *base) + Iamb + (Idiff*base);      }
      else      {
         color = vec4(0,0,0,1.0);      }

return color;}

void main(void)

vec4 col  = vec4(0.0,0.0,0.0,1.0);vec4 darksidevec=darkside();if(glow_on == 0)
   vec4 base = texture2D(textureUnit0, texCoord);   vec4 shinytex = texture2D(textureUnit1, texCoord);   float  shine = (shinytex.x +shinytex.y +shinytex.z) /3.0;   //vec4 ambienttexture = texture2D(textureUnit2, texCoord);   vec3 amb=;

   vec3 L = normalize(lightPositions[0] - v);   vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)   vec3 R = normalize(-reflect(L,N));   //calculate Ambient Term:   vec4 Iamb = vec4(amb,1);
   //calculate Diffuse Term:   vec4 Idiff =  vec4(uDiffuse,1 )* max(dot(N,L), 0.0);   Idiff = clamp(Idiff, 0.0, 1.0);

   if(shine < 0.29)
     col = (vec4(amb,1.0) *base) + Iamb + (Idiff*base);   }
   else   {
     // calculate Specular Term:                                   //shinyness is here      vec4 Ispec = vec4(uSpecular,1.0 ) * pow(max(dot(R,E),0.0),90.0*shine);//0.3*shine);///REALLY IMPORTANT      Ispec = clamp(Ispec, 0.0, 1.0);      col = (vec4(amb,1.0) *base) + Iamb + (Idiff*base) + Ispec;   }
 else {//This does the nightside
      col =darksidevec; }

   gl_FragColor = col;}

Monday 28 March 2016

Signed Distance fields fonts

I'm currently working on a hobby game project for Android using the JPCT opengl library .
While doing this i noticed that i would have to either use androids standard UI widgets or "BLIT" ui objects using JPCT's blitter.

Neither of these were suitable to me as i wanted to build a spatial UI type

I found a potentially good way to do this reading about "Signed Distance Fields".  This method also interested me as it was an excuse to work with graphics shaders.

Not wanting to reinvent the wheel i first learn how this version for the Cinder library worked .

Then translated it into something that would work as a GLSL ES shader for the JPCT Library.

I ended up with with this, The image below is a screenshot of the program i made running on the android emulator using different font set's i imported as PNG's

These include a Rongorongo font
And a Hieroglyph font

Here is a link a github project af this project here

Below are some screen shots of a later version of my signed distance fields being used my game , running on an Android device . 


The main menu buttons. The play/pause toggle button and the "awesome face" button attached the planet are all done using signed distance fields.  The other four buttons that are in ever screen shot are standard android UI buttons i'm using to test some features.

Monday 21 March 2016

Who runs


Publishing this post so it's recorded somewhere a little less ephemeral than Twitter just some of what "" is upto.

Background. is am Irish "newsite" renowned for lifting stories from elsewhere and running questionable competitions to increase it's popularity on social media.

But it's also used to push the far right wing views of its founder Leo Sherlock and his Sister Cora Sherlock who runs the Irish anti-choice group "Pro Life Campaign Ireland". The following will just be demonstrating Cora's link to the site and some interesting posts from one of their admins in the run up to the marriage referendum.

Facebook Insights is a tool used for analyzing traffic coming from Facebook to a website.
Domain Insights shows all referral traffic to your domain from Facebook, including when people link to your site in their Facebook status messages, clicks on social plugins such as the Like or Share button, and more. Domain Insights also provides sharing metrics and demographic information per domain and per URL so you can optimize your content for sharing and better tailor your content to your audience. 
Site owners add tags containing their admins Facebook ID to the headers on the page. 
 property="fb:admins" content="1234" />
. has two of these tags. One corresponds to the Facebook account of Cora Sherlock herself suggesting she has strong role in the running of the site the other ID included belongs to a "David Knight".

546782817 Cora.
100003753785672 David.

This is in the source of every page served by TheLiberal and anyone can view by simply right clicking and selecting "View Source" on any of their websites pages. 

The numbers  can be added to the facebook url by anyone leading them back to those profiles.

With Cora Sherlock this closely involved it's impossible to believe anything published particularly in relation to abortion , reproductive choice  and the 8th amendment could ever approach being unbiased :

But as promoters of the far right they're not focused on just single issues. As the other tagged admin "David Knight" demonstrated on TheLiberals Facebook page in the days before the marriage referendum trying to confuse voters.

Shouldn't  need more to conclude that Cora Sherlock , "David Knight" and their site TheLiberal probably aren't the most trustworthy sources for news, even now when the independence of a lot of other Irish media is questionable.

Note 22/06/2017
The tags referencing Coras account appear to have been removed now.

Wednesday 6 November 2013

I have pushed my college project on classifying facial expressions using neural networks to github.