Skip to content

Commit

Permalink
M1 complete, M2 needs normals -sG
Browse files Browse the repository at this point in the history
  • Loading branch information
SethGibson committed May 16, 2015
1 parent 44dfd34 commit 3593100
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 53 deletions.
Binary file added Content/01_morning/export/01_nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/01_morning/export/01_ny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/01_morning/export/01_nz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/01_morning/export/01_px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/01_morning/export/01_py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/01_morning/export/01_pz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_ny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_nz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/02_midday/export/02_pz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_ny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_nz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/03_dusk/export/03_pz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_ny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_nz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/04_nightsky/export/04_pz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/05_starry/export/05_nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/05_starry/export/05_ny.png
Binary file added Content/05_starry/export/05_nz.png
Binary file added Content/05_starry/export/05_px.png
Binary file added Content/05_starry/export/05_py.png
Binary file added Content/05_starry/export/05_pz.png
Binary file modified app/app-release.apk
Binary file not shown.
5 changes: 3 additions & 2 deletions app/src/main/assets/frag_instance.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ varying vec3 WorldPos;

void main()
{
vec3 normal = normalize(Normal);
vec3 lightDir = normalize(uLightPos-WorldPos);
float diffContrib = max(dot(Normal,lightDir),0.0);
gl_FragColor = max(Color*diffContrib,(Color*0.25));
float diffContrib = max(dot(normal,lightDir),0.0);
gl_FragColor = Color*diffContrib+Color*0.2;
}
9 changes: 4 additions & 5 deletions app/src/main/assets/vertex_instance.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ void main()
{
Color = iColor;

vec4 finalPosition = (vec4(vPosition.xyz*vec3(iSize),1.0)+vec4(iPosition,1.0));
vec3 finalPosition = vPosition.xyz*vec3(iSize)+iPosition;

Normal = mat3(uNormalMatrix) * vNormal;
WorldPos = vec3(uModelMatrix*finalPosition);

gl_Position = uProjMatrix*uViewMatrix*uModelMatrix*finalPosition;
Normal = vec3(uViewMatrix*uModelMatrix*vec4(vNormal,0.0));
WorldPos = vec3(uViewMatrix*uModelMatrix*vPosition);
gl_Position = uProjMatrix*uViewMatrix*uModelMatrix*vec4(finalPosition,1.0);
}
92 changes: 74 additions & 18 deletions app/src/main/java/org/xdd/cosmicdancer/CloudRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.Point;
import android.opengl.GLSurfaceView;
import android.os.SystemClock;
import android.transition.Scene;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
Expand All @@ -22,13 +23,15 @@ public class CloudRenderer implements GLSurfaceView.Renderer
public ShaderManager mShaderMgr;

//Skybox
private int S_NUM_CUBEMAPS = 5;
private int S_TRANS_TIME_MILLIS = 5000;
public SkyboxManager mSkyboxMgr;
private int mSkyboxProgID;
private int[] mSkyboxTexIDs = new int[5];
private int mSkyboxVaoID;
private int mSkyboxProgID;
private int[] mSkyboxTexIDs = new int[S_NUM_CUBEMAPS];
private int mSkyboxCurrentID = 0;


private float mYAngle = 0f;
private float mYRate = 0.2f;

//Pointcloud
public PointCloudManager mCloudMgr;
Expand All @@ -53,18 +56,19 @@ public CloudRenderer(Context pContext)
Point cSize = new Point();
cDisp.getSize(cSize);
mAspect = (float)cSize.x/(float)cSize.y;
mStartTime = System.currentTimeMillis();
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
glClearColor(0.25f, 0.25f, 0.25f, 1f);
mCamera = new SceneManager.Camera( 0, 0, 25,
mCamera = new SceneManager.Camera( 0, 0, 40,
0, 0, 0,
0, 1, 0,
0.1f,500.0f,
45.0f);
mLightPosition[0] = 0;mLightPosition[1] = 10;mLightPosition[2] = 10;
mLightPosition[0] = 0;mLightPosition[1] = 0;mLightPosition[2] = 40;
mShaderMgr = new ShaderManager(mContext);
mSkyboxMgr = new SkyboxManager(mContext, mShaderMgr);
mCloudMgr = new PointCloudManager(mContext,mShaderMgr);
Expand Down Expand Up @@ -96,24 +100,29 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config)

mCloudProgID = mCloudMgr.CreateProgram();

int numCirclePoints = 16;
float[] meshData = new float[(numCirclePoints+1)*6];
byte[] indexData = new byte[numCirclePoints*3];
SceneManager.GetCircleVerts(numCirclePoints, meshData, indexData);
int subdAxis = 16;
int subdHeight = 16;
float radius = 1.0f;
float[] meshData = new float[subdAxis*subdHeight*6];
int[] indexData = new int[(subdAxis*subdHeight+subdAxis)*6];
//SceneManager.GetCircleVerts(numCirclePoints, meshData, indexData);
SceneManager.GetSphereVerts(meshData,indexData,radius,subdAxis,subdHeight);

int meshVBO = mCloudMgr.CreateArrayBuffer(meshData, GL_STATIC_DRAW);
int instanceVBO = mCloudMgr.CreateArrayBuffer(instanceData, GL_STATIC_DRAW);
int indexVBO = mCloudMgr.CreateElementBuffer(indexData, GL_STATIC_DRAW);
int elementCount = meshData.length/6;
int indexVBO = mCloudMgr.CreateElementIntBuffer(indexData, GL_STATIC_DRAW);
int elementCount = meshData.length;
int instanceCount = instanceData.length/7;
mPointCloud = mCloudMgr.CreatePointCloud(meshVBO, elementCount, instanceVBO, instanceCount, indexVBO, mCloudProgID);
mPointCloud = mCloudMgr.CreatePointCloud(meshVBO, elementCount, instanceVBO, instanceCount, indexVBO, mCloudProgID, GL_UNSIGNED_INT);

/*
float[] meshData = SceneManager.GetCubeVerts();
float[] meshData = new float[60*6];
SceneManager.GetHedronVerts(meshData);
//float[] meshData = SceneManager.GetCubeVerts();
int meshVBO = mCloudMgr.CreateArrayBuffer(meshData, GL_STATIC_DRAW);
int instanceVBO = mCloudMgr.CreateArrayBuffer(instanceData, GL_STATIC_DRAW);
int elementCount = meshData.length/6;
int instanceCount = instanceData.length/7;
mPointCloud = mCloudMgr.CreatePointCloud(meshVBO, elementCount, instanceVBO, instanceCount, -1, mCloudProgID);
*/
}
Expand All @@ -129,10 +138,16 @@ public void onSurfaceChanged(GL10 gl, int width, int height)
public void onDrawFrame(GL10 gl)
{
long sysTime = System.nanoTime();
long elapsedTime = System.currentTimeMillis() - mStartTime;
if(elapsedTime>S_TRANS_TIME_MILLIS)
{
mStartTime = System.currentTimeMillis();
mSkyboxCurrentID = (mSkyboxCurrentID+1)%S_NUM_CUBEMAPS;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

mSkyboxMgr.SetMatrices(mAspect, 45.0f, 0.1f, 10.0f, new float[]{0, 0, 0});
mSkyboxMgr.DrawSkybox(mSkyboxVaoID, mSkyboxProgID, mSkyboxTexIDs[0]);
mSkyboxMgr.DrawSkybox(mSkyboxVaoID, mSkyboxProgID, mSkyboxTexIDs[mSkyboxCurrentID]);

float xAngle = sysTime*0.00000002f;
float yAngle = sysTime*0.00000004f;
Expand All @@ -145,10 +160,51 @@ public void onDrawFrame(GL10 gl)
public void SetupSkyboxes()
{
//load textures
//morning
int[] skyboxIds = new int[]
{
R.drawable.01_px,
}
R.drawable.px01,R.drawable.nx01,
R.drawable.py01,R.drawable.ny01,
R.drawable.pz01,R.drawable.nz01
};
mSkyboxTexIDs[0] = mSkyboxMgr.CreateCubemap(skyboxIds);

//midday
skyboxIds = new int[]
{
R.drawable.px02,R.drawable.nx02,
R.drawable.py02,R.drawable.ny02,
R.drawable.pz02,R.drawable.nz02
};
mSkyboxTexIDs[1] = mSkyboxMgr.CreateCubemap(skyboxIds);

//dusk
skyboxIds = new int[]
{
R.drawable.px03,R.drawable.nx03,
R.drawable.py03,R.drawable.ny03,
R.drawable.pz03,R.drawable.nz03
};
mSkyboxTexIDs[2] = mSkyboxMgr.CreateCubemap(skyboxIds);

//evening
skyboxIds = new int[]
{
R.drawable.px04,R.drawable.nx04,
R.drawable.py04,R.drawable.ny04,
R.drawable.pz04,R.drawable.nz04
};
mSkyboxTexIDs[3] = mSkyboxMgr.CreateCubemap(skyboxIds);

//stars
skyboxIds = new int[]
{
R.drawable.px05,R.drawable.nx05,
R.drawable.py05,R.drawable.ny05,
R.drawable.pz05,R.drawable.nz05
};
mSkyboxTexIDs[4] = mSkyboxMgr.CreateCubemap(skyboxIds);


//setup program
mSkyboxProgID = mSkyboxMgr.CreateProgram();
Expand Down
38 changes: 31 additions & 7 deletions app/src/main/java/org/xdd/cosmicdancer/PointCloudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

public class PointCloudManager
{
Expand All @@ -20,6 +21,7 @@ public class CloudData
public int GlslProgram;
public int ElementCount;
public int InstanceCount;
public int IndexType;

public CloudData()
{
Expand All @@ -29,9 +31,10 @@ public CloudData()
IndexVBO = -1;
GlslProgram = -1;
ElementCount = -1;
IndexType = -1;
}

public CloudData(int pVAO, int pMeshID, int pNumElem, int pInstID, int pNumInst, int pIndexID, int pProgID)
public CloudData(int pVAO, int pMeshID, int pNumElem, int pInstID, int pNumInst, int pIndexID, int pProgID, int pIndexType)
{
CloudVAO = pVAO;
MeshVBO = pMeshID;
Expand All @@ -40,6 +43,7 @@ public CloudData(int pVAO, int pMeshID, int pNumElem, int pInstID, int pNumInst,
GlslProgram = pProgID;
ElementCount = pNumElem;
InstanceCount = pNumInst;
IndexType = pIndexType;
}
};

Expand Down Expand Up @@ -77,6 +81,7 @@ public CloudData(int pVAO, int pMeshID, int pNumElem, int pInstID, int pNumInst,
private static int S_SIZE_NORM = 3;
private static int S_SIZE_SCALE = 1;
private static int S_SIZE_FLOAT = 4;
private static int S_SIZE_INT = 4;
private static int S_VERTEX_STRIDE;
private static int S_INSTANCE_STRIDE;

Expand Down Expand Up @@ -144,7 +149,7 @@ public int CreateArrayBuffer(float[] pData, int pUsage)
return vboID[0];
}

public int CreateElementBuffer(byte[] pData, int pUsage)
public int CreateElementByteBuffer(byte[] pData, int pUsage)
{
ByteBuffer dataBuffer = ByteBuffer.allocateDirect(pData.length)
.put(pData);
Expand All @@ -159,7 +164,24 @@ public int CreateElementBuffer(byte[] pData, int pUsage)
return vboID[0];
}

public CloudData CreatePointCloud(int pMeshVBO, int pNumElems, int pInstanceVBO, int pNumInst, int pIndexVBO, int pProg)
public int CreateElementIntBuffer(int[] pData, int pUsage)
{
IntBuffer dataBuffer = ByteBuffer.allocateDirect(pData.length*S_SIZE_INT)
.order(ByteOrder.nativeOrder())
.asIntBuffer();
dataBuffer.put(pData);
dataBuffer.position(0);

int[] vboID = new int[1];
glGenBuffers(1,vboID,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID[0]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, pData.length*S_SIZE_INT, dataBuffer, pUsage);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);

return vboID[0];
}

public CloudData CreatePointCloud(int pMeshVBO, int pNumElems, int pInstanceVBO, int pNumInst, int pIndexVBO, int pProg, int pIndexType)
{
int elementCount = pNumElems;
if(pIndexVBO>=0)
Expand Down Expand Up @@ -193,7 +215,7 @@ public CloudData CreatePointCloud(int pMeshVBO, int pNumElems, int pInstanceVBO,
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

return new CloudData(cVaoID[0],pMeshVBO, elementCount, pInstanceVBO, pNumInst, pIndexVBO,pProg);
return new CloudData(cVaoID[0],pMeshVBO, elementCount, pInstanceVBO, pNumInst, pIndexVBO,pProg,pIndexType);
}

public void SetMatrix(SceneManager.Camera pCamera, float pAspect, float[] pTrans, float[] pRot)
Expand All @@ -213,7 +235,9 @@ public void SetMatrix(SceneManager.Camera pCamera, float pAspect, float[] pTrans
perspectiveM(mProjMatrix, 0, pCamera.FOV, pAspect, pCamera.NearClip, pCamera.FarClip);

setIdentityM(mNormMatrix, 0);
invertM(mNormMatrix,0,mModelMatrix,0);
multiplyMM(mNormMatrix,0,mViewMatrix,0,mModelMatrix,0);
invertM(mNormMatrix, 0, mNormMatrix, 0);
transposeM(mNormMatrix,0,mNormMatrix,0);
}

public void DrawCloud(CloudData pCloudData, float[] pLightPos)
Expand All @@ -222,15 +246,15 @@ public void DrawCloud(CloudData pCloudData, float[] pLightPos)
glUniformMatrix4fv(mLocModelM, 1, false, mModelMatrix, 0);
glUniformMatrix4fv(mLocViewM, 1, false, mViewMatrix, 0);
glUniformMatrix4fv(mLocProjM, 1, false, mProjMatrix, 0);
glUniformMatrix4fv(mLocNormM, 1, true, mNormMatrix, 0);
glUniformMatrix4fv(mLocNormM, 1, false, mNormMatrix, 0);
glUniform3fv(mLocLightPos,1,pLightPos,0);

glBindVertexArray(pCloudData.CloudVAO);

if(pCloudData.IndexVBO>=0)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pCloudData.IndexVBO);
glDrawElementsInstanced(GL_TRIANGLES,pCloudData.ElementCount,GL_UNSIGNED_BYTE,0,pCloudData.InstanceCount);
glDrawElementsInstanced(GL_TRIANGLES,pCloudData.ElementCount,pCloudData.IndexType,0,pCloudData.InstanceCount);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else
Expand Down
Loading

0 comments on commit 3593100

Please sign in to comment.