Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Shader rendering conflict with ghost object, fog and shadows

Author
Message
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 17th Oct 2010 13:29
Dear All,

I've run into a conflict between ghost object on, shadowing and fog in DBPro and shaders, that probably shows my ignorance of the graphics pipeline.

I have an advanced terrain to which I am applying GG's terrain shader, and a water plain, on which a water shader is running. I've created a ghosted plain above the terrain and water plain, the terrain's texture appears through the ghosted plain, the water shader does not (as shown in the image below). I've also discovered that fog does not affect the terrain object, even when I specifically set object fog to on for this object. DBPro's stencil shadows also do not get applied to the terrain.

I am guessing the problem is something to do with the rendering order of shaders and inherent DBPro functions. My terrain shader being applied before the ghost object, the water shader, which is multi-pass, being applied after the ghost object? GG's terrain shader is applied only when I create the terrain and is not updated, the water object's shader is updated at every time step. Anyway so I am not surprised I can't see the water shader through the ghosted plain, but surprised that the terrain isn't affected by fog and shadows. I would post the code....but it is 20,000 lines so far.

I have a sneaking suspicion the answer will be to control ghosting, fog and shadows with my shaders instead of using DBPro functions. With this in mind, if I was to write a shader to apply to an object to ghost it, I'd want to take the projected texture behind the object and combine it with the texture specified in a sampler weighted by the R bit of the sampler texture. Could a shader Guru suggest how to access the texture behind an object? It's straightforward using tex2D for a sampler but I am uncertain how to pass the background texture and whether I can use tex2D? I've put an illustration below that tries to explain what I mean by this poorly phrased question.

Many thanks,
Mr Grumpy

GrumpyOne - the natural state of the programmer
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Oct 2010 14:21 Edited at: 17th Oct 2010 14:21
Quote: "I have a sneaking suspicion the answer will be to control ghosting, fog and shadows with my shaders instead of using DBPro functions"

When you activate a shader, you are basically replacing the fixed rendering pipeline (note, not DBPro's rendering pipeline - see below). That means that every effect that you would normally activate via DBPro (fog, lighting, transparency, ghosting, wireframe etc) needs to be reproduced within the shader.

There are some small exceptions to this - ghosted and transparent objects should not only be set within the shader, but should also be flagged to DBPro too. The reason for this is that these settings not only affect the render itself (when a shader is not involved), but they also affect the order of rendering, so that ghosted and transparent objects get rendered after the other object.

Shadows are outside my knowledge, and there may be other settings that need to be set both in your shader and within DBPro - you'll need to experiment.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 17th Oct 2010 14:49
Thanks mate. I figured it was something along those lines. Strangely wireframe still works with the terrain as does ghosting. It'll be easy to do fog effects in a shader since I simply blend my fog colour depending on distance from camera. I really have no idea how to write a shader to ghost an object, since it needs to blend the object's texture with the camera's view of the background. Perhaps if GG or DarkShader read this they can point me in the right direction.

GrumpyOne - the natural state of the programmer
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Oct 2010 18:58 Edited at: 17th Oct 2010 18:59
Quote: "Perhaps if GG or DarkShader read this they can point me in the right direction."


I might if I understood precisely what you're trying to do. As I understand it you have a terrain object with one of my shaders applied to it and also a plain with a water shader applied. As you say, it is straightforward to amend each shader to include fog. What I don't understand is the purpose of the ghosted plain or how precisely you are trying to apply it. Also, I don't immediately see why ghosting works on one and not the other. Does the water shader use separate camera renders? I wonder if the ghosting is being applied at the wrong stage.

You say your project is 20000 lines long. Could you construct a much simpler demo to highlight the problem?
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 20th Oct 2010 03:12
Pardon the delay...it took a while to cut n paste the code to get a working simpler demo.

What I am trying to achieve it ghosted plains over my terrain and water layer to generate majestic clouds, volcano smoke etc. In this demo I've opted for majestic cloud. You'll see that the texture on the terrain appears through the ghosted cloud, the texture on the water doesn't. I am perplexed. Perhaps it is something to do with the fact both the water plain and the cloud are ghosted.

You'll recognise the terrain shader, it's yours, plus the addition of some extra code to add an additional texture and user defined blending thresholds. The water shader is a simplified version of one of evolveds and doesn't use multiple cameras.

I just realised that my question was, in anycase, completely stupid. The plains (planes?) are transparent since they are set as ghosted in DBPro, not by specific blending of the background texture in the shader....

Demo attached.

Many thanks,
Mr Grumpy

GrumpyOne - the natural state of the programmer
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 20th Oct 2010 20:39
Ah ha!

You jogged my mind. The shaders are treated in the wrong order....or rather in an order I didn't want. If I disable the ghosted object's zwrite then the water shader shows through. It seems the rendering engine evaluates zdepth by distance of an object's origin from the camera. I expected something a little more sophisticated.

As long as I don't have any other objects over the top of my majestic clouds, or scary volcanic eruptions, I can safely disable zdepth.

Best,
Mr Grumpy

GrumpyOne - the natural state of the programmer
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Oct 2010 20:56
Quote: "You jogged my mind."


I did? I haven't even downloaded your demo yet.

Glad you got it sorted out though.

Login to post a reply

Server time is: 2026-07-22 03:51:36
Your offset time is: 2026-07-22 03:51:36