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 / Using a shader, how would I make some vertices transparent but not others in one mesh?

Author
Message
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 7th Sep 2013 09:45 Edited at: 7th Sep 2013 09:51
Hi all

Say I have a pretty big mesh in DBPro (~3000 vertices and ~20000 indices). I have three questions:

How would I make just some of the vertices transparent but not all of them?
How would I set the blend mode to "replace" (if such a thing exists - I want to overwrite the backbuffer with black wherever the mesh is transparent)?
How would I set the blend mode to "add" (to add to the contents of the backbuffer)?

Basically I want to have the edges of two meshes overlapping but blended together smoothly.

Any help would be much appreciated

EDIT: I have very little shader knowledge, but I really want to learn to write my own shaders, so if you could explain the shader that would be much more helpful...but it's not necessary and any help at all is much appreciated

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Sep 2013 12:14 Edited at: 7th Sep 2013 19:39
Quote: "How would I set the blend mode to "add""

in DBP:

in shader:

---
Vertex alpha:

You need to pass Color.a (interpolated vertex alpha) to pixel shader from vertex shader. You can use COLOR0 as output from vertex shader.
---
POST UPDATED

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 7th Sep 2013 14:55 Edited at: 7th Sep 2013 15:24
Thanks mr Handy, that's the kind of thing I was looking for, but...

Quote: "You need to pass Color.a (interpolated vertex alpha) to pixel shader from vertex shader. You can use COLOR0 as output from vertex shader."


...I have virtually no shader knowledge and therefore have no idea how to do that

Also, is it possible to apply the COLOR0 variable to only certain vertices and not all of them (but still within the one mesh)?

Thanks again

EDIT: Like this:



mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Sep 2013 15:23 Edited at: 7th Sep 2013 15:30
Oh. You see, first you need to find a shader (look for 'ultimate shader pack' thread) that will suit your needs.

Shader will override DBP lighting and object appearance so at least you need "per pixel lighting" shader to get basic lighting.

Then we could see what to do next.

COLOR is an every vertex color RGBA value. COLOR0 is a color at layer 0.

Imagine the shader as a regular "for" loop for every object pixel on the screen:
for pixel = 1 to 10000000000....
shader code:
{ render single vertex }
{ render single pixel }
next pixel


So you need to write RGBA (UV, whatever) value to every vertex. Shader will do the rest.

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 7th Sep 2013 15:38 Edited at: 7th Sep 2013 15:39
Quote: "Oh. You see, first you need to find a shader (look for 'ultimate shader pack' thread) that will suit your needs. Shader will override DBP lighting and object appearance so at least you need "per pixel lighting" shader to get basic lighting. Than we could see what to do."


Oh ok. I know using a shader instantly disables any automatic rendering, but I only need at most very basic per-vertex lighting, and for initial tests not even that is really necessary. I'll see what I can find.

Quote: "COLOR0 is an every vertex alpha value. Imagine the shader as a regular "for" loop for every object pixel on the screen."


Hmm...that's what I thought. What I need is a way to basically say, in the shader, "if vertextype=1 then setVertexAlpha(255) else setVertexAlpha(0)". Basically.

EDIT: Refer to the picture I added to my previous post.

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Sep 2013 16:00 Edited at: 7th Sep 2013 16:05
I just remember - DBP have a problem with use of vertex color in shader. So better to write alpha value as UV coordinate in vertex.

I wish some shader guys will come here and share with experience.

P.S. but what you want to do is not a problem

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 7th Sep 2013 16:11 Edited at: 7th Sep 2013 16:14
Ok I half found, half assembled a base shader. Turns out I can figure out very simple shader stuff but I still have no idea how to achieve what I need. Here's the base shader:



Quote: "I wish some shader guys will come here and share with experience."


Yes, me too. I was rather hoping Green Gandalf would chime in at some point; he's pretty good with shaders as far as I know.

Quote: "but what you want to do is not a problem"


Oh well as long as you have some idea how to achieve this I'm very happy for you to help

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Sep 2013 16:48 Edited at: 7th Sep 2013 17:34
Quote: " I was rather hoping Green Gandalf would chime in at some point"


Mention my name and I will appear.

You might be able to do it simply by adding vertex diffuse to the object's FVF format using the convert object FVF command. In that case you can set the colour of each vertex using the vertexdata commands. However, as Mr Handy says, that approach is bugged in some situations in DBPro and a simple solution is to do what mr Handy suggests, i.e. add extra UV coordinates to store the colour values. If your model has just one set of UV coordinates and you only need to set the transparency then you will need an extra set of UV coordinates. You can then store the alpha value in the U component, leaving the V component free for something else. You will still need to use the vertexdata commands though and the problem might be how to decide which vertices to set to zero and which to 1.

I'm sure mr Handy can give you the details.

I did have a simple demo doing something like this - I'll see if I can find it.

Edit It was quicker to write a new demo. Try the attached project.



Powered by Free Banners

Attachments

Login to view attachments
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Sep 2013 17:43 Edited at: 7th Sep 2013 19:41
POST UPDATED

This code works + blending customize feature!

Also here is HLSL blending table: http://www.gamedev.ru/terms/Blending You will need google translate! You can try different BlendOp, SrcBlend and DestBlend values (names)!



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Sep 2013 18:36 Edited at: 7th Sep 2013 19:04
mr Handy

This bit probably won't work as intended:



See image:



Edit My version of the shader is equivalent to the following in the technique:



I'll answer your other question about blendOpAlpha later.



Powered by Free Banners

Attachments

Login to view attachments
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Sep 2013 19:33 Edited at: 7th Sep 2013 20:03
GreenGandalf, I have not noticed your attached code. I have tested and fixed mine now (that post is updated).

EDIT: Oops, I also have not noticed your last EDIT, though I fixed code as you have said! I am too tired today

I have included BlendOp=ADD; because Clonkex asked add operation...

EDIT №9000: Oops, I also also have not noticed "the following are the default settings and can often be omitted".

I am so silly

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Sep 2013 21:29
As far as I can tell BlendOPAlpha does the same as BlendOp - although the documentation suggests otherwise. Here are the options for BlendOp (from the DX9 SDK docs) :

Quote: "D3DBLENDOP Enumeration
Defines the supported blend operations. See Remarks for definitions of terms.

Syntax
typedef enum D3DBLENDOP {
D3DBLENDOP_ADD = 1,
D3DBLENDOP_SUBTRACT = 2,
D3DBLENDOP_REVSUBTRACT = 3,
D3DBLENDOP_MIN = 4,
D3DBLENDOP_MAX = 5,
D3DBLENDOP_FORCE_DWORD = 0x7fffffff
} D3DBLENDOP, *LPD3DBLENDOP;

Constants
D3DBLENDOP_ADD
The result is the destination added to the source. Result = Source + Destination

D3DBLENDOP_SUBTRACT
The result is the destination subtracted from to the source. Result = Source - Destination

D3DBLENDOP_REVSUBTRACT
The result is the source subtracted from the destination. Result = Destination - Source

D3DBLENDOP_MIN
The result is the minimum of the source and destination. Result = MIN(Source, Destination)

D3DBLENDOP_MAX
The result is the maximum of the source and destination. Result = MAX(Source, Destination)

D3DBLENDOP_FORCE_DWORD
Forces this enumeration to compile to 32 bits in size. Without this value, some compilers would allow this enumeration to compile to a size other than 32 bits. This value is not used.

Remarks
Source, Destination, and Result are defined as:

Term Type Description
Source Input Color of the source pixel before the operation.
Destination Input Color of the pixel in the destination buffer before the operation.
Result Output Returned value that is the blended color resulting from the operation.



This enumerated type defines values used by the following render states:

D3DRS_BLENDOP
D3DRS_BLENDOPALPHA "




Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 8th Sep 2013 03:35
Wow that's perfect!! You guys are the best!

Quote: "Mention my name and I will appear."


lol I'll have to remember that...

Quote: "using the convert object FVF command."


Under no circumstances can I use that command. From talking to Grumpy One while he was making Forester Pro, I believe it's a very slow command. However, I make my mesh from scratch and it's procedurally generated, so it can be absolutely whatever I want it to be from the get-go (in other words I can generate the mesh with a specific FVF value).

Quote: "This code works + blending customize feature!"

Quote: "My version of the shader is equivalent to the following in the technique"

Quote: "I have tested and fixed mine now (that post is updated)."


Thanks so much! Those shaders are both perfect for what I need, AND due to all this, the whole shader thing FINALLY clicked in my mind and I understand it!! I've never had so much trouble trying to understand something before in my life...

I'll post the results of your efforts in my semi-secret project sometime later (HOPEFULLY today, but not necessarily...depends how well I go)

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2013 13:11
Quote: "AND due to all this, the whole shader thing FINALLY clicked in my mind and I understand it!! "


Now that's what I call a result.

Quote: "I'll post the results of your efforts in my semi-secret project sometime later (HOPEFULLY today, but not necessarily...depends how well I go)"


Looking forward to it.



Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 8th Sep 2013 15:38 Edited at: 8th Sep 2013 15:50
Quote: "Now that's what I call a result."


Haha

Ok, I have a slight problem, in that the mesh is completely invisible. I suspect it's not using the texture correctly, but I'm not sure how to make it use it because in Dark Shader you can just set the shader in a little box. I'm assuming this line...



...has to be set to the correct texture somehow.

And how would I modify the shader to not need that line, if possible? I mean, how would I make it just use the texture that's assigned the object already?

EDIT: If you reply and I'm silent for a day or two, don't worry, I have to go out for most of tomorrow and might not get a chance to reply on Tuesday

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Sep 2013 16:08
Quote: "...has to be set to the correct texture somehow."

No. But try this:


Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 02:34 Edited at: 9th Sep 2013 03:01
No, that doesn't fix it. Just a second while I create a simpler project to test this properly and make sure it's not my code causing the problem...

This is what the shader currently looks like anyway:



Also, just to be sure, the alpha value should be in the range on 0-1, correct? Not 0-255?

Ok, this is what I do in my test code now:



The debug info bit and the stuff up the very top is stuff I put into every single project I start with.

In this case the cube is visible and has a texture but since I've set the alpha to 0 directly in the shader with a constant for debugging, it actually shouldn't be visible. Also, the ambient lighting bit doesn't affect it and it appears fullbright.

The cube, being just a make object cube cube doesn't (as far as I know) have a second texture stage, so I commented out anything relating to that to make sure that wasn't causing a problem.

EDIT:

*FACEPALM*

I was editing the wrong copy of the shader!! Right, well the shader works perfectly, now to go figure out what's wrong in my code to stop it working properly on my big mesh...

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 03:51
Ok, I still can't get the shader to work on my big mesh (it's still invisible with the shader applied), but I did notice that even when the shader's not applied, if I turn the camera away so the mesh is entirely outside the view frustum, it still says I'm rendering ~6000 polys. I've done calculate objects bounds but it still does that. I've checked the positions of all the vertices and none are not where they should be (pretty sure about that). Could that somehow be linked to the shader issue?

I'll do some more experiments, but the Land Rover (that I was supposed to be taking today but it turns out had a flat battery due to the alternator not working) should just about be charged so I might not have much more time to fiddle.

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 04:03
Quote: "alpha value should be in the range on 0-1, correct?"

Correct.
Quote: "it's still invisible with the shader applied"

Take a note: that also can be the result of error in shader. Use 'perform checklist for effect errors' to be sure.

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 04:22
I did that already and there are no errors.

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 05:35
Ok, I'm VERY excited now!! Finally got it to work!!

In the end I got my test code (which just used make object cube to make a test object) and did this instead:



...because that's basically how I was creating the mesh in my main project (only I wasn't typing out the vertex data by hand ). As I was writing that code I noticed there was an extra parameter in lock vertexdata for limb that I didn't know about. I ignored it to begin with as I just wanted to see if I could get the simpler test code to act the same was as the main code, and lo and behold when I applied the shader the object disappeared. Yes! That meant it was something to do with how I was creating the object.

So I remembered that extra parameter and tried using it. A value of 1 did nothing, but when I tried 2 it worked! The object appeared again, this time with the shader applied! So, in future, remember that the vertexdata set up in an object created using make object new from the Matrix1 DLLs isn't properly initialised until you lock the vertexdata with that lock mode parameter set to 2.

Yes!! Very happy!

Time to go tidy up my very messy code (it always ends up horribly messy when I have to spend hours debugging something obscure) and then add tri-planar projection to the shader (lets see I get that far without needing help again ).

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 06:01
Ok, he's the current result without tri-planar blending or lighting (except ambient) applied yet:



And here's the shader that achieves that:



The only thing is that the blend between the two textures goes purple. Is there another way to blend (I assume in the pixel shader)? None of the other BLENDOP modes blend any better (in fact most result the terrain being mostly black).

Overall very happy with the result

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 9th Sep 2013 10:02 Edited at: 9th Sep 2013 10:04
How would you adjust the shader to represent an RGB value, rather than the alpha? So instead of a vertex being transparent it could be a hex value, such as 0x8000FF00

EDIT: Further to this, can secondary (or more) textures be blended in this way too?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 11:20
Quote: "can secondary (or more) textures be blended in this way too?"

Alpha blending has a limit depending on GFX card.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 11:57
Quote: "The only thing is that the blend between the two textures goes purple."


That's caused by rendering your semi-transparent object before the other object so it gets blended with the backdrop (blue) instead of the true background objects. Just make sure you're using the correct transparency modes. If all your objects have the transparency mode set then you'll need to make sure the objects get rendered in the correct order.

To begin with try



I'm not sure why your code seems to work without that. I don't get transparency unless I use that.



Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 16:10
Quote: "That's caused by rendering your semi-transparent object before the other object so it gets blended with the backdrop (blue) instead of the true background objects."


Oh DUH! *facepalm* THAT'S why the page make sure it's black before blending!! I kinda forgot about that... Thanks awfully!

Both objects are transparent (they overlap) and the blending works perfectly for me without turning on object transparency.

Quote: "How would you adjust the shader to represent an RGB value, rather than the alpha? So instead of a vertex being transparent it could be a hex value, such as 0x8000FF00

EDIT: Further to this, can secondary (or more) textures be blended in this way too?"


I actually have no idea. Well, I mean of course it can be done (and now that I think about it it should be a fairly simple thing to do), but I don't have much of an idea as to how this would be done.

Actually, I would start by setting the diffuse in the vertexdata to the colour you want with set vertexdata diffuse, then use this shader:



I have no idea if that shader would work (it's just off the top of my new-to-shaders head) but you're welcome to it

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 9th Sep 2013 16:32
Here's what it currently looks like, with basic lighting, tri-planar projection and the background set to black so it blends properly without going purple



The only thing is, the tri-planar projection rotates the textures on some angles, and I have no idea how the maths works for this kind of thing. Anyone know if it's possible to fix this? I want all my textures to be facing the same way if possible.

Current (somewhat messy) shader:



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 19:34
Quote: "I want all my textures to be facing the same way if possible."


Is that possible with triplanar texturing? The three planes are at right angles to each other so I'm rather baffled by what you mean.

Quote: "Both objects are transparent (they overlap) and the blending works perfectly for me without turning on object transparency."


Oops! I'd been experimenting and had commented out the alphablending line in the shader (that line is NOT a default setting). You only need the set object transparency command if you need to adjust the render order or use other features. So, yes, it works fine for me too without that command.



Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 10th Sep 2013 02:42
Quote: "Is that possible with triplanar texturing? The three planes are at right angles to each other so I'm rather baffled by what you mean."


Well...for example, the lighter texture in the picture above (the one with the lines in it) is a sliding wood panel texture (it was the first one I found; it's going to be dirt and grass eventually ) and all the lines should be one direction, but on slopes (and near them due to the blending), the lines go a different direction. In my mind it seems possible to rotate the projection somehow, but I'm not sure how that would be achieved if it is indeed possible.

I mean, it's not a big deal if I can't fix it because it'll be dirt and grass and you won't see the rotation, but I'd like to be able to have tongue-and-groove wood landscapes if I want

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 10th Sep 2013 02:52
It's ok, I fixed it myself. Well, as much as is possible. I was staring at the shader trying to work out which bit defined which direction the projections came from, and noticed this bit:



So I tried changing the X and Z around on coord2, and it rotated the texture 90 degrees on level surfaces. So I fiddled around until I got all the projections set the correct way around to give the best result. Ignoring the fact that I probably need to tighten the blending a bit (I found a number in the shader that adjusts blending ), I'm rather pleased with the result:



Quote: "I'd been experimenting and had commented out the alphablending line in the shader"


Haha good one

Current (tidied) shader:



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Sep 2013 15:01
Sounds like you've got it sorted.

As I guess you've discovered, tri-planar texturing is quite easy in the shader.

The next thing to think about is whether you want to adjust the contrast along the seams between the different copies of the texture. Without such an adjustment the seams where the blending weights are far from 0 or 1 will tend to look blurred compared to the rest. If you're interested I'll dig out one of mine - unless you want to practise a bit more...



Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 10th Sep 2013 16:07
Quote: "If you're interested I'll dig out one of mine"


Yes please! I'm not quite sure what you mean about contrast along seams, so I'd have a lot of trouble modifying my shader

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 11th Sep 2013 06:34
Can you post your compiled EXE Clonkex? The screenshots look interesting.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 11th Sep 2013 07:21
Quote: "Can you post your compiled EXE Clonkex? The screenshots look interesting."


No, sorry, that leaves my DLL open for theft (because it's easy to extract DLLs from the EXE) and as it will be a paid DLL I can't risk it, but sometime in the next couple of weeks, hopefully, if I can get it mostly working I'll release a limited version for free.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 11th Sep 2013 07:33
Quote: "No, sorry, that leaves my DLL open for theft (because it's easy to extract DLLs from the EXE) and as it will be a paid DLL I can't risk it, but sometime in the next couple of weeks, hopefully, if I can get it mostly working I'll release a limited version for free."

Good luck. Hope it makes you a mint.

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 11th Sep 2013 07:53
<hijack>
For the record; I couldn't get the shader working that instead of transparency, it changed the RGB colour value.
</hijack>

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Sep 2013 16:52
Quote: "I couldn't get the shader working"


Which shader? Several versions by different authors have been posted here.

Quote: "instead of transparency, it changed the RGB colour value"


What happens if you change the backdrop colour? Sounds like the issue we discussed earlier.



Powered by Free Banners
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 13th Sep 2013 15:36
Quote: "Good luck. Hope it makes you a mint."


Thanks, me too

Currently working on what is possibly the hardest thing to code yet...realtime updating

Quote: "<hijack>
For the record; I couldn't get the shader working that instead of transparency, it changed the RGB colour value.
</hijack>"


Hey, that's not a hijack. This is a thread about shaders and you're welcome to ask your questions here also

Quote: "Which shader? Several versions by different authors have been posted here."


Probably this one (from this post):



Quote: "I couldn't get the shader working that instead of transparency, it changed the RGB colour value."


Just to be clear- you want to change the RGB values for each vertex separately (or all the same, up to you) instead of changing the transparency, right?

Just a tip that I discovered: if your object is created using IanM's Matrix1 DLLs, you'll probably need set object transparency objNum,2.

Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 4th Nov 2013 14:04 Edited at: 26th Oct 2015 03:57
Ok, so after a fair amount more work I decided writing a wrapper for the awesome Polyvox library wasn't going to cut it, primarily because Polyvox doesn't limit its generated meshes to 65535 indices and its incredibly difficult to cut them up for use in DBPro in a memory-efficient manner, but also because its really hard to smooth a voxel terrain when its generated with Marching Cubes.

SO. I decided to write my own voxel terrain library.

Crazy.

I had not the faintest clue where to begin, but after reading through an large amount of stuff, I discovered a scarily simple way of doing it (I might attempt to explain how I did it sometime, but not right now).

And after an enormous amount of work, I finally have a result:



I started out just using lists of vertices and scanning through them to find a vertex. It's fairly slow doing it like that. So I hit upon the idea of using an octree system. I spent at least a week converting my code. The octree would make the slowest part of the code at least 100x faster. Seriously. However as I went further and further, and the code got more and more complicated, I realised the new octree system was causing significant slow-downs in previously fast areas, so much so that just 4 hours ago I scrapped the whole octree altogether and returned to my previous code.

Last time I used the normal scan-through approach, the code was working to create an unsmoothed blocky terrain, but the smoothing was broken. So the moment I returned to my previous code I set about fixing the smoothing, which was confused me for about an hour until I realised the bug. Then it all worked beautifully. And you can see the result above.

NOW. The problem is that it's slow. Really slow. That little tiny terrain (32 voxels across) took 9.25 seconds to generate. That's with 3 smoothing passes. With no smoothing it takes 0.667 seconds to generate, but that's useless unless you're making Minecraft-like terrain, and even then it takes too long.

So I have to find a way to make it faster. I'm currently thinking along the lines of "containers" which split up the vertices based on position, in a similar way to the octree, but in such a way as to allow a simple calculation to access the vertex directly by its number, unlike with the octree system.

Wish me luck!

EDIT: Also, I haven't set it up to generate the necessary polygons for texture blending. It's trivial, though, so I'm leaving it 'til later.
gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 23rd Nov 2013 21:11
@Clonkex

I was wondering if you had an example I could play with ?

to move side ways - is to move forward
Since a Strait line gets thin fast
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 16th Dec 2013 05:54
Quote: "I was wondering if you had an example I could play with ?"


Sorry, no. Not yet If you were hoping to be able to modify the terrain in realtime, that doesn't even work yet Or rather, I haven't tried to make it work yet. This project is postponed until after Christmas, because as it is I don't have the time to work on it. After Christmas, however, it won't be long until you CAN have a demo version of the plugin

Be patient, it will come

Login to post a reply

Server time is: 2024-05-18 09:45:14
Your offset time is: 2024-05-18 09:45:14