Underwater Terrain Shading
by Jacob Dankovchik · in Torque Game Engine Advanced · 02/17/2007 (11:01 pm) · 54 replies
This is the shader code for the stuff posted in the topic here: www.garagegames.com/mg/forums/result.thread.php?qt=39336
There are a few things I need to mention though. Unfortunately, I can't get it to work with Atlas2. I've not the time to learn the ins and outs of Atlas2 to get this working smoothly, so I'll just post the code here that I used in the past and let someone who knows the Atlas code better try to work it in. If someone out there does get it working, at least please post the solution... Otherwise I'd rather not you use it at all if you don't share your help.
Anyhow, the way this was setup to work was as a second pass called through the Atlas material with a multiply blend function. It would work out the shade value for the terrain underwater and just times that by the actual color.
It starts with a small engine change. I know this could probably be done better. And i've no clue the effect multiple waterblocks has. But this is to get the waterblock's size and position into the shader so we can check if the pixel is underwater. This goes in waterblock.cpp, in setShaderParams:
The shader requires 2.0, so assemble any material def's with it with that in mind.
And now the shaders itself. These aren't modified or cleaned up, this is just the stuff I used that works. No big deal to clean it up anyhow really. You get the idea.
There are a few things I need to mention though. Unfortunately, I can't get it to work with Atlas2. I've not the time to learn the ins and outs of Atlas2 to get this working smoothly, so I'll just post the code here that I used in the past and let someone who knows the Atlas code better try to work it in. If someone out there does get it working, at least please post the solution... Otherwise I'd rather not you use it at all if you don't share your help.
Anyhow, the way this was setup to work was as a second pass called through the Atlas material with a multiply blend function. It would work out the shade value for the terrain underwater and just times that by the actual color.
It starts with a small engine change. I know this could probably be done better. And i've no clue the effect multiple waterblocks has. But this is to get the waterblock's size and position into the shader so we can check if the pixel is underwater. This goes in waterblock.cpp, in setShaderParams:
reg[0] = mObjScale.x; reg[1] = mObjScale.y; reg[2] = mObjScale.z; GFX->setPixelShaderConstF( 9, (float*)reg, 1 ); Point3F pos = this->getPosition(); reg[0] = pos.x; reg[1] = pos.y; reg[2] = pos.z; GFX->setPixelShaderConstF( 11, (float*)reg, 1 ); reg[0] = mBaseColor.red;///mBaseColor.alpha ; reg[1] = mBaseColor.green;///mBaseColor.alpha; reg[2] = mBaseColor.blue;///mBaseColor.alpha; reg[3] = mBaseColor.alpha; GFX->setPixelShaderConstF( 17, (float*)reg, 1 );
The shader requires 2.0, so assemble any material def's with it with that in mind.
And now the shaders itself. These aren't modified or cleaned up, this is just the stuff I used that works. No big deal to clean it up anyhow really. You get the idea.
#22
03/30/2007 (7:33 pm)
We all have busy lives. I have more important things to work on than this at the moment. But the source code is there. Anyone familiar with the Atlas clipmap manager should find this fairly easy to move over.
#23
Not all of us great programers
Sorry for being crappy about it just would like to use the resource but after of this time something gets posted and then oh but by the way it doesn't work. It is just frustrating.
oh well, I hope one day it will get done.
03/31/2007 (8:43 am)
If it is so easy then why hasn't jacob been able to get something working to the community in the more than a year that he has worked on it.Not all of us great programers
Sorry for being crappy about it just would like to use the resource but after of this time something gets posted and then oh but by the way it doesn't work. It is just frustrating.
oh well, I hope one day it will get done.
#24
03/31/2007 (9:51 am)
Because I was trying to finish it up when Atlas made a significant change which effected how it all went into the engine. I don't have time to work on it now because Torque isn't exactly on the US Navy's priority list. If you want this damn code, do it yourself. Stop trying to make demands from everyone else like we owe you something. I did this for a project on my own, people liked it, asked for the code. I told you it wasn't ready, and its not. But thats you're problem now. Wanted it so bad, here it is, now shutup.
#25
03/31/2007 (11:41 am)
Wow, this place is getting worse and worse.
#26
If someone contributes to the community, almost everyone start thinking that it is a "must have" about the support in case of "main" product updated.
Jacob, you did a great job, and thanks a lot for your contribution, and the GG community is great because people like you are exists here.
And yeah, I can only re-post that Tim A., Ben G. and others are used to say sometimes (many? times): Need it? Do it yourself!
All of us are here for many reasons, and one of these reasons - "learning", and I prefer to call this "reason" as a major one, even you work for a commercial product or anything else. You got the product. You have full sources. All the rest is upon to you... Have something - help others. Stuck - ask, someone will reply you if they have an answer.
Anyway, Stefan, I think "this place is getting worse and worse" is not right words. It's just a "wrong"... right?
03/31/2007 (2:19 pm)
Stefan, seems that it's becoming like a "ritual" for many people.If someone contributes to the community, almost everyone start thinking that it is a "must have" about the support in case of "main" product updated.
Jacob, you did a great job, and thanks a lot for your contribution, and the GG community is great because people like you are exists here.
And yeah, I can only re-post that Tim A., Ben G. and others are used to say sometimes (many? times): Need it? Do it yourself!
All of us are here for many reasons, and one of these reasons - "learning", and I prefer to call this "reason" as a major one, even you work for a commercial product or anything else. You got the product. You have full sources. All the rest is upon to you... Have something - help others. Stuck - ask, someone will reply you if they have an answer.
Anyway, Stefan, I think "this place is getting worse and worse" is not right words. It's just a "wrong"... right?
#27
Yelling "damn" and "shut up" in the same post hardly makes you look any better.
03/31/2007 (3:16 pm)
Both. Yes, people have "no right" (lacking a better phrase here) to ask for support from volounteer contributors. But there is also very little reason to flame someone for his badly worded request, in the case of Barnette above. Yelling "damn" and "shut up" in the same post hardly makes you look any better.
#28
Theres no winning in these situations and it's a major motivation killer to have people pull it on you and have others try to justify it.
03/31/2007 (3:51 pm)
I wasn't flaming anyone. Damn and shut up are hardly much for flaming. I'm just slightly irked at people who seem to think everyone owes them something. I don't remember how many times I said this wasn't a done project and it didn't work yet. But people demanded it, Barnette included. I released it to meet their demands, and now suddenly nobody wants to bother with it, instead they want me to fix it.Theres no winning in these situations and it's a major motivation killer to have people pull it on you and have others try to justify it.
#29
03/31/2007 (4:53 pm)
I think there are quite a few who wants to tinker with it, if they knew how to do it.
#30
03/31/2007 (7:03 pm)
I think the problem is that a lot of people are still waiting for the Make Game Button still.
#31
@JD:
Sorry man I didn't mean to upset you, you have done amazing work. the point I was trying to make which I guess I did a lousy job of is Matt said it was fairly easy to fix. My point is that if it was easy it would have been done by now. This is simply beyond the understanding of many of us.
Again I appologize.
and if there is anyone who I can work with to get this going I would love to help. I simply suck at programing and am a 3D artist by profession.
PS: I for one am greatful for your service to our country Jacob.
04/01/2007 (10:06 am)
Oo! yeah I heard that is going to be a added feature next year. right after Constructor is released. That is gonna be sweet! JK@JD:
Sorry man I didn't mean to upset you, you have done amazing work. the point I was trying to make which I guess I did a lousy job of is Matt said it was fairly easy to fix. My point is that if it was easy it would have been done by now. This is simply beyond the understanding of many of us.
Again I appologize.
and if there is anyone who I can work with to get this going I would love to help. I simply suck at programing and am a 3D artist by profession.
PS: I for one am greatful for your service to our country Jacob.
#32
And yes, I'll agree that it isn't too simple of a task to get it working. You'd need to know how the clipmapping works pretty well because thats where I hit my snags when I tried. I'd really love to help and finish this too, I just don't have the time anymore. Some should open up in a couple months, we'll see if I can try some more stuff then.
04/01/2007 (4:47 pm)
Apology much accepted, and I apologize if I came off as overly hostile with that. Took it the wrong way is all.And yes, I'll agree that it isn't too simple of a task to get it working. You'd need to know how the clipmapping works pretty well because thats where I hit my snags when I tried. I'd really love to help and finish this too, I just don't have the time anymore. Some should open up in a couple months, we'll see if I can try some more stuff then.
#33
04/01/2007 (7:41 pm)
Cool if there is anything I can do with my meger knowledge let me know
#34
Have added the changes to the waterblock.cpp, compiled it with no errors, tested with old shaders, created 2 new files for shader (NewWaterP2_0.hlsl and NewWaterP2_0.hlsl in example/shaders/water), and have simple change the filenames in the datablock:
new ShaderData( WaterCubeReflectRefract )
{
DXVertexShaderFile = "shaders/water/NewWaterV2_0.hlsl";
DXPixelShaderFile = "shaders/water/NewWaterP2_0.hlsl";
pixVersion = 2.0;
};
Then started the engine, and have no water surface ;)
The console.log shown no errors.
04/10/2007 (6:29 am)
I havent get it work...Have added the changes to the waterblock.cpp, compiled it with no errors, tested with old shaders, created 2 new files for shader (NewWaterP2_0.hlsl and NewWaterP2_0.hlsl in example/shaders/water), and have simple change the filenames in the datablock:
new ShaderData( WaterCubeReflectRefract )
{
DXVertexShaderFile = "shaders/water/NewWaterV2_0.hlsl";
DXPixelShaderFile = "shaders/water/NewWaterP2_0.hlsl";
pixVersion = 2.0;
};
Then started the engine, and have no water surface ;)
The console.log shown no errors.
#35
04/10/2007 (7:59 am)
That won't work. The shaders are for Atlas, not for the water. Use the default water shaders.
#36
06/01/2007 (9:37 pm)
Anyone ever make any progress or just moved on to other things?
#38
;)
06/09/2007 (9:01 am)
Not bad there Matt, the water. Only problem is, its with Legacy which I just don't care for with its restricted size and such. I mean, it looks pretty good, but I perfer Atlas myself. Which is why I think my picture is better. ;)
#39
Hope things are going well here. hopefully the milittary isn't working you too hard.
06/09/2007 (9:20 am)
That was my sentiment. working on legacy is a waste of time.Hope things are going well here. hopefully the milittary isn't working you too hard.
#40
06/09/2007 (9:29 am)
I'd say that Legacy and Atlas each have their place, depending on what your project is. =) I'm happy to see both moving forward with exciting improvements!
Torque Owner James Brad Barnette
3Dmotif LLC