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] Heat Haze / Distortion (Easy to Use)

Author
Message
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 5th Nov 2010 16:14
Quote: "Your images look like the same issue that my solution avoids."

Hey that seems to be good news
Looking forward to see your magic again, when you have the time

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Nov 2010 14:29
Here's the revised version of your earlier demo.

The main change is in the way the haze mask is used. The original version used it to blend between the distorted image and the original undistorted image. This caused the edges to be misaligned since the two images would have the edges in different positions. The new version uses the same mask texture but uses it to control the final amount of distortion - so you get less distortion near the edges of the mask and the two images should match perfectly there. You can try adjusting the scroll speeds, bumpiness, etc, to change the effect.

Quote: "Hey that seems to be good news"


I've had another look at your images and I don't think that what I said was correct - I was looking at the wrong seam and I'm not sure what's causing it till I see some code.

The attached demo fixes the earlier issue I mentioned (it also contains several other minor changes to the shader code, mainly to bring it in line with my preferred style but there are a few simplifications as well).

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Nov 2010 11:24
Interesting.

I've just had a closer look at my demo and while it solves one problem it creates two new ones:

1. the anti-aliasing is lost in the heat haze object
2. the image coordinates seem to be slightly off so you can see the edge of the mask object in places. (This may be the usual pixel/texel offset problem but I'm not sure of the best way to fix it in this case. )

Back to the drawing board it seems.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Nov 2010 12:18
Problem solved.

I forgot that my method needs a full-resolution image of the screen for the heat haze object.

Just change this



to this



I can't see the edges of the mask object now.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 8th Nov 2010 20:22
Hey thank you very much for the revision, I'm really interested.
I'll try to take a look into it tomorrow and tell you about the results
Thanks again

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 9th Nov 2010 03:38 Edited at: 9th Nov 2010 03:38
@Green Gandalf:
Quote: "The new version uses the same mask texture but uses it to control the final amount of distortion - so you get less distortion near the edges of the mask and the two images should match perfectly there."


Ah, I see what you mean. I hadn't thought about doing it that way, good idea, thanks for sharing


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 9th Nov 2010 10:48 Edited at: 9th Nov 2010 11:11
Ok, I tried your new "HeatHaze3.fx" version Green Gandalf.

It looks rather improved over plane objects. The 'heat' seems more thick and intense, almost like underwater. Definitively an improvement here, good work

Now about spheres and other objects, ajem. I think we are just one step away. This is how it looks:



I just changed this:

for this:


Don't know how you made it, but the effect is now just at the borders! Lol.
To be more precise, the effect affects the left and right sides of the sphere, while there is an 'empty zone' that goes from pole to pole.

I've been doing some quick tests over the shader file, trying to make it appear the inverse, that is, to see the effect at the center
However I'm not totally sure about what I'm doing

For how it looks, it should be possible to reach a 0 distortion over the edges, and a maximum at the center (the opposite as it is now), shouldn't it?

[EDIT: One additional comment, I see the 'HeatHaze3.fx' has float numbers expressed as 0.5, 1.0... without the final 'f', like 0.5f, 1.0f
Now if I'm not wrong, the shader is using double floats if the subfix 'f' is not used. This may affect performance in some cases. I think the same can be applied about integer multipications for a float result.

Quote: "I forgot that my method needs a full-resolution image of the screen for the heat haze object."

I guess that affects performance as well, oh well no big deal
]

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Nov 2010 12:22 Edited at: 9th Nov 2010 13:46
Quote: "To be more precise, the effect affects the left and right sides of the sphere, while there is an 'empty zone' that goes from pole to pole."


That's because you are using the sphere's default UV coordinates for looking up the mask texture and you are probably looking at the seam where the two edges meet. The mask texture gives zero distortion at the edges and hence on the sphere's seam as well.

A better way would be to do what's been suggested before - use the sphere's normal instead of a mask texture.

Would you like a demo?

Quote: "I guess that affects performance as well, oh well no big deal"


Yes. It might be possible to improve performance by using the set camera view command because I think we only need the bit that's covered by the heat quad. Food for thought.

Edit A quick test suggests that has no effect on performance - it's as if the whole scene is rendered before the clipping takes place. Here's the code I used - I got 340 fps with and without set camera view:



Edit2

Quote: "One additional comment, I see the 'HeatHaze3.fx' has float numbers expressed as 0.5, 1.0... without the final 'f', like 0.5f, 1.0f
Now if I'm not wrong, the shader is using double floats if the subfix 'f' is not used. This may affect performance in some cases."


I doubt it. The compiled shader code is the same in each case with my tests. I've no idea why some people add the extra "f" - it just makes cluttered code. Perhaps you could provide an example where it makes a difference?
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 10th Nov 2010 18:22
Quote: "That's because you are using the sphere's default UV coordinates for looking up the mask texture and you are probably looking at the seam where the two edges meet. The mask texture gives zero distortion at the edges and hence on the sphere's seam as well."

Yes that makes sense, I think I do not completely understand how the mask texture is being used now.

Quote: "A better way would be to do what's been suggested before - use the sphere's normal instead of a mask texture.

Would you like a demo? "

Well, do you have the time? I don't want to abuse. I think I understand the concept that you propose, but the result will always be one hundred times better if you put it down into HLSL code, rather than me
Although it would be nice to have the best shader possible, I'm overwhelmed at the moment. Any help would be very much appreciated

Quote: "Yes. It might be possible to improve performance by using the set camera view command because I think we only need the bit that's covered by the heat quad. Food for thought.

Edit A quick test suggests that has no effect on performance - it's as if the whole scene is rendered before the clipping takes place. Here's the code I used - I got 340 fps with and without set camera view"

That was a good idea. I get 158 fps without set camera view and 174 with set camera view, using 1680x1050, so it gives a little boost after all

Quote: "The compiled shader code is the same in each case with my tests. I've no idea why some people add the extra "f" - it just makes cluttered code. Perhaps you could provide an example where it makes a difference? "

No, sorry I don't have any proof. My opinion is based in the HLSL reference regarding double floats, and in the overall optimization for using floats with the nowadays videocards.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Nov 2010 19:04 Edited at: 10th Nov 2010 19:27
Quote: "That was a good idea. I get 158 fps without set camera view and 174 with set camera view, using 1680x1050, so it gives a little boost after all"


Sounds like it'll be worth a second look. Thanks.

Quote: "My opinion is based in the HLSL reference regarding double floats, and in the overall optimization for using floats with the nowadays videocards."


Could you be more specific about your source? This is what I see in the DX9 SDK docs about scalar types (vectors and matrices use the same basic types per element):

Quote: "Scalar Types (DirectX HLSL)
HLSL supports several scalar data types.

bool - true or false.
int - 32-bit signed integer.
uint - 32-bit unsigned integer.
half - 16-bit floating point value. Note that this data type is only provided for language compatibility. Direct3D 10 shader targets map all half data types to float data types.
float - 32-bit floating point value.
double - 64-bit floating point value.
"


If you declare something as "float" or "float4", etc, it will be a 32 bit value. If you want double precision you need to declare the variable as "double". I'm 99% sure the extra "f" has no effect, but I could be wrong .

Quote: "Well, do you have the time?"


Yes and no - I'll add it to my list.

Edit Returning to the "f" issue, you may be thinking of this:

Quote: "Floating point numbers
Floating point numbers are represented in HLSL as follows:

fractional-constant exponent-part(opt) floating-suffix(opt)
digit-sequence exponent-part floating-suffix(opt)

fractional-constant :
digit-sequence(opt) . digit-sequence

digit-sequence .

exponent-part :
e sign(opt) digit-sequence

E sign(opt) digit-sequence

sign : one of
+ -

digit-sequence :
digit

digit-sequence digit

floating-suffix : one of
h H f F
"


Note that the floating-suffix is marked as optional, i.e. "(opt)". I guess it may be a useful reminder for programmers who use a variety of precisions in their HLSL code - the usual choice being "half" versus "float".
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 11th Nov 2010 10:30
Quote: "Quote: "Well, do you have the time?"

Yes and no - I'll add it to my list. "

Thank you very much. I have too many opened fronts, so I'll check this when you have had the time.

Quote: "If you declare something as "float" or "float4", etc, it will be a 32 bit value. If you want double precision you need to declare the variable as "double". I'm 99% sure the extra "f" has no effect, but I could be wrong."

One thing is the variable declaration, and the other is the use of constants in the expresions, such as fixed numbers.
'Casting', that is to convert one type to another, is usually very expensive in performance terms.
Being it variables or constants, the compiler must order a casting to convert the final result to floats. The use of the subfix 'f' instructs the compiler and ensures that there will be no casting.
So as a good practice, I think it is good to not to mix integers/floats/doubles in the same expression, but always compute integers with integers and floats with floats, whenever possible.
I guess not that big deal anyway

Back on topic, I'll be paying attention for any updates you'd like to provide.
Latest news are that the Heat Haze effect is being applied for an 'enter atmosphere at high speed' effect. I'll show how it looks when it is finished

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Nov 2010 19:30
Quote: "'Casting', that is to convert one type to another, is usually very expensive in performance terms.
Being it variables or constants, the compiler must order a casting to convert the final result to floats. The use of the subfix 'f' instructs the compiler and ensures that there will be no casting."


Which compiler are you talking about?

I've just re-checked the compiled asm code from the HLSL compiler and I see the default constants don't appear in the asm listing so they must be passed to the shader at another point in the rendering cycle. In theory this only needs to happen once regardless of the size of the object or screen resolution - but what happens in practice is another matter. If, for example, it happens per screen pixel then you might be right about the casting issue but if it happens once per frame or only once per loaded fx file then the overhead must be trivial. In fact I don't believe any "casting" as you call it is involved at all at run time - but I'd like to see the evidence one way or the other. I'm wondering whether you are thinking about C++ behaviour. Unfortunately I don't know enough about that to comment.

Quote: "Back on topic, I'll be paying attention for any updates you'd like to provide."


Yes indeed. I'll try to look into it over the next few days.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 12th Nov 2010 08:50
Quote: "Which compiler are you talking about?"

Well... any! This kind of behaviour spreads from DBPro to whatever the language (being it compiled, interpreted or whatever), and HLSL files are compiled at run-time...

Quote: "In fact I don't believe any "casting" as you call it is involved at all at run time - but I'd like to see the evidence one way or the other. I'm wondering whether you are thinking about C++ behaviour."

Hey I didn't make up that word, lol. Here is an easy link about variable casting: http://en.wikipedia.org/wiki/Type_conversion
Read where it says...
Quote: "Implicit type conversion in C-like languages
Implicit type conversion... is an automatic type conversion by the compiler...
...In a mixed-type expression, data of one or more subtypes can be converted to a supertype as needed at runtime so that the program will run correctly..."

And yes, HLSL is a C-like language. In fact it is almost the same, it is just the base functions that are different.
Anyway only talking about concepts, there is no easy way to test if casting happens, but it does. Take the example that appears there:

Quote: "Although d, l and i belong to different data types, they will be automatically converted to equal data types each time a comparison or assignment is executed."

That conversion, automatic or forced, is the one that spends resources.

Quote: "Quote: "Back on topic, I'll be paying attention for any updates you'd like to provide."

Yes indeed. I'll try to look into it over the next few days. "

Fantastic

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Nov 2010 13:54
More relevant links might be the following:

Binary_Casts

Casting and Conversion

However, neither of these address the question at issue, namely whether you need the "f" suffix for floats in HLSL. The MS DX9 SDK docs suggest you don't since the presence of the decimal point is sufficient to cast a constant as a float rather than an integer - if it isn't then the suffix is NOT optional whereas the docs say it IS optional. Things ain't "optional" if you get different results with or without them.

I realise the SDK is not always correct or precise so you could still be correct. For example, it doesn't say explicitly whether "1.5" is cast as a 16 bit half float or a 32 bit float. Your comments suggest that it is unwise to write HLSL statements such as



since that would involve a cast from integer to float - and I agree with that and try to remember to write float constants as floats. However, I can find nothing which supports your contention that "1.5" is different from "1.5f" in HLSL - but it might be.

I know it doesn't seem to be a big issue - but if casting is done unnecessarily per pixel per frame then, as you say, it's best to avoid it if you can. I remain to be convinced that there is a casting issue in this case though.

Perhaps I ought to do some browsing on the GameDev forums.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 12th Nov 2010 16:01 Edited at: 12th Nov 2010 16:26
Quote: "... if casting is done unnecessarily per pixel per frame then, as you say, it's best to avoid it if you can."

Well, why to take any risks? Besides, from my C/C++ point of view, I'm used to see the trailing 'f', because it is the only way to diferentiate double floats from single ones, so in fact it increases the readability, in my opinion.

If you are still interested perhaps we could finally make some testings. Just pick a bunch of high poly count objects like,



and then apply a different (but the same) test shader to each one, something like this,



Build the same version with floats, like

Or/And


You can even do a test with doubles...


Then we could try to see if there's a noticeable difference between each version

[EDIT: Oh well I rather prefer that you play with the heat haze shader than with this, lol, but hey you please have fun ]

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Nov 2010 18:14 Edited at: 12th Nov 2010 18:28
Quote: "Oh well I rather prefer that you play with the heat haze shader than with this"


Me too.

I've had an inconclusive afternoon browsing this.

But discovered lots of interesting other stuff on the way.

For example:

Introduction to HLSL

(note the absence of the "f" and even of the "." in several places, especially after page 23)

Dark Secrets of Shader Development

Clever Shader Tricks http://developer.amd.com/media/gpu_assets/04%20clever%20shader%20tricks.pdf (you'll need to cut and paste the link )

The last one has some interesting comments about the trade off between maths instructions versus texture read instructions. Looks like maths is good, texture reads are bad on newer cards.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Nov 2010 16:39
Quote: "note the absence of the "f" and even of the "." in several places, especially after page 23"

Oh maybe he became lazy?
Interesting stuff anyway

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Nov 2010 16:48
Here's a simple version of the heat haze using the sphere's normals instead of a mask texture.

Is this the sort of thing you had in mind? If so, then we can probably tweak the code and tidy a few things up. I was a bit handicapped by the fact that I wasn't quite sure of the effect you wanted.

Shader:



Revised dba code:

Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Nov 2010 18:22 Edited at: 13th Nov 2010 18:24
Quote: "Is this the sort of thing you had in mind?"

Well, not exactly

To fade the edges of the object, I was thinking in dot multiplying the world normal with the camera view. That way edges at the border are more faded.
Perhaps this is more expensive in calculus, your method, based on Z component of world normal should do the same with much more less calculus, but I guess that the result is equally a little bit less integrated for the edges.

This is the 'HeatHaze5.fx' version.
It is based in the 'HeatHaze4.fx', no texture mask, but using the dot(normal, camera_view) technique:



And here is how it looks:



But I have tried to do the same with the texture mask version ('HeatHaze3.fx'), and the results have not been so good. It results in a very low effect, perhaps because the last calculus makes the result very small.

Please take a look to see if we can have the best of both worlds with a texture mask and the 'dot(normal, camera_view)' approach.
What do you think?

This is the 'HeatHaze6.fx' version (to be revised).
It is based in the 'HeatHaze3.fx', it uses texture mask, but applies the dot(normal, camera_view) technique:



Any ideas? Perhaps I might be doing some mistake...

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Nov 2010 19:48
I think you'll find that your "camera view" method is the same as mine - except for minor details. What do you think the "camera view" vector is in view space if not simply the vector (0,0,1)?

In your final version, are you using the same UV coordinates for the mask as before? If so, then you will only make your earlier problem worse - which seems to be what you mean when you say "It results in a very low effect". I think you need to forget the coding for a moment and describe in words the effect you're after.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Nov 2010 11:03
Oops!

Quote: "I think you'll find that your "camera view" method is the same as mine "


Er, actually, it isn't. What you've done is what I should have done.

For some obscure reason I got confused between the camera's viewing direction (which is the same for all pixels in the scene and is what I was referring to in my previous post) and the direction of the camera's view of the current pixel which is what you've used and is what I should have used. Oh well.

Your 'HeatHaze5.fx' shader is what I intended except that I'd move the subtraction in the following pixel shader line into the vertex shader



so in the pixel shader you'd have something like




I'd also make sure that you are subtracting a float3 from a float3 to reduce the chance of accidental coding errors.

I still don't know why you want both the mask and this method though.

Sorry about any confusion my previous post caused.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 14th Nov 2010 19:18 Edited at: 14th Nov 2010 19:19
Quote: "What do you think the "camera view" vector is in view space if not simply the vector (0,0,1)?"

Yes, well I was to ask you if the world z normal was in the same XYZ frame of reference that the camera viewing direction, because that was the only explanation for being equal to the dot product.

Anyway glad that you made a revision, because I was starting to feel confused again

Quote: "...describe in words the effect you're after."

I'm sorry that I have not explained myself, here is another sample of what the improvement is about.
Imagine that the effect is the black area:



So what I would like is to use a 3d mesh instead of a plane, while keeping the 'fade away' of the effect at the edges. I have tried to do that with the 'dot(normal, camera_view) technique', glad to know that it was a good approach

Quote: "I still don't know why you want both the mask and this method though."

Yes I think you are right. Now the normal map should be enough to create the haze effect, shouldn't it?

So here is the most advanced version, I moved the operations in the pixel shader to the vertex shader, as you suggested.

DBPro code:


Shader file 'HeatHaze6c.fx' code:


It works quite neat now, the fade away of the effect is perfect, however now I see a 'seam' from pole to pole
I'll upload a picture in the next post.

Attachments

Login to view attachments
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 14th Nov 2010 19:25 Edited at: 14th Nov 2010 19:26
Here is a picture of the problem:



A seam from pole to pole, that perhaps is better noticed at run time (instead of a picure).
Perhaps I made some mistake with the shader code, but, do you know if this is because the sphere-normal-tangent-bitangent old problem?
I've tried to normalize the input normals with no luck...

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Nov 2010 21:57
Quote: "Yes I think you are right. Now the normal map should be enough to create the haze effect, shouldn't it?"


Yes, it should.

Quote: "however now I see a 'seam' from pole to pole"


I was wondering whether that would come up.

Quote: "Perhaps I made some mistake with the shader code, but, do you know if this is because the sphere-normal-tangent-bitangent old problem?"


No, it's almost certainly because your normal map isn't seamless. Try a seamless one and I'd guess the seam will disappear. I'll see if I can dig one up from somewhere.

Sounds like we are on the same wavelength again.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 15th Nov 2010 10:11 Edited at: 15th Nov 2010 10:13
Quote: "Quote: "however now I see a 'seam' from pole to pole"

I was wondering whether that would come up. "

Lol, yeah Murphy's law is after us

Quote: "it's almost certainly because your normal map isn't seamless. Try a seamless one and I'd guess the seam will disappear. I'll see if I can dig one up from somewhere."

Right! Phew, lucky this time. Now it works perfetly!
I attach a corrected normal map texture

Quote: "Sounds like we are on the same wavelength again. "

It was about time!

Many thanks all along, I'll post a practical result with the latest advances

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Dec 2010 13:03
Hi guys, I've been watching this thread for a while now and I just realised I could really use this effect in my current WIP. I need a subtle underwater effect like this to use as a fullscreen shader.

I was thinking I could apply it to 'bitmap 0' but I'm not sure whether it would work how I'm imagining it.

Basically it's for a 2D game using Box2D. Has anyone tried using this fullscreen yet on a purely 2D game?

Any advice would be massively appreciated!

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 8th Dec 2010 05:40
If Box2D is strictly 2D then I'm not sure how this exact shader could be adopted to work. Is it possible to get the screen onto an image in real-time? If you could do that then one could probably make a simplified version of this with the help of Sven B's ImageKit plugin .


Guns, cinematics, stealth, items and more!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Dec 2010 10:29
Quote: "If Box2D is strictly 2D then I'm not sure how this exact shader could be adopted to work. Is it possible to get the screen onto an image in real-time? If you could do that then one could probably make a simplified version of this with the help of Sven B's ImageKit plugin"

I could be wrong but I think bitmap 0 (zero) is the rendered screen image. How would I use the image kit to get this effect?

Sorry, I have the image kit but haven't really used it much yet.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2010 11:35 Edited at: 8th Dec 2010 11:41
A standard fullscreen shader approach should work for this.

I also have a feeling that Lee introduced some screen effect commands a couple of upgrades back. Perhaps those are what you want? I haven't used those myself yet. I'll do some delving to see if I can find anything - of course I might be getting confused with the texture screen commands (which I also haven't used).

It's also possible that I'm just confused.

Edit

Not completely apparently. Look at these two commands:

texture screen
set screen effect

I haven't tried either yet - but they are both in the Help file.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Dec 2010 11:42
Quote: "A standard fullscreen shader approach should work for this.

I also have a feeling that Lee introduced some screen effect commands a couple of upgrades back. Perhaps those are what you want? I haven't used those myself yet. I'll do some delving to see if I can find anything - of course I might be getting confused with the texture screen commands (which I also haven't used).

It's also possible that I'm just confused. "

Yes I think a fullscreen shader is the way I want to do it. I didn't know about the screen effect commands but I know the texture backdrop command was recently re-introduced (for DarkCLOUDS I think), thanks for your help GG!

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Dec 2010 12:28
I believe fullscreen shaders will only affect camera 0, which is 3D only. Any 2d placed on it will not be affected by the shader. (As you need to place a 3D plain in front of the camera, any 2d will not be shadered)

If the box 2D plugin works entirely in 2D then it won't be able to be shadered.

My signature is NOT a moderator plaything! Stop changing it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Dec 2010 12:34
Quote: "I believe fullscreen shaders will only affect camera 0, which is 3D only. Any 2d placed on it will not be affected by the shader. (As you need to place a 3D plain in front of the camera, any 2d will not be shadered)

If the box 2D plugin works entirely in 2D then it won't be able to be shadered."

I hope (and think) you are wrong as a shader can be applied to an image and bitmap zero is an image (I think).

You don't have to use a plain in front of the camera either as you can just paste the returned image to the screen. I did that on "The Waystation"...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2010 12:48
I suspect Mobiius is right. You should be able to check easily enough though.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Dec 2010 16:44 Edited at: 8th Dec 2010 16:44
Yay! nod of approval from the venerable Green Gandalf! lol

Quote: "I hope (and think) you are wrong as a shader can be applied to an image and bitmap zero is an image (I think)."

true, but shaders have to be applied to objects, to generate said image.

Bitmap 0 is an image, just one created from the 3d world.

My signature is NOT a moderator plaything! Stop changing it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Dec 2010 17:01
Quote: "true, but shaders have to be applied to objects, to generate said image."

I'll let someone who knows what they're talking about answer that one.

Quote: "Bitmap 0 is an image, just one created from the 3d world."

That's a better way of putting it.

I guess that means it's impossible then... I thought the mighty GG would come to my rescue but even some things are beyond the gods.

I was hoping maybe if I created a memblock from bitmap 0 and an image from the memblock I could then apply a shader to it (or something along those lines) but I figure that would be too slow anyway...

"Set screen effect" didn't work either... it kind of worked on pasted sprites (using another effect) but not on the Box2D stuff.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Dec 2010 18:08 Edited at: 8th Dec 2010 18:10
If you want to apply per-object shaders to objects in Box2D, you need to do the rendering yourself. (It's actually fairly easy, just make a plain for each body and update its position and rotation each loop to the values returned by Box2D)

Full-screen shaders can be used with Box2D without too much difficulty. Create an image that you can render to (either using "set camera to image" or IanM's easy to use "make image" command) the size of the screen. Before calling "b2DrawWorld" call "set current bitmap" passing in the NEGATIVE version of the image ID you just created. You can texture a full-screen quad with the image and apply any full-screen shaders you want, just like normal.

eg.


I missed out all the parts that are identical for the normal code to get a fullscreen shader working.

You should be able to use 'texture screen' with the new image and 'set screen effect' to make it even easier!

[b]
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2010 19:32
Thanks Diggsey. Sounds like more experimentaion is on the way.

Quote: "I'll let someone who knows what they're talking about answer that one."


I think Diggsey just did that.

Quote: "Yay! nod of approval from the venerable Green Gandalf!"


Probably just a fluke.

Quote: "I thought the mighty GG would come to my rescue but even some things are beyond the gods."


That's where Diggsey comes in.

Quote: "it kind of worked on pasted sprites (using another effect)"


That's interesting. So how exactly did you do that?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 10:22
Quote: "If you want to apply per-object shaders to objects in Box2D, you need to do the rendering yourself. (It's actually fairly easy, just make a plain for each body and update its position and rotation each loop to the values returned by Box2D)"

I see what you're saying but it won't quite work for me. I made another game using transparent plains for netbooks (as this game is) and it ran at about 15fps. I don't want to re-write the whole thing just to find the same problem.

I'll go the fullscreen shader route using the Image Kit to apply the shader I think (getting some help from Sven B too!)... instead of using 'texture screen' and 'set screen effect' you can set the effect and paste the image in one command.

I'll let you know how I get on but I won't be using this shader now so if you want to follow my progress with this it'll be the underwater level of my WIP "Ker-Bang!".

Thanks for your help guys!

GG, I already changed the code so I can't remember exactly what I did that 'kind of' worked, sorry!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2010 11:26
Quote: "so I can't remember exactly what I did that 'kind of' worked"


That happens to me increasingly often.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 12:28 Edited at: 10th Dec 2010 12:35
Can't find Matrix Utility command "make image"... is it from another plugin?

EDIT: NVM just saw the update... new commands!!

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Dec 2010 15:37
edit:
I made a few mistakes in my last post

Apparantly, using 'set current bitmap' with a negative number sets the camera number, not the image number (assuming you used 'set camera to image'). It SHOULD work by using IanM's 'draw to image' command instead if you used 'make image' but so far I haven't been able to get it to work...

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 15:47 Edited at: 10th Dec 2010 15:48
I have it writing to an image using IanM's new commands but it won't apply the particular effect I am using using the one technique I want to use.

Here's my 'semi'-working setup code:


...and for displaying it:


This works like a dream when I use the "Spiral" technique from the Image Kit but not for "Mapped" which is the one I want...

Here's the spiral technique:


Attachments

Login to view attachments
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 18th Dec 2010 23:44
Hmmm... I didn't keep up with all of these comments but I beleive I have found a bug. (this is with the original code) I can't seem to change the cameras to 1 and 2 instead of 0 and 1. I just have to adapt all of my code to fit 0 and 1, so it's not a huge problem, but whenever I try to update the shader everything freezes.

Nice work anyway though.

swis
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Dec 2010 00:35 Edited at: 19th Dec 2010 00:37
@swissolo:
Have you tried messing around with the setup function?


If you change MainCam to whatever your main camera is (camera 1 in your case I think) and HeatCam to your heat haze camera (camera 2 in your case) it should work . Let me know if the problem persists .


Guns, cinematics, stealth, items and more!
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 19th Dec 2010 02:58
These are the values I changed. I worked around them though.

swis
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 20th Dec 2010 00:37 Edited at: 20th Dec 2010 00:37
You're right, I just tried it myself . It's possible to do, but maybe a little more complicated than I'd like. I found that by setting the main camera to an image and then adding:

before sync, it worked. But that's a really messy workaround, and you're still rendering to camera 0. I'd need to think about it some more. Anyway, I'm glad you've found a way to work around it .


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 20th Dec 2010 11:19
Cameras ID must be consecutive, this happened to me too.
I think it is a behaviour that is already known.
Perhaps Green Gandalf can tell a little bit more about it, I'm kind of sure that he has met it before. Anyway it is like it is.

gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 26th Feb 2011 09:11
Sixty Squares thanks for starting this post

every time I find a new addition to what I have in mind
the closer I get to my goal ;o)

I understand some of what has been created here
in time I will understand a lot lot more ;o)

If a thought is Just a thought ~ so whats the main thought ?
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 26th Feb 2011 16:29
No problem, I'm glad it was helpful . Feel free to ask questions if you have any.


Guns, cinematics, stealth, items and more!
gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 26th Feb 2011 19:06
ok will do Sixty Squares

Sixty Squares it would not be too hard in setting up
several Blooms to run at the same time ?

If a thought is Just a thought ~ so whats the main thought ?

Login to post a reply

Server time is: 2024-05-07 15:39:07
Your offset time is: 2024-05-07 15:39:07