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.

Dark GDK / How to make a change of the transparency of a flat object on the fly?

Author
Message
s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 14th Sep 2014 19:55 Edited at: 14th Sep 2014 19:59
I need analog of sprite's dbSetSpriteAlpha() for semitransparent flat objects.
In 3D-game I use semitransparent wave from spaceship (Picture 1). Wave should gradually become more and more transparent, and then should disappear. But I can not change transparency of OBJECT on-the-fly, like I can do this with SPRITE using dbSetSpriteAlpha(). What should I do?

I use 24-bit images without transparency (Picture 2) and this code:
+ Code Snippet

I can not use "dbFadeObject(int iObject, int iFade)" because I need to use "dbSetObjectLight (b, 0)" in my scene.
I can not use dbSetObjectTransparency() for some reason.
I do not want to use the atlas of images of waves from opaque to transparent.
Other variants?..

Attachments

Login to view attachments
Rudolpho
11
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 15th Sep 2014 12:55
You can either use dbSetAlphaMappingOn or implement it in your own shader that you assign to the object. If you want the default lighting model I would assume the internal alpha blending shader contains that.


"Why do programmers get Halloween and Christmas mixed up?" + Code Snippet
s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 15th Sep 2014 20:54 Edited at: 15th Sep 2014 23:06
Thanks, but dbSetAlphaMappingOn() gives me bug:
dbSetAlphaMappingOn() gives transparency gradually only with 32-bit images with dbSetObjectTransparency(,1). I use dbSetObjectTransparency(,1) for my semitransparent 32-bit image of flat object of very far nebula.
If I use for wave "24-bit images + dbGhostObjectOn(b,0)", all OK except for the possibility of partial transparency of my semitransparent wave.
If I use for wave "32-bit images + dbSetObjectTransparency(,1) + dbSetAlphaMappingOn()", all OK with partial transparency of wave, but wave is overlapped by fery far nebula.



Rudolpho, can you give me simple example of shader fx for simple manipulations with alpha? Please, if you can.
.

Attachments

Login to view attachments
s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 15th Sep 2014 23:41 Edited at: 15th Sep 2014 23:44
Epilogue.

For lack of a better option, I decided to use dbSetAmbientLight(100) + dbSetObjectLight(,1) + dbFadeObject() for the wave, and for volume objects (spaceships) will use the shader fx of light/shadow. Now wave becomes transparent gradually, as I wanted.
Rudolpho
11
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 16th Sep 2014 01:48
Quote: "Rudolpho, can you give me simple example of shader fx for simple manipulations with alpha? Please, if you can."


Setting the alpha is very simple; basically your pixel shader outputs a float4 where the first component is the amount of red, the second green, the third blue and the fourth alpha of the current pixel. All values are given in the normalized (0..1) range.
Something like this will work (incomplete code only showing a simple pixel shader without struct definitions and the like):

+ Code Snippet

The problems you seem to be having is probably more due to incorrect depth ordering of your objects. Are you sure that (the pivot point of) the nebula object is indeed further away from the camera than your wave object? I am unsure whether DBPro/DarkGDK does any depth sorting at all for transparent objects but you should probably use dbSetObjectTransparency(...) on all objects that use some kind of transparency (ie. both of your wave and nebula objects). For this particular case where the objects probably won't differ in Z order (you say the nebula is supposed to be very far away in the distance) you might get away with disabling z-writes/-reads for them (dbEnableObjectZRead(...) / dbDisableObjectZRead(...) and so on).

The alpha mapping issues with 24-bit images is probably related to the fact that such image formats only have RGB and no alpha channel.


"Why do programmers get Halloween and Christmas mixed up?" + Code Snippet
s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 16th Sep 2014 19:37
1) I understand. Thank you for help.

2) if you're interested:

camera: (0,75,0) is looking at the (0,0,0).

wave: (x,0,z).
dbSetObjectLight(,0) + dbDisableObjectZWrite() + dbSetObjectTexture(,2,1) + dbGhostObjectOn(,0) + 24-bit (picture on the black fon).

nebula: (0,-900,0).
dbSetObjectLight(,0) + dbDisableObjectZWrite() + dbSetObjectTexture(,2,1) + dbSetObjectTransparency(,1) + 32-bit (semitransparent picture with alpha).

Result: graphic bug.

But now I found decision (look at my previous post).
P.S. Object with dbSetObjectTransparency() is not good for all cases, because it is very specific command and gives sometimes strange graphic bugs (with "SPARK trail particles" above it; with other flat objects with dbSetObjectTransparency() above it; and some other cases). I am trying to avoid this command.

Thank you for help.
WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 21st Sep 2014 18:39
Quote: "I do not want to use the atlas of images of waves from opaque to transparent."


After looking into this problem, I discovered two things. Another missing function; dbTextureBackdrop() - now fixed. And a function I was an aware of that may be the answer to your problem; dbSetImageTranslucency().

s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 21st Sep 2014 19:10
WOW! It is interesting! dbSetImageTranslucency() -- VS's intellisence show info about it, but I can not find any info about this command in "DarkGDK's Help" or "DBPro's Help". Please, can you give me some more info about this command?
WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 21st Sep 2014 19:27 Edited at: 21st Sep 2014 19:30
Intellisence shows the function as - void dbSetImageTranslucency(int iID, int iPercent). The function sets the alpha channel of an image. iPercent is actually a value from 0 to 255.

This doesn’t look like it will work either. Between setting the object to not be effected by light and the ghosting on, seems make every attempt fail.

TheComet
9
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Sep 2014 01:03 Edited at: 22nd Sep 2014 01:06
What you could also do is modify the alpha channel of each vertice's diffuse attribute.

+ Code Snippet

This requires the object's FVF_DIFFUSE attribute to be set with dbConvertObjectFVF() (or something like that).

I like offending people. People who get offended should be offended. -- Linux Torvalds
WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 22nd Sep 2014 03:36
@TheComet - Brilliant! Your function is exactly what dbFadeObject() does. But, by using dbConvertObjectFVF(b, 338);- dbFadeObject() will work.

s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 22nd Sep 2014 21:58 Edited at: 22nd Sep 2014 22:16
1) Please, help. I wanted to test this TheComet\'s code:

+ Code Snippet

but I can not compile it. Error: \"identifier not found\". (picture is in attachment) Tested in 2 different source codes of 2 different programs.

I use last WickedX\'s lib & include. ALL other code in my programs works fine. What am I doing wrong?

2nd question) In 1st big program I have many pages of source code. In 1st page I use #include "DarkGDKWindow.h", in all other pages I use #include "DarkSDK.h".
In 2nd little program I have 1 page of source code and I use #include "DarkGDK.h". In both cases everything works perfectly.
Question: all right? "DarkGDK.h" and "DarkSDK.h" work the same way?

Attachments

Login to view attachments
TheComet
9
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Sep 2014 22:31
I actually translated that from DBP because I don't know DarkGDK

The DBP code was:
+ Code Snippet

Function names might be different in DGDK.

I like offending people. People who get offended should be offended. -- Linux Torvalds
WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Sep 2014 01:18 Edited at: 23rd Sep 2014 01:24
1) The D in data in the vertex functions need to be capitalized.

2a) It shouldn’t matter, but I would stick with DarkGDKWindow.h to be on the safe side.

2b) DarkGDK.h adds two defines before calling DarkSDK.h. Looks like they define the functions DarkGDK() and LoopGDK() as the internal function types DarkSDK() and LoopSDK().

I set my test code up exactly as you stated in the original post. Changing the FVF to 338 allowed dbFadeObject() to work on it.

s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 24th Sep 2014 01:14 Edited at: 24th Sep 2014 01:18
Hmm... This works:

+ Code Snippet

This does not work (wave disappears):

+ Code Snippet

1) Why?
2) I can not see this and compare now, but as I understand, SetObjectAlpha() changes only alpha, but 1st method changes alpha AND make colors more dark (this is bad!) because it uses this code:

+ Code Snippet

... why am I not right?
WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th Sep 2014 02:38 Edited at: 24th Sep 2014 23:13
1) TheComet’s function is only changing the diffuse colors alpha channel. Using dbConvertObjectFVF() only adds the diffuse property to the vertex format. By default the color will still be zero. This is the reason the object is not visible.

2) Since the object is textured, dbFadeObject() is changing it’s brightness. If you look at the first line you remarked, you might think the whole object would be one grayscale color. dbFadeObject() works perfectly for me. The object fades just as lowering the alpha channel of an image would, with transparency and without calling dbSetObjectTransparency() .

WickedX
8
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th Sep 2014 04:38
Looking over the DirectX SDK Reference, an object is lit in two ways. The vertexdata properties and by a material property. The make object functions do not set the vertexdata diffuse property. By using dbSetObjectLight( ,0) you are disabling the objects material. DarkGDK must use a default material that’s not affected by dbFadeObject(). Converting the object to use the vertexdata diffuse property allows the vertexdata diffuse property to take over allowing dbFadeObject() to work with the vertexdata diffuse propery instead. I’m tired, hope that made sense.

s_i
7
Years of Service
User Offline
Joined: 23rd May 2009
Location:
Posted: 24th Sep 2014 22:56
Yeah, very interesting, thank you very much! Now I understand why there is construction ''if-else'' in the function SetDiffuse(sMesh* pMesh, float fPercentage).

dbConvertObjectFVF(b,338) + dbFadeObject() works very well, I am glad.

Thank you, WickedX. Thank you, TheComet.

Login to post a reply

Server time is: 2017-04-24 06:22:13
Your offset time is: 2017-04-24 06:22:13