• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Meltac

Execute shader depending on what's visible on screen

34 posts in this topic

High all,

 

In a 3D first-person / ego perspective game I've got a simple script that checks whether the player is currently located inside of one of a list of specified coordinate boxes (say, in a room of a list of defined rooms), and execute some shader / post process accordingly.

 

Now what I would need instead is to check whether what the players currently sees is the inside of one of those coordinate boxes, i.e. he might still be outside but on screen sees only the inside of the box, or vice-versa, looks from within the box to the outside.

 

I could do such a check either by scripting the engine, or in the responsible post process shader.

 

How would I achieve this? Any suggestions are welcome.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

Ok, I've checked the suggestions. It seems that I could do some sort of frustum culling or per-pixel-box-check, but both approaches require a rather ugly set of calculations which I'd like to avoid if there is a simpler way.

 

What I actually have at the point where I would like to do the check (high-level script on CPU, not GPU side):

  • Camera world position
  • Camera direction
  • Camera FOV
  • 2 Box corner world coordinates (left-bottom-front, right-top-back)

What I do not have right away:

  • View frustrum definition (near/far plane or say 6 planes defining frustum)
  • Any specific pixel information (uv, view space position, depth or the like)

What I would like to calculate:

  • Percentage of screen "covered" by box.

 

Any clues on how to perform such calculation?

0

Share this post


Link to post
Share on other sites

Nobody?

 

I had thought of some check using the view angles between the camera direction and the view vector (direction) to the box's corners or its center point. That way I could for example determine whether a certain point (i.e. corner vertex) is located inside or outside of the screen boundaries, only be checking view angle and distance, thus avoiding the requirement of any world-to-screen-space or whatever matrix calculations.

 

What do you guys think of such an approach?

0

Share this post


Link to post
Share on other sites


Now what I would need instead is to check whether what the players currently sees is the inside of one of those coordinate boxes, i.e. he might still be outside but on screen sees only the inside of the box, or vice-versa, looks from within the box to the outside.

 


What I would like to calculate:
Percentage of screen "covered" by box.

 


That way I could for example determine whether a certain point (i.e. corner vertex) is located inside or outside of the screen boundaries, only be checking view angle and distance, thus avoiding the requirement of any world-to-screen-space or whatever matrix calculations.

 

What exactly are you trying to do again?

0

Share this post


Link to post
Share on other sites

What exactly are you trying to do again?

 

Not sure if you're kidding me, or what's so hard to understand after all my descriptions... but well, OK:

 

 

As written in my initial post, I want my host application to decide which (pixel) shader to execute, depending on if the camera's view shows mainly (i.e. high percentage of screen coverage) the inside of an area defined by an (imaginary) cube / box. It is not sufficient to know whether the camera / player is located inside of that cube, but I need to know if what is visible on screen is the inside of that cube.

 

 

Think of a cubic area of radioactivity that should cause the execution of some noise post-process effect when the player is inside of or near that area, but only if he's facing / seeing the area.

 

 

I do not want to use frustum culling to find the intersection between the view frustum and the box, which would be the "classic" approach for the given task. The main reason for this is that I do not have a near and far plane given in my host app, only the FOV plus by calculation the distance and angle to any point on the map.

 

I do not want to use Hodgman's idea either because my host app knows crap about any DirectX calls, which would be required for that approach.

 

So I need some other way to check what the camera currently sees, a way that requires nothing but the things that I actually have in my application, that is as said before:

  • Camera world position
  • Camera direction
  • Camera FOV
  • 2 Box corner world coordinates (left-bottom-front, right-top-back)

plus the mentioned functions to calculate the distance and view angle to a given world space point.

 

 

Was that clear now? Thanks for any suggestions.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

Don't occlusion queries give you exactly what you're looking for? You might need to retool a bit in order for them to fit your game code, but issuing a query will actually tell you how many pixels are affected.

2

Share this post


Link to post
Share on other sites

Don't occlusion queries give you exactly what you're looking for? You might need to retool a bit in order for them to fit your game code, but issuing a query will actually tell you how many pixels are affected.

 

I second this approach - it sounds like an exact match for what you are trying to do, and there is support for it built into the API itself.  You can even do asynchronous queries too.

0

Share this post


Link to post
Share on other sites

From his posting history, I think he's making a graphical mod for STALKER, which means doing raw D3D stuff is out of the picture.

 

What kind of rendering operations can you perform, Meltac?

2

Share this post


Link to post
Share on other sites

From his posting history, I think he's making a graphical mod for STALKER, which means doing raw D3D stuff is out of the picture.

 

That is true. I stopped mentioning the X-Ray engine that STALKER uses as most people here won't post *any* replies otherwise because they don't know that engine.

 

 

 


What kind of rendering operations can you perform, Meltac?

 

As the version of X-Ray I'm working with is not open, I have only access to those parts of the engine that are, this is, a LUA based scripting sub-engine and the pure HLSL vertex and pixel shaders. No applicable DirectX host application here. So, any D3D... function calls and the like are absolutely out of scope. Probably I shouldn't have tagged this thread D3D9, but I wanted to make clear that the engine is basically built onto DirectX 9.

 

This said, they are virtually no "rendering" operations in the usual way possible at all. All I've got are the mentioned camera properties and the world space coordinates of the box to check against. The operations I can do must be pure math / programming algorithms without any dependency to the DirectX API or any GPU specifics.

 

The LUA script part provides extensions for matrix / vector math operations, though. Theoretically this should be sufficient to do the job when applied to the given point and direction coordinates and the FOV angle taken into account.

 

EDIT:
And to highlight it once again, I do not have *any* view / world / transformation / projection / inverse or whatever matrix available, only the point coordinates of the camera and the box.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

That's what I've meant. As soon as Hodgman has mentioned STALKER and raw D3D stuff being out of the picture, no soul seems to dare to reply unsure.png

Edited by Meltac
0

Share this post


Link to post
Share on other sites

That's what I've meant. As soon as Hodgman has mentioned STALKER and raw D3D stuff being out of the picture, no soul seems to dare to reply unsure.png

 

I don't have any problem with the STALKER engine - I just don't know how to implement what you are asking without access to the API...  Is it really necessary to use the STALKER engine, or could you upgrade to something more open?

-1

Share this post


Link to post
Share on other sites


I don't have any problem with the STALKER engine - I just don't know how to implement what you are asking without access to the API... Is it really necessary to use the STALKER engine, or could you upgrade to something more open?

 

I am developing mods for STALKER which are supposed to run on a normal installation of that game, so "upgrading" to whatever different engine is not an option.

 

I am pretty, pretty sure that the task I'm asking for is very well doable without directX API, probably even in multiple different ways. Probably I should have asked in a more math related forum rather than here, as what I am intending to do really doesn't require any D3D stuff because it's mainly a question of vector math (even though it might be well doable using the directX API as well).

0

Share this post


Link to post
Share on other sites
As well as the math angle, it might help to describe the problem from a design perspective too. Is this something to do with radiation or anomaly zones? You want the players screen to undergo an effect when they stare into an anomaly, etc?

Also, as well as post-processing shaders, can you place custom meshes into the world and put custom materials/shaders on them? Maybe there's a solution down this path as well?
1

Share this post


Link to post
Share on other sites

it might help to describe the problem from a design perspective too. Is this something to do with radiation or anomaly zones? You want the players screen to undergo an effect when they stare into an anomaly, etc?

Also, as well as post-processing shaders, can you place custom meshes into the world and put custom materials/shaders on them? Maybe there's a solution down this path as well?

 

I have made several post-processing effects that affect only certain areas on the game level map while leaving others untouched. One prominent example would be reflective surfaces, say the tile floor in some lab casting diffuse light reflections. The reflection stuff is made by a post-process shader. Implementation details of that post-process are off-topic here.

 

As I have no means to control which areas on the map have a reflective floor by material or color or any other 2D or 3D property I need to manually define arrays of coordinate set for those areas where the post-process should be executed. Then, my CPU-side script should check whether what the player currently sees is "mostly" part of such a defined coordinate set (e.g. tile floor to be rendered reflective), and if so, set some engine variable that will be read by the GPU-side shader to enable the according post-process. It's no an exact match then because the percentage of screen coverage will decide whether to enable a specific shader effect, but it's a approximative approach.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

 


it might help to describe the problem from a design perspective too. Is this something to do with radiation or anomaly zones? You want the players screen to undergo an effect when they stare into an anomaly, etc?

Also, as well as post-processing shaders, can you place custom meshes into the world and put custom materials/shaders on them? Maybe there's a solution down this path as well?

 

I have made several post-processing effects that affect only certain areas on the game level map while leaving others untouched. One prominent example would be reflective surfaces, say the tile floor in some lab casting diffuse light reflections. The reflection stuff is made by a post-process shader. Implementation details of that post-process are off-topic here.

 

As I have no means to control which areas on the map have a reflective floor by material or color or any other 2D or 3D property I need to manually define arrays of coordinate set for those areas where the post-process should be executed. Then, my CPU-side script should check whether what the player currently sees is "mostly" part of such a defined coordinate set (e.g. tile floor to be rendered reflective), and if so, set some engine variable that will be read by the GPU-side shader to enable the according post-process. It's no an exact match then because the percentage of screen coverage will decide whether to enable a specific shader effect, but it's a approximative approach.

 

 

Do you have access for any gbuffer data?

1

Share this post


Link to post
Share on other sites

Do you have access for any gbuffer data?

 

No, as I said no directX API or other raw 3D / GPU instructions. Only (repeated for the 3rd time now):

 

  • Camera world position
  • Camera direction
  • Camera FOV
  • 2 Box corner world coordinates (left-bottom-front, right-top-back)

plus the mentioned functions to calculate the distance and view angle to a given world space point.

 

Is it really that hard?

Edited by Meltac
-1

Share this post


Link to post
Share on other sites

Do you have access for any gbuffer data?

 
No, as I said no directX API or other raw 3D / GPU instructions. Only (repeated for the 3rd time now):
 
  • Camera world position
  • Camera direction
  • Camera FOV
  • 2 Box corner world coordinates (left-bottom-front, right-top-back)
plus the mentioned functions to calculate the distance and view angle to a given world space point.
 
Is it really that hard?
He was asking about the inputs to your post-processing shaders - whether you get each pixel'a diffuse color, specular, normal, depth, etc... Or whether you just get the final 'lit' pixel colours.
0

Share this post


Link to post
Share on other sites

Oh, sorry. I might have misunderstood the question.

 

So yes in my post-process pixel shader I can access:

 

- color

- normal

- position (not sure what space, I'd guess view space)

 

but: how would that help in any way when I don't have any means to fill or alter that gbuffer data on the application host side where I need to do the distinction?

Edited by Meltac
0

Share this post


Link to post
Share on other sites

Its view space position (A16R16G16B16F), you do not modify gbuffer you can transform your point in view space and compare z to see if it is visible, but i am not sure exactly what you want to do so let someone else propose some solutions.

Edited by belfegor
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0