Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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  
  [LWJGL] Use 2 images to create shadows  (Read 467 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

Senior Member


Medals: 4
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Posted 2013-10-10 01:07:20 »

Hi!
I am trying to create a simple "baked" model engine in lwjgl. I tried this idea in Game Maker, and it worked perfectly, but I cannot seem to replicate it in Java.

The idea:
-Have your normal scene draw as it would
-Draw a second scene to an image (this scene would draw your baked model, but at the same camera position)
-Overlay the second scenes image ontop of the normal scene (with a blendmode that multiplies the colors)

What I already have done in java:



What I want to have as a desired effect:


The first two pictures represent scene 1 and scene 2.

I need to figure out how to draw scene 2 ontop of scene 1, and blend its colors in.
To do this, I would need to figure out how to save scene 2 to a surface (image) of some kind. But then I still wouldn't know how to overlay it, and use blend modes.

Any ideas?

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Coding with bad posture since 2011... Nonstop.


« Reply #1 - Posted 2013-10-10 01:09:40 »

You could render the first part, disable depth testing, and then draw the lighting. You couldn't stop there unless you wanted to see light through walls though, that was just where I would start if I were you.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #2 - Posted 2013-10-10 01:19:38 »

It's probably more efficient to do this through shaders, as using blend modes requires 2 drawings.

Make a shader that multiplies the two texture colours together and then you just require one render call. Just make sure you bind the two textures properly.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

Senior Member


Medals: 4
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #3 - Posted 2013-10-10 02:34:36 »

The only problem, is that the 2 scenes are actually 2 different models as well as 2 different textures.

I could attempt to scrap the whole idea, and do lights through shaders... but I have no idea where to start with them ;x

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-10-10 02:38:24 »

why do you have two different scenes? You really should only have the base scene with no lighting, and then add in overlays with the green effects. If its baked in completely, like it'll never change at all, just create overlays for each light, don't over complicate it by rendering two scenes.

But you really should just use shaders
https://github.com/mattdesl/lwjgl-basics/wiki/Shaders

Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #5 - Posted 2013-10-10 03:25:14 »

The only problem, is that the 2 scenes are actually 2 different models as well as 2 different textures.

I could attempt to scrap the whole idea, and do lights through shaders... but I have no idea where to start with them ;x

It looks like the models' shapes are identical, so why couldn't you put both textures onto one shape?

Offline orange451

Senior Member


Medals: 4
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #6 - Posted 2013-10-10 03:30:18 »

The only problem, is that the 2 scenes are actually 2 different models as well as 2 different textures.

I could attempt to scrap the whole idea, and do lights through shaders... but I have no idea where to start with them ;x

It looks like the models' shapes are identical, so why couldn't you put both textures onto one shape?
because then I would severely lose texture quality. Both UV mapped differently (1 uv mapped to support the maps normal texturing, and the other uv mapped to have the baked texture).

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #7 - Posted 2013-10-10 03:37:00 »

Use the following blend mode:

1  
GL11.glBlend(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);


I hope it works. Haven't checked it myself.

Offline davedes
« Reply #8 - Posted 2013-10-10 03:38:09 »

You need a VBO that contains vertex position and two sets of texture coordinates. Texcoord A would be the UV map of your diffuse. Texcoord B would be the UV map of your baked global illumination / occlusion / etc. Then in a shader you would be blend them together as you see fit.

Using two texture units is explained here:
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson4

If you are not familiar with VBOs and vertex data you have quite a bit of reading ahead of you. The easiest would be to use LibGDX which handles VBO, shader compilation, vector math, etc.

https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes


In either case this doesn't sound like an optimization. It sounds like your UV maps for the baked lighting will be pretty huge. You may as well just bake the lighting in your 3D program, and export a single set of textures with all the lighting baked in.

Or, another sane approach is to use something like SSAO or irradiance volumes:
http://john-chapman-graphics.blogspot.ca/2013/01/ssao-tutorial.html
http://codeflow.org/entries/2012/aug/25/webgl-deferred-irradiance-volumes/

Offline cylab

JGO Knight


Medals: 34



« Reply #9 - Posted 2013-10-10 09:27:00 »

to answer the OPs initial question, google: FBO render to texture opengl

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (11 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (23 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!