Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3D VoxelArt Character  (Read 1993 times)
0 Members and 1 Guest are viewing this topic.
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Posted 2014-06-15 22:23:31 »

Soooo ... I'm making a 3D game (Should be some kind of MOBA KitPvP but for the art that's irrelevant Cheesy )

The problem is: I'm totally too bad on making good Character Models.
The whole Game should be Voxel-Based (to make it easier to generate a limited random world the players can interact with, e.q. Cutting down Trees, collect Berries etc.)
Creating some Example Trees is quite easy, getting generated by the Server randomly (Same with Bushes for Berries etc.)
But for Character Models that won't work (For Monsters or Animals that run arround neither) so i made myself an editor that lets me create Voxel Models and export in a format that saves space and lets me load them very simple (Into VBOs). There's 2 Files the Editor produces: the Geometry Data containing each Voxel's Position and Color (For Modelloading and -Editing purpose) , and the File that gets used for loading the Model, it just contains the Color, Normals and Vertices for only the faces that are Visible, so Cubes inside of a Model get Lost in this Format.

So well, Can anyone show me a good Tutorial for 3D Voxel Characters that don't have too many vertices? or Any ideas how to Improve Mine cause i think it doesn't look too good:  Huh
Offline Drenius
« Reply #1 - Posted 2014-06-16 15:10:25 »

It looks good...
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #2 - Posted 2014-06-16 19:49:58 »

What, really? i mean look at Cube Worlds Voxel models:

or this one over here which is just an example from a voxel editor i found online:


The one from cubeworld deffinitly needs more Power to render cause it has much more voxels in it, but the second one looks very good in my opinion and has arround the same amout of cubes my model has.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #3 - Posted 2014-06-16 19:52:51 »

Just reproduced the second Character and well ... it doesn't look that good in my program Clueless the hair looks very strange cause the faces that point in the same direction have exactly the same color, in the editor it's not as you can see in my post above, so it's deffinitly the shaders which make my models look less good  Lips Sealed any tutorial on how to improve that?
Offline Drenius
« Reply #4 - Posted 2014-06-16 19:54:05 »

CubeWorld avatar > your model > ... > ... > the example you found.
Seriously, go that way and it will be fine.
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #5 - Posted 2014-06-16 20:05:47 »

Oh okay, so it's just me thinking that all the Art (if 2D or 3D) i make is worse than everyone else's stuff?  Shocked
Offline PandaMoniumHUN

JGO Coder


Medals: 32
Exp: 3 years


White-bearded OGL wizard


« Reply #6 - Posted 2014-06-16 20:12:32 »

Oh okay, so it's just me thinking that all the Art (if 2D or 3D) i make is worse than everyone else's stuff?  Shocked
It's probably because your program doesn't use any kind of lighting/shading and anti aliasing.
However, I would suggest you not to work too much on the tiny details of the tool, but rather spend the time developing the game itself. As long as you can get the job done with the tool it's fine and helpful, but spending days trying to make your models look better in your voxel editor is rather counterintuitive. Smiley

My Blog | Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #7 - Posted 2014-06-16 20:16:18 »

Well i don't want them to look good in the model editor, i want them to look good in the game (might as well switch to the modeleditor I got that image from cause it has much more functions) but in my game they look less good and that's what disappoints me, cause it does not look the way i want it to Smiley
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #8 - Posted 2014-06-16 21:09:11 »

 

Tryed the model i made myself out in the editor with their shaders and I think it looks way better, So for now i'll focus on making the actual game and make better Shaders for it later Smiley
Offline OpenGLShaders
« Reply #9 - Posted 2014-06-16 21:31:32 »

When/if you get to shaders, look into per pixel lighting, ambient occlusion, and a specular component. That should make it look more like the cube world photo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #10 - Posted 2014-06-16 23:45:40 »

Okay, I'll start with the Ambient Occlusion cause that's what i think will help me the most, next I'll go with per pixel lighting and the the specular component. That's all in the Fragment Shader isn't it? cause it doesn't apply to the whole face i guess
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #11 - Posted 2014-06-19 23:52:15 »

Can someone help me with the Point Light per pixel? :/

the only thing not working is placing the Light source. as you can see i set the position to a very high y amount so basically it shouldn't be visible at all but in the 3D room, the light comes from the Point(0|0|0)

Vertex Shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
varying vec4 pos;

void main()
{
   gl_TexCoord[0] = gl_MultiTexCoord0;
   
   pos = gl_Vertex;
   
   gl_Position = ftransform();
   
   vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
   
   vec4 mul = vec4(normal.z,normal.z,normal.z,1.0);
   
   gl_FrontColor = gl_Color * mul;
}

Fragment Shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
uniform sampler2D tex;
// Lights
uniform vec3 lpos[100];
uniform vec3 color[100];
uniform float intense[100];
uniform int amount;
uniform float alpha[100];

varying vec4 pos;

void main()
{  
   int i;
   vec4 finalcolor = texture2D(tex,gl_TexCoord[0].st)*gl_Color;
   for(i = 0; i < amount; i++){
      // distance
      vec3 ppos = vec3(pos.x,pos.y,pos.z);
      float distance = length(lpos[i]-ppos);
     
      if(distance < intense[i]){
         float falpha = 1.0-(distance/intense[i]);
         finalcolor.r = finalcolor.r + color[i].r * falpha * alpha[i];
         finalcolor.g = finalcolor.g + color[i].g * falpha * alpha[i];
         finalcolor.b = finalcolor.b + color[i].b * falpha * alpha[i];
      }
   }
   gl_FragColor = finalcolor;
}

Rendering:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void render() {
      cam.lookThrough();
      test.shader.addLight(new Vector3f(0, 1000000, 0),
            new Vector3f(1, 0, 0), 1f, 10);
      GL11.glColor4f(r, g, b, a);

      GL11.glBegin(GL11.GL_LINES);
      GL11.glVertex3f(-10f, 0, 0);
      GL11.glVertex3f(10f, 0, 0);
      GL11.glVertex3f(0, 0, -10f);
      GL11.glVertex3f(0, 0, 10f);
      GL11.glEnd();
      model.draw();
   }

Shader init:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
package util.shader;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import org.lwjgl.opengl.ARBFragmentShader;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.ARBVertexShader;
import org.lwjgl.opengl.GL20;
import org.lwjgl.util.vector.Vector3f;

public class Shader {
   public int program, vert, frag;

   public Shader(String path) throws Exception {
      // Load Vertex Shader
      vert = 0;
      vert = ARBShaderObjects
            .glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
      ARBShaderObjects.glShaderSourceARB(vert, readFileAsString(path
            + ".vert"));
      ARBShaderObjects.glCompileShaderARB(vert);
      if (GL20.glGetShaderi(vert, GL20.GL_COMPILE_STATUS) == 0) {
         System.err.println(GL20.glGetShaderInfoLog(vert, 1024));
         System.exit(1);
      }
      // Load Fragment Shader
      frag = 0;
      frag = ARBShaderObjects
            .glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
      ARBShaderObjects.glShaderSourceARB(frag, readFileAsString(path
            + ".frag"));
      ARBShaderObjects.glCompileShaderARB(frag);
      if (GL20.glGetShaderi(frag, GL20.GL_COMPILE_STATUS) == 0) {
         System.err.println(GL20.glGetShaderInfoLog(frag, 1024));
         System.exit(1);
      }
      // Load Shader Program
      program = 0;
      program = ARBShaderObjects.glCreateProgramObjectARB();
      ARBShaderObjects.glAttachObjectARB(program, vert);
      ARBShaderObjects.glAttachObjectARB(program, frag);
      ARBShaderObjects.glLinkProgramARB(program);
      if (GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == 0) {
         System.err.println(GL20.glGetProgramInfoLog(program, 1024));
         System.exit(1);
      }
      ARBShaderObjects.glValidateProgramARB(program);
      if (GL20.glGetProgrami(program, GL20.GL_VALIDATE_STATUS) == 0) {
         System.err.println(GL20.glGetProgramInfoLog(program, 1024));
         System.exit(1);
      }
   }

   public void activate() {
      ARBShaderObjects.glUseProgramObjectARB(program);
      light = 0;
   }

   public void deactivate() {
      ARBShaderObjects.glUseProgramObjectARB(0);
   }

   public void destroy() {
      ARBShaderObjects.glDeleteObjectARB(frag);
      ARBShaderObjects.glDeleteObjectARB(vert);
      ARBShaderObjects.glDeleteObjectARB(program);
   }

   private String readFileAsString(String filename) throws Exception {
      StringBuilder source = new StringBuilder();

      FileInputStream in = new FileInputStream(filename);

      Exception exception = null;

      BufferedReader reader;
      try {
         reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

         Exception innerExc = null;
         try {
            String line;
            while ((line = reader.readLine()) != null)
               source.append(line).append('\n');
         } catch (Exception exc) {
            exception = exc;
         } finally {
            try {
               reader.close();
            } catch (Exception exc) {
               if (innerExc == null)
                  innerExc = exc;
               else
                  exc.printStackTrace();
            }
         }

         if (innerExc != null)
            throw innerExc;
      } catch (Exception exc) {
         exception = exc;
      } finally {
         try {
            in.close();
         } catch (Exception exc) {
            if (exception == null)
               exception = exc;
            else
               exc.printStackTrace();
         }

         if (exception != null)
            throw exception;
      }

      return source.toString();
   }

   // Tests
   public void setUniform(String uniform, float x, float y, float z) {
      int loc = GL20.glGetUniformLocation(program, uniform);
      GL20.glUniform3f(loc, x, y, z);
   }

   public void setUniform(String uniform, int x) {
      int loc = GL20.glGetUniformLocation(program, uniform);
      GL20.glUniform1i(loc, x);
   }

   public void setUniform(String uniform, float x) {
      int loc = GL20.glGetUniformLocation(program, uniform);
      GL20.glUniform1f(loc, x);
   }

   // Light? :/
   int light = 0;

   public void addLight(Vector3f pos, Vector3f col, float alpha, float intense) {
      if (light != 100) {
         setUniform("lpos[" + light + "]", pos.x, pos.y, pos.z);
         setUniform("color[" + light + "]", col.x, col.y, col.z);
         setUniform("intense[" + light + "]", intense);
         setUniform("alpha[" + light + "]", alpha);
         light++;
         setUniform("amount", light);
      }
   }
}
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2014-06-20 07:50:23 »

This won't solve your problem, but there is room for improvement:

1  
2  
-   gl_FrontColor = gl_Color * mul;
+   col = gl_Color * mul;
Use a
varying vec3 col
to pass your calculated color to the fragment shader


1  
2  
-   vec4 finalcolor = texture2D(tex,gl_TexCoord[0].st)*gl_Color;
+   vec4 finalcolor = texture2D(tex,gl_TexCoord[0].st)*col;
use the
varying vec3 col
here.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #13 - Posted 2014-06-20 11:21:45 »

Okay, did that and also improved fragment shader:

1  
2  
3  
      // distance
      vec3 ppos = vec3(pos.x,pos.y,pos.z);
      float distance = length(lpos[i]-ppos);


to:

1  
2  
      // distance
      float distance = length(lpos[i]-pos.xyz);


still i don't understand why
1  
lpos[i]
allways is 0,0,0
// had to put it in code tabs cause it writes italic there haha :p
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #14 - Posted 2014-06-20 12:36:13 »

1  
2  
3  
      finalcolor.r=lpos[i].x;
      finalcolor.g=lpos[i].y;
      finalcolor.b=lpos[i].z;


Since this colors the whole model black i guess it doesn't change the lpos at all and it stays 0,0,0 (it should be 0,1000000,0)
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #15 - Posted 2014-06-20 12:55:52 »

I'm so done, what did i do wrong? :/

1  
2  
3  
         setUniform("color[" + light + "]", col.x, col.y, col.z); // works
                                                      // totally
                                                      // fine

they both get called just after each other, and i checked, the Vector3f pos has values in it right before and after calling this line:
1  
2  
3  
         setUniform("lpos[" + light + "]", pos.x, pos.y, pos.z); // doesn't
                                                   // work at
                                                   // all


Current Vertex Shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
varying vec4 pos;
varying vec4 col;
void main()
{
   gl_TexCoord[0] = gl_MultiTexCoord0;
   pos = ftransform();
   gl_Position = ftransform();
   vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
   vec4 mul = vec4(normal.z,normal.z,normal.z,1.0);
   col = gl_Color * mul;
}


Current Fragment Shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
uniform sampler2D tex;
// Lights
uniform vec3 lpos[100];
uniform vec3 color[100];
uniform float intense[100];
uniform int amount;
uniform float alpha[100];

varying vec4 pos;
varying vec4 col;

void main()
{  
   int i;
   vec4 finalcolor = texture2D(tex,gl_TexCoord[0].st)*col;
   for(i = 0; i < amount; i++){
      // distance
      float distance = length(lpos[i]-pos.xyz);
     
      if(distance < intense[i]){
         float falpha = 1.0-(distance/intense[i]);
         finalcolor.r = finalcolor.r + color[i].r * falpha * alpha[i];
         finalcolor.g = finalcolor.g + color[i].g * falpha * alpha[i];
         finalcolor.b = finalcolor.b + color[i].b * falpha * alpha[i];
      }
   }
   gl_FragColor = finalcolor;
}
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2014-06-20 19:16:01 »

You set lpos[ i ].y to a massive value.
Therefore length(pos - lpos) is huge.
Therefore it is greater than 'intense' (10).

The if condition yields false, causing the contents of the if block never to be executed.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #17 - Posted 2014-06-20 20:20:26 »

well. that's what's supposed to happen (for testing if i can set the position) but the light source is allways on the same place, if i set it to 0,0,0 or to 0,1000000,0 :/ the light still appears at the point 0,0,0 even if it shouldn't affect anything at all cause the y value is too big
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #18 - Posted 2014-06-20 20:24:37 »

Here that's what shows up (white light) it's the same if i place it in 0,0,0 or 0,1000000,0:

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #19 - Posted 2014-06-20 20:33:01 »

Change your frag.shader to:
gl_FragColor = vec4(lpos[0].xyz, 1.0);

and slowly increase lpos.y

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #20 - Posted 2014-06-20 20:47:26 »

that coloured it green (So it sends the right data in)
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #21 - Posted 2014-06-20 20:49:40 »

1  
      float distance = length(lpos[i]-pos.xyz);


If i change that line to:
1  
      float distance = length(lpos[0]-pos.xyz);


it works fine for that one light but i can't have multiple lights like this :/ and why is there even a difference, the for loop starts with 0 and stops after that  Huh
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #22 - Posted 2014-06-20 20:50:30 »

Well, use the same approach to other variables, to (slowly) determine the values of them all, narrowing down the issue.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #23 - Posted 2014-06-20 20:55:27 »

Okay, lpos[0] is 0,1,0 in this case:
1  
gl_FragColor = vec4(lpos[0],1.0);

--> whole model is green (that's what i expected)
But:
1  
2  
int c = 0;
gl_FragColor = vec4(lpos[c],1.0);

--> whole model is black (so values are 0,0,0 Huh when they should be 0,1,0)

But it's both the same thing actually no?
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #24 - Posted 2014-06-22 22:50:19 »

Just testing out more stuff:
1  
2  
3  
if(dis < light[i].range){
   col = vec4(1.0,0.0,0.0,1.0);
}

crashing the code, while
1  
2  
3  
if(dis < light[i].range){
}
col = vec4(1.0,0.0,0.0,1.0);


It doesn't even give me an exception, just stops whole programm and throws an err.log file (Can upload if anyone is interested)
I don't get it how GLSL works ... -_-
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!