Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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  
  Making a vector2f array based off a texture  (Read 819 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-04-10 00:24:51 »

So this has been bugging me for a long time, I have a lighting "handler" that takes in a collection of vector2f's and draws quads going down from two points on them, looking like ray-casting. I wanted a way to make textures bind into the vector2f's to make the lighting handler know what the texture is.

How it works is everything lit extends a mesh, the mesh has a array of vector2fs called "getVertices".

Heres how I light a quad:
1  
2  
3  
4  
5  
6  
7  
8  
   public Vector2f[] getVertices() {
      return new Vector2f[] {
            new Vector2f(position.x, position.y),
            new Vector2f(position.x, position.y + size.y),
            new Vector2f(position.x + size.x, position.y + size.y),
            new Vector2f(position.x + size.x, position.y)
      };
   }
Offline Spacebeans
« Reply #1 - Posted 2014-04-10 20:03:46 »

I should have mentioned I wanted the mesh to line-up with the texture. So the lighting engine is aware that there is a alpha pixel in the texture, and makes the vector array understand that.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #2 - Posted 2014-04-11 02:15:49 »

You're not making any sense at all. I don't think anyone has understood what you're after. I can't even find a real question. What is the problem?

I should have mentioned I wanted the mesh to line-up with the texture.
Huh? Line up?

So the lighting engine is aware that there is a alpha pixel in the texture, and makes the vector array understand that.
What? What does the vector array have to do with what texture data you have in your texture? Why does your vector array need to "understand" if there's transparency in your texture?

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #3 - Posted 2014-04-11 19:57:10 »

I mean that the lighting engine takes in a vertex array, then draws a quad from the two points. Then I draw a texture over the lighting, looking like ray casting. But the only thing that's ray-casted is the data in the vector array. So when I have a texture with alpha and stuff, it doesn't ray cast it. I need a way to make the vertex2f array line up with a texture.
Offline saucymeatman
« Reply #4 - Posted 2014-04-11 20:42:18 »

I mean that the lighting engine takes in a vertex array, then draws a quad from the two points.
So the vertex array has two points in it and it draws a quad "from" the two points.
This is confusing, how does it draw a quad from two points? Are the two points the corners of the quad?

Then I draw a texture over the lighting, looking like ray casting.
Wait, so you have a texture with highlights and shadows and other lighting effects and then you draw a texture over it? What does ray casting look like?

But the only thing that's ray-casted is the data in the vector array.
Huh? The data in the vector array that is used as a parameter for the "lighting engine"? So lost at this point.

So when I have a texture with alpha and stuff, it doesn't ray cast it. I need a way to make the vertex2f array line up with a texture.
I dont understand this part at all...

Whats the question?
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #5 - Posted 2014-04-12 00:04:29 »

A picture might help?

Myomyomyo.
Offline Spacebeans
« Reply #6 - Posted 2014-04-12 16:16:49 »

A picture might help?

Sorry for the more detail in the second one.
And I forgot to fill the shadow inside the block on the first one.

Here is the scene:

How I want it:


How it is:


Note: The gray in the texture is the alpha on the texture.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #7 - Posted 2014-04-12 16:59:07 »

Judging from your picture, this might be relevant: http://archive.gamedev.net/archive/reference/programming/features/2dsoftshadow/page3.html

Myomyomyo.
Offline Spacebeans
« Reply #8 - Posted 2014-04-12 17:02:32 »

Thanks, but that's already implemented. All I need is something like a for method to find all the pixels in the texture, change the vector2f array to only go around the pixels that aren't transparent.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #9 - Posted 2014-04-12 18:25:32 »

So you want only opaque pixels in the texture to cast shadows?

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #10 - Posted 2014-04-12 18:37:13 »

Exactly, but the only thing that the lighting "sees" is the vector array.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #11 - Posted 2014-04-12 22:40:20 »

Well, a tip for next time: First tell us what you're trying to achieve and what the problem is, THEN tell us what you're trying to solve it with. "I'm trying to make a texture with transparent texels cast shadows" tells us more than all your previous posts combined.

The problem is quite complex, since as you're saying the shadows rely on the transparency of the texture you're using. Even worse, how much light is blocked at any point X in the shadow depends not on one texel in the shadow casting texture but on all texels in a line from the light to the point X. I see a number of solutions:

1. Fake it.

2. Approximate the opaque parts of the texture with a mesh of vertices. For complex shapes this is difficult to implement, slow as hell due to the massively inflated vertex count and shadow overdraw and has low quality. Not recommended unless you have shapes that can be very easily approximated with a mesh.

3. Raycast through the texture on rendering. This technique (and variations of it) are the only techniques that can handle arbitrary textures without any preprocessing or vertex shapes, but it can also be very GPU intensive due to the raycasting. You can do this in two different ways. The first one is to simply read a number of texels from the texture along a line going from the light to the point you're testing:



This is pretty hard to implement in a good way and can be extremely slow since the raycasting is wastefully done for each shadowed pixel. A better approach would be to construct a 1D shadow map by raycasting through the texture and simply sample the shadow map for each pixel that is potentially shadowed and multiplying its color with the value in the shadow map. This should be more than fast enough and relatively simple to implement. There are multiple techniques that you can find via Google that use this approach.

Myomyomyo.
Online matheus23

JGO Kernel


Medals: 112
Projects: 3


You think about my Avatar right now!


« Reply #12 - Posted 2014-04-13 00:03:52 »

In most cases theagentd's second option is enough. Try that one out. There is also another pixel-perfect lighting techneque that davedes implemented, see this post: http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/msg/230988/view.html#msg230988

This can be done with shaders. But I've already tried searching for the source code that davedes wrote once, but I couldn't find it, maybe you do Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #13 - Posted 2014-04-13 00:59:09 »

In most cases theagentd's second option is enough. Try that one out. There is also another pixel-perfect lighting techneque that davedes implemented, see this post: http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/msg/230988/view.html#msg230988
Step 4 in that technique is essentially a raycast.  persecutioncomplex

Myomyomyo.
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.

xFryIx (52 views)
2014-11-13 12:34:49

digdugdiggy (34 views)
2014-11-12 21:11:50

digdugdiggy (28 views)
2014-11-12 21:10:15

digdugdiggy (23 views)
2014-11-12 21:09:33

kovacsa (46 views)
2014-11-07 19:57:14

TehJavaDev (50 views)
2014-11-03 22:04:50

BurntPizza (49 views)
2014-11-03 18:54:52

moogie (65 views)
2014-11-03 06:22:04

CopyableCougar4 (63 views)
2014-11-01 23:36:41

DarkCart (148 views)
2014-11-01 14:51:03
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!