JMonkey Filter Shader - get World Position of Fragment

242 views Asked by At

I'm implementing Warcraft/Age of Empires-style "Fog of War" by writing a Filter class and the appropriate JME material definition with vertex and fragment shaders.

I was able to figure that out very easily, I can now tint the entire screen for example.

But I'm now stuck again in computing where a given fragment is located in the world.

So, how can this be done?

Why I need this, is basically I have a texture (32x32) with which to darken the world at particular places based on the alpha channel of the texture.

0,0 in the texture would correspond to 0,0,0 in the world. Given a "world map or terrain" of size 100,100.

1

There are 1 answers

0
Petter Thowsen On

This doesn't answer the question on how to get the world position of a fragment in a shader used in Filters, but anyway:

It was explained to me that it would be wiser to implement fog of war for all the shaders used by objects in the game, becaues it's easier and a lot more easily extendable (one can toggle the FOW effect on individual objects or materials).

The answer is to add a new varying vec2 called "worldPos" for example and set it to worldPos = g_WorldMatrix * vec4(inPosition, 1.0); in the vertex shader.

That's all. This does not work for Filters though.