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.


Messages - kkl

Pages: 1 ... 7 8 [9] 10 11 ... 20
121
Support / Re: Repeating texture performance
« on: August 12, 2014, 09:15:17 am »
Hi Egon,

Thanks for the idea. I spent a good amount of time to study the deferred rendering. It seems like it will skip drawing/processing the polygon that is located behind any opaque polygon to improve performance, CMIIW. What if the polygon is partial opaque and transparent (say, an object with opaque at the center and a small portion of transparent area around its sides)? Does it defered if most area of texture is opaque or it simple treats it as all transparent? 

122
Bones / Re: Crowd animation
« on: July 09, 2014, 05:12:02 pm »
Yup, I agree. We could own most CPU resources in game. Live Wallpaper is a bit tricky, where it has to be battery optimized while giving decent performance.

I tried forcing it to ~30fps. When the fishes are out of screen, the CPU usage is ok. But when they are in the screen, CPU is as high as usual.

Maybe I should turn some of the 3D objects to 2D, so it doesn't take too much of CPU for draw calls. Else, I might need to look into hardware crowd animation. There's a gem I found that might does it; http://http.developer.nvidia.com/GPUGems3/gpugems3_ch02.html

123
Bones / Re: Crowd animation
« on: July 09, 2014, 02:33:05 am »
I'd tried with Galaxy Trend Plus and Galaxy S4. They seems to have good fps ~58fps. But the CPU usage is relatively high, accordingly to the reading after enabling 'CPU usage' in 'Developer Setting' in Android. Just wish there's another way to reduce CPU usage.

124
Bones / Re: Crowd animation
« on: July 08, 2014, 03:43:44 pm »
CMIIW, did you mean total 250 tris in 20 objects? I meant each of them has 250 tris, total up with 20 objects = 5000 tris.

125
Bones / Re: Crowd animation
« on: July 08, 2014, 12:15:37 pm »
I'm making a school of fish swimming around a curved path under the ocean, and it sure looks nice if there are more objects. Initially, I thought of putting the fishes as a single object and animate altogether, but the skeleton has to be remade in Blender for each fish and it might be a bit time consuming. If there's more skeletons joints, it might cost a lot of memory too.

I was thinking of putting all fishes into one mesh, then pass in the one shared skeleton and apply to each fish one by one in shader by using instance id. This would be best case, but I think it would be hard to implement.

Quote
can you lower polygon counts? do you need to animate all of them?
Yea, I think I could go ahead n reduce poly count further (now 250 tris each after rough remesh). Maybe some objects don't have to be animated too.

126
Bones / Re: Crowd animation
« on: July 08, 2014, 10:33:16 am »
Hi Raft,

Sorry for confusing. It's not animation that cost performance. It's the draw calls, caused by drawing too many objects.

To reduce draw calls, we could combined the all meshes into one (thus calling only one draw call). But this way it's hard to calculate bone animation as all object mesh data is in shader.

Quote
maybe you can profile it to see what slows it down?
It doesn't slow down, to be exact. It just takes alot of computing power. I'm working on live wallpaper and computing consumption is quite critical, or else the battery will drain pretty fast.
From the previous testing in hardware skinning post, we have one object with ~1ms to animate. If 20 objects, which would take ~20ms to process. I think that 1ms is roughly spent on draw call.

127
Bones / Re: Crowd animation
« on: July 08, 2014, 02:30:54 am »
Hi Egon,

Yes. It is caused by the number of draw calls. If we squeeze all meshes into one draw call, probably we need to move all animation calculations into shader, so it animates each of the meshes, right? Would love to hear from you guys on more recommendations.

128
Bones / Crowd animation
« on: July 07, 2014, 05:29:46 pm »
Hi Raft,

I have been trying with the hardware skinning and it works pretty well so far, despite of few bugs :P, but it takes alot of computing power if it's drawing the same object for >20. Just wonder if it's a good idea to move all objects animation into shader so all animations are done in hardware instead. Do you have any plan implementing this in the future?

129
Bones / Re: Hardware skinning needed
« on: June 24, 2014, 03:40:59 pm »
Hi Kiffa,

It's almost done, but there's still some problem wif the initial rotation and I didn't have time to fix that yet. It would be great if you could fix it.

The attachment contains the required java files. You would need to download the Bones source code and replace the java files with the same names.

Example usage:
Code: [Select]
try {
group = BonesIO.loadGroup(context.getAssets().open(
"models/monkey.bones"));
} catch (Exception ex) {
ex.printStackTrace();
}

for (final Animated3D o : group) {

try {
final GLSLShader shader1 = new GLSLShader(
Loader.loadTextFile(context.getAssets().open("shaders/vertex_hardware_skinning.src")),
Loader.loadTextFile(context.getAssets().open("shaders/fragment.src")));
o.setShader(shader1);
o.setRenderHook(new RenderHookAdapter(){

@Override
public void beforeRendering(int arg0) {
shader1.setUniform("skinPalette", o.getSkeletonPose().getPalette());
}

});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
o.setHardwareEnabled(true);
o.build();
o.discardMeshData();
}

Currently, I hard coded the vertex shader to support up to 10 bones only. If you wanna increase it, edit skinPalette[10] to bigger size array in vertex_hardware_skinning.src. The vertex shader also supports up to 2 light sources only, but you can go ahead and copy part of jpct original vertex shader and paste it to increase light sources.

[attachment deleted by admin]

130
Support / Re: Repeating texture performance
« on: June 19, 2014, 05:36:52 pm »
Hi Egon, sry having to bring this up again. I checked from forum and many people are saying that transparent object are the most expensive process for fillrate, but I don't quite sure how transparent object would affect the fillrate, in technical speaking. Hope I can hear more about it from you.

From what i can understand, the more transparent part fills up the screen, the more hardware cost it would be. Is it caused by the z buffer where it checks the z buffer and rewrite again, or something else?

Say, if I put a all transparent objects at background (they takes almost more than half of the screen), and leave the opaque 3D objects at front, does it help in fillrate?

131
Support / Re: GLSLShader pass matrix array
« on: June 08, 2014, 08:02:09 am »
Hi Egon,

Is it doable to pass dynamic matrix array to shader? It seems like in shader, we have to specify a fixed number of matrix uniform array size and pass values only within that limit. Is it true?

132
Bones / Re: Hardware skinning needed
« on: June 08, 2014, 07:53:11 am »
Quote
And how much faster is it now?
I tested it out by just doing a simple check on the time taken for the entire drawframe method. Test case is a model w/o texture with ~1968 vertices and 7 bones. Only 3 bones are moving. Test device is Samsung Galaxy S4 with octa core.

Here's the result:
Software: ~ 11-14 ms
Hardware skinning: ~ 1-4 ms

The test result seems to be quite promising. Anyway the rotation seems to be incorrect compared to the software version. I'll try check it out.

133
Bones / Re: Hardware skinning needed
« on: June 07, 2014, 11:42:53 am »
I got it worked!! I fixed the previous code with these:

Code: [Select]
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;

uniform vec4 additionalColor;
uniform vec4 ambientColor;

uniform float alpha;
uniform float shininess;
uniform bool useColors;

uniform float fogStart;
uniform float fogEnd;
uniform vec3 fogColor;

uniform int lightCount;

uniform mat4 skinPalette[7];

uniform vec3 lightPositions[8];
uniform vec3 diffuseColors[8];
uniform vec3 specularColors[8];
uniform float attenuation[8];

attribute vec4 position;
attribute vec3 normal;
attribute vec4 color;
attribute vec2 texture0;
attribute vec2 texture1;
attribute vec2 texture2;
attribute vec2 texture3;

attribute vec4 skinWeights;
attribute vec4 skinJointIndices;

varying vec2 texCoord[4];
varying vec4 vertexColor;
varying vec3 fogVertexColor;
varying float fogWeight;

const vec4 WHITE = vec4(1,1,1,1);

void main() {

texCoord[0] = texture0;
texCoord[1] = (textureMatrix * vec4(texture1, 0, 1)).xy;
texCoord[2] = texture2;
texCoord[3] = texture3;

vec4 myPosition = vec4(0,0,0,0);
vec3 myNormal = vec3(0,0,0);

vec4 vertexTemp;
vec3 normalTemp;
mat4 mat;

for (int i = 0; i < 4; i++) {
mat = skinPalette[int(skinJointIndices[i])];
vertexTemp = mat * position;
vertexTemp *= skinWeights[i];
myPosition += vertexTemp;
normalTemp = mat3(mat) * normal;
normalTemp *= skinWeights[i];
myNormal += normalTemp;
}

vec4 vertexPos = modelViewMatrix * myPosition;
vertexColor = ambientColor + additionalColor;

if (lightCount>0) {
// This is correct only if the modelview matrix is orthogonal. In jPCT-AE, it always is...unless you fiddle around with it.
vec3 normalEye   = normalize(modelViewMatrix * vec4(myNormal, 0.0)).xyz;

float angle = dot(normalEye, normalize(lightPositions[0] - vertexPos.xyz));

if (angle > 0.0) {
vertexColor += vec4((diffuseColors[0] * angle + specularColors[0] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[0] - vertexPos.xyz)*attenuation[0])), 1);
}

// Freaky Adreno shader compiler can't handle loops without locking or creating garbage results....this is why the
// loop has been unrolled here. It's faster this way on PowerVR SGX540 too, even if PVRUniSCoEditor says otherwise...

if (lightCount>1) {
angle = dot(normalEye, normalize(lightPositions[1] - vertexPos.xyz));

if (angle > 0.0) {
vertexColor += vec4((diffuseColors[1] * angle + specularColors[1] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[1] - vertexPos.xyz)*attenuation[1])), 1);
}

}
}


if (fogStart != -1.0) {
fogWeight = clamp((-vertexPos.z - fogStart) / (fogEnd - fogStart), 0.0, 1.0);
fogVertexColor = fogColor * fogWeight;
} else {
fogWeight = -1.0;
}

vertexColor=vec4(min(WHITE, vertexColor).xyz, alpha);

if (useColors) {
vertexColor *= color;
}

gl_Position = modelViewProjectionMatrix * myPosition;
}

where myPosition and myNormal are initialized to zero.  But the normal seems to be abit off. I'm looking into it.

134
Bones / Re: Hardware skinning needed
« on: June 07, 2014, 10:13:31 am »
Hi Raft,

I've spending few weeks to implemet hardware skinning, but I encountered few problems and I hope you could help me out on this

I've made these code, but the result seems incorrect:

vertex shader: skinPalette is hardcoded to match the bones file I have (im not sure if the number of matrix palettes is fixed).
Code: [Select]
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;

uniform vec4 additionalColor;
uniform vec4 ambientColor;

uniform float alpha;
uniform float shininess;
uniform bool useColors;

uniform float fogStart;
uniform float fogEnd;
uniform vec3 fogColor;

uniform int lightCount;

uniform mat4 skinPalette[7];

uniform vec3 lightPositions[8];
uniform vec3 diffuseColors[8];
uniform vec3 specularColors[8];
uniform float attenuation[8];

attribute vec4 position;
attribute vec3 normal;
attribute vec4 color;
attribute vec2 texture0;
attribute vec2 texture1;
attribute vec2 texture2;
attribute vec2 texture3;

attribute vec4 skinWeights;
attribute vec4 skinJointIndices;

varying vec2 texCoord[4];
varying vec4 vertexColor;
varying vec3 fogVertexColor;
varying float fogWeight;

const vec4 WHITE = vec4(1,1,1,1);

void main() {

texCoord[0] = texture0;
texCoord[1] = (textureMatrix * vec4(texture1, 0, 1)).xy;
texCoord[2] = texture2;
texCoord[3] = texture3;

vec4 myPosition = vec4(position);
vec3 myNormal = vec3(normal);

vec4 vertexTemp;
vec3 normalTemp;
mat4 mat;


for (int i = 0; i < 4; i++) {
mat = skinPalette[int(skinJointIndices[i])];
vertexTemp = mat * position;
vertexTemp *= skinWeights[i];
myPosition += vertexTemp;
normalTemp = normal * mat3(mat);
normalTemp *= skinWeights[i];
myNormal += normalTemp;
}

vec4 vertexPos = modelViewMatrix * myPosition;
vertexColor = ambientColor + additionalColor;

if (lightCount>0) {
// This is correct only if the modelview matrix is orthogonal. In jPCT-AE, it always is...unless you fiddle around with it.
vec3 normalEye   = normalize(modelViewMatrix * vec4(myNormal, 0.0)).xyz;

float angle = dot(normalEye, normalize(lightPositions[0] - vertexPos.xyz));

if (angle > 0.0) {
vertexColor += vec4((diffuseColors[0] * angle + specularColors[0] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[0] - vertexPos.xyz)*attenuation[0])), 1);
}

// Freaky Adreno shader compiler can't handle loops without locking or creating garbage results....this is why the
// loop has been unrolled here. It's faster this way on PowerVR SGX540 too, even if PVRUniSCoEditor says otherwise...

if (lightCount>1) {
angle = dot(normalEye, normalize(lightPositions[1] - vertexPos.xyz));

if (angle > 0.0) {
vertexColor += vec4((diffuseColors[1] * angle + specularColors[1] * pow(angle, shininess))*(1.0/(1.0+length(lightPositions[1] - vertexPos.xyz)*attenuation[1])), 1);
}

}
}


if (fogStart != -1.0) {
fogWeight = clamp((-vertexPos.z - fogStart) / (fogEnd - fogStart), 0.0, 1.0);
fogVertexColor = fogColor * fogWeight;
} else {
fogWeight = -1.0;
}

vertexColor=vec4(min(WHITE, vertexColor).xyz, alpha);

if (useColors) {
vertexColor *= color;
}

gl_Position = modelViewProjectionMatrix * myPosition;
}

This's the code to add vertex attributes to shader. linearizeArray is converting float[][] to float[] and linearizeToFloatArray is short[][] to float[]
Code: [Select]
float[] f1 = SkinHelper.linearizeArray(skin.weights);
float[] f2 = SkinHelper.linearizeToFloatArray(skin.jointIndices);
skinWeights = new VertexAttributes(
"skinWeights", f1, VertexAttributes.TYPE_FOUR_FLOATS);
skinJointIndices = new VertexAttributes(
"skinJointIndices", f2, VertexAttributes.TYPE_FOUR_FLOATS);
Mesh mesh = getMesh();
mesh.addVertexAttributes(skinWeights);
mesh.addVertexAttributes(skinJointIndices);

This's where I set the uniform for matrix palette (in array form, Egon created a new GLSLShader to pass matrix array).
Code: [Select]
object3D.setRenderHook(new RenderHookAdapter(){

@Override
public void setCurrentShader(GLSLShader shader) {
super.setCurrentShader(shader);
shader.setUniform("skinPalette", object3D.getSkeletonPose().getPalette());
}
});

I tried to debug glsl and most debugger I tried were not working. Hope you could help me out on this. May be I missed something.

135
Support / Re: GLSL debug
« on: June 06, 2014, 12:01:55 pm »
That's pretty cool that you built the entire JPCT shader without using debugger~ how did you do that?

Pages: 1 ... 7 8 [9] 10 11 ... 20