Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (162)
games submitted by our members
Games in WIP (632)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4 5 ... 10
 21 
 on: 2015-05-24 14:57:51 
Started by tommohawkaction - Last post by tommohawkaction
Is there a way i get can hold of the default shader instead of having to create a new one for the meshes?

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  
      String vertexShader = "attribute vec4 a_position;    \n" + 
                "attribute vec4 a_color;\n" +
                "attribute vec2 a_texCoord0;\n" +
                "uniform mat4 u_worldView;\n" +
                "varying vec4 v_color;" +
                "varying vec2 v_texCoords;" +
                "void main()                  \n" +
                "{                            \n" +
                "   v_color = vec4(1,0,0,1); \n" +
                "   v_texCoords = a_texCoord0; \n" +
                "   gl_Position =  u_worldView * a_position;  \n"      +
                "}                            \n" ;
String fragmentShader = "#ifdef GL_ES\n" +
                  "precision mediump float;\n" +
                  "#endif\n" +
                  "varying vec4 v_color;\n" +
                  "varying vec2 v_texCoords;\n" +
                  "uniform sampler2D u_texture;\n" +
                  "void main()                                  \n" +
                  "{                                            \n" +
                  "  gl_FragColor = v_color;\n" +
                  "}";
     
      shader = new ShaderProgram(vertexShader, fragmentShader);
     
      modelBatch

 22 
 on: 2015-05-24 14:48:03 
Started by tommohawkaction - Last post by tommohawkaction
No its quite simple as he doesnt rotate the camera so no billboarding is needed.
I am just stuck trying to get a plane to render with colour/texture ahh

 23 
 on: 2015-05-24 14:13:55 
Started by tommohawkaction - Last post by CaptainJester
I don't do much 3D myself, I just know the concepts.

That image looks like he is using billboarding. Search on that term to see if it gives you what you want.

 24 
 on: 2015-05-24 13:53:40 
Started by SauronWatchesYou - Last post by Husk
If you're doing modern OpenGL, which you probably should be, shaders it is. You don't have to do it by blending, you could calculate the final pixel colour in the shader. I'm not sure which way would perform better, you'll have to benchmark that. Depending on how your game works, you might even be able to do the calculation in the vertex shader and let the GPU interpolate, though I'm not sure since I've never done it, but I like to think about it. Tongue

It'd simply be a matter of uploading a texture like this to the GPU:



Then either, use the shader to blend the tile and lightmap together, and output the final colour, or render the lightmap (using a simple passthrough shader) after you've rendered the tiles as their default colour and enable blending (you'll have to find the right blending function). Each tile only needs to correspond to one pixel in the lightmap.

All approaches should be sufficiently fast even on low spec computers, it's up to you on how you want to balance performance/development complexity. My guess is passing alpha values once to the GPU and using those will be fastest, but there is a reason we do benchmarks and testing. Tongue

 25 
 on: 2015-05-24 13:28:24 
Started by tommohawkaction - Last post by tommohawkaction
sorry again my mistake I meant face.
If you look at that photo above i am trying to do that same thing how would i do such a thing?
Example code would be helpful
If you willing to help via skype then my skype it: tommohawkaction


 26 
 on: 2015-05-24 13:28:19 
Started by kevglass - Last post by Eobard Aviles
Don't have a day job, currently, but I start work on Tuesday.  Shocked

My dream job is making my own online gaming company. Smiley

 27 
 on: 2015-05-24 13:26:21 
Started by SauronWatchesYou - Last post by SauronWatchesYou
That's another interesting idea, Husk.The lightmap would require a shader, correct? And as you said I'd have to find some way of blending that would actually create the block effect (Google should help with that) It's good to know that there are different ways of getting the same effect Pointing

@icass doesn't LibGDX only support Box2D lighting out of the box?

 28 
 on: 2015-05-24 13:22:00 
Started by tommohawkaction - Last post by CaptainJester
One problem is that you think you are rendering a cube when you are only rendering a face. A cube has 6 faces with a total of 8 vertices.

I ran your code an there were no glitches for me. Define "glitchy".

 29 
 on: 2015-05-24 12:59:30 
Started by SauronWatchesYou - Last post by Husk
As far as the efficiency part of your question goes, that shouldn't really affect performance in a meaningful way as long as you're isolating the problem to what's in view and preferably only in the area light affects, rather than everything in your game. There's a couple extra things you could do though.

Firstly, you don't need to use the distance formula, you only need to know what the lighting value of blocks are at X distance from you. So either use the formula once when loading the game, and create a lookup table, or just manually write a lookup table. When you move, simply set the tiles around you to their approriate lighting value, and clear the lighting of anything outside of the new area.

You can avoid blending by just not requiring it, and you're pixel/fragment shader would just be a simple pass through of a lighting scalar. In a game like the one you've shown, you really only need to redraw what changes, when something changes, because it's easy to know, unlike more complicated games. I'm not sure if dirty rectangles are still a thing, but that's probably going too far. Of course, you should benchmark any approach, and get the application working first.

Or you could create a screen size light map, which you create once and just render it over the top of your game. With the right blending functions you should be able to achieve the same effect.

 30 
 on: 2015-05-24 12:49:31 
Started by tommohawkaction - Last post by tommohawkaction
^^ Yeah sorry didnt make it clear

I was only messing around so instead of creating two objects i just override the other one

I did get a cube to render though but very glitchy
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  
public static final int FRAME_WIDTH = 1280;
   public static final int FRAME_HEGIHT = 720;
   public static final int FPS_CAP = 60;
   public static final boolean VSYNCENABLED = false;
   
   // Camera Settings
   public static final int FOV = 67;
   public static final float NEAR = 0.1f;
   public static final float FAR = 300f;
   
   public static PerspectiveCamera camera;
   
    public Model model;
    public ModelBatch modelBatch;
    public ModelInstance instance;
    private Mesh mesh;
    private ShaderProgram shader;
   
   @Override
   public void create () {
      String vertexShader = "attribute vec4 a_position;    \n" +
                "attribute vec4 a_color;\n" +
                "attribute vec2 a_texCoord0;\n" +
                "uniform mat4 u_worldView;\n" +
                "varying vec4 v_color;" +
                "varying vec2 v_texCoords;" +
                "void main()                  \n" +
                "{                            \n" +
                "   v_color = vec4(1,0,0,1); \n" +
                "   v_texCoords = a_texCoord0; \n" +
                "   gl_Position =  u_worldView * a_position;  \n"      +
                "}                            \n" ;
String fragmentShader = "#ifdef GL_ES\n" +
                  "precision mediump float;\n" +
                  "#endif\n" +
                  "varying vec4 v_color;\n" +
                  "varying vec2 v_texCoords;\n" +
                  "uniform sampler2D u_texture;\n" +
                  "void main()                                  \n" +
                  "{                                            \n" +
                  "  gl_FragColor = v_color;\n" +
                  "}";
     
      shader = new ShaderProgram(vertexShader, fragmentShader);
     
      modelBatch = new ModelBatch();
      init();
     
        ModelBuilder modelBuilder = new ModelBuilder();
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        blockInit();
       
       
   }
   private void init(){
      camera = new PerspectiveCamera(FOV,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
      camera.far = FAR;
      camera.near = NEAR;
      camera.position.set(0, 0, 50);
      camera.update();
     
   }
   private void blockInit(){
      float[] vertices = {
            -1f, -1f, 0,      // bottom left
                1f, -1f, 0,       // bottom right
                1f, 1f, 0,        // top right
                -1f, 1f, 0,
      };
      short[] indices = {
            0,1,2,
            2,3,0
      };
      VertexAttributes attribs = new VertexAttributes(
            new VertexAttribute(Usage.Position,3,ShaderProgram.POSITION_ATTRIBUTE)
      );
      mesh = new Mesh(true, vertices.length, indices.length, attribs);
      mesh.setVertices(vertices);
      mesh.setIndices(indices);
      instance = new ModelInstance(model);
   
   }
   @Override
   public void render() {
        Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        shader.begin();
        shader.enableVertexAttribute(0);
        shader.enableVertexAttribute(1);
        shader.enableVertexAttribute(2);
        shader.setUniformMatrix("u_worldView", camera.combined);
        shader.disableVertexAttribute(2);
        shader.disableVertexAttribute(1);
        shader.disableVertexAttribute(0);
        mesh.render(shader, GL20.GL_TRIANGLES);
        shader.end();
   }
   @Override
   public void dispose() {
      modelBatch.dispose();
      model.dispose();
   }

Pages: 1 2 [3] 4 5 ... 10
 
MrMapcom (12 views)
2015-05-23 20:26:16

MrMapcom (19 views)
2015-05-23 20:23:34

Waterwolf (29 views)
2015-05-20 15:01:45

chrislo27 (35 views)
2015-05-20 03:42:21

BurntPizza (70 views)
2015-05-10 15:53:18

FrozenShade (55 views)
2015-05-07 09:11:21

TheLopais (218 views)
2015-05-06 13:36:48

TheLopais (202 views)
2015-05-06 13:35:14

TheLopais (206 views)
2015-05-06 13:33:39

TheLopais (226 views)
2015-05-06 13:32:48
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!