Jump to content
  • Advertisement

Phoenix_1271

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

102 Neutral

About Phoenix_1271

  • Rank
    Newbie
  1. Phoenix_1271

    River simulation

    River height 2 [SOLVED]: I have encountered another problem on my road to create water on irreagular terrain. After reading and implementing paper from my previous question (hydrostatic pressure columns) I ended with really granular heightmap image (areas with water and areas that are dry are on really odd places). That's even more weird because water level is set to half of the maximum terrain value so all cells should be overlapping at least a little and water should flow between adjecent cells. Does anyone has slightest clue what am I doing wrong? SOLUTION: Everytime I got real stuck and wrote problem to this board I have found solution within next 24 hours - LOL. Solution was quite simple - I forgot that there is pixel-to-texel offset. So I got interpolated color values instead of original in every step. That was causing the problem because image was really badly degraded in about 100 time steps. So if you are doing some image processing don't forget to add epsilon values to your texCoords. Epsilon = 0.5f / dimension_of_texture
  2. Phoenix_1271

    OpenGL GUI

    Little tutorial on inheritence and collections, because I think you don't exactly get it: class Base { public: Base() { } virtual ~Base() { } virtual void Draw() = NULL; string GetID() { return myID; } protected: string myID; }; class Foo : public Base { public: Foo() { someArray = new char[4]; myID = "foo"; } ~Foo() { delete [] someArray; } virtual void Draw() { cout << "Drawing something"; } private: char * someArray; }; Creating object Base * foo = new Foo(); Constructors will be called in this order: Foo::Foo() -> Base::Base() Drawing: foo->Draw() Result on standard output: Drawing something; Deleting: delete foo; Destructors will be called in this order: Foo::~Foo() -> Base::~Base() Generic collections: vector<Base*> myVector; Inserting: myVector.push_back(foo); Deleting certain object from collection: void DeleteObject(string ID) { vector<Base*>::iterator it; for (it = myVector.begin(); it != myVector.end(); it++) { if ((*it)->GetID() == ID) { delete *it; myVector.erase(it); return; } } } It doesnt matter what type of ID you will use - it can be some string, pointer or anything else that is suitable. String was used to show how iterators works. I would recommend you to buy a book on C++ programming and study basic techniques that this language offers. Alse check out this library documentitaion for C/C++. There you can find some examples as well.Hope this example helps.
  3. Phoenix_1271

    OpenGL GUI

    If you use C++ (strongly recommended for this type of work). Create abstract class that will have function: virtual void Draw() = NULL; Then do some inheriting for your objects and implement this method. Then you can have your collection for example vector<BaseObject> list, where stored objects are created this way BaseObject temp = new TextBox(). In rendering loop you will go throught this collection and call simply Draw() function that will properly select draw code for specified object.
  4. Phoenix_1271

    River simulation

    Thank you for reply. Yestarday I have solved other two problems (common thing when I got stuck for week and then ask somewhere ). Solutions are posted in upper topic for those who will wonder how to do it.
  5. Phoenix_1271

    River simulation

    Hi, this is my first post for this forum so I hope that this questions wouldn't be too stupid I have decided that I would like try to do water simulation according to this paper. And because I like some challenge I would like to extend it to flowing river simulation. For 3D rendering I am using DirectX 11. 1) Heightfield question [SOLVED]: On page 3 you can find some equations for flowfiled texture. Start point is to create heightfield texture based on the terrain mesh of the river. Everywhere I looked I found only tutorials on generating terrain from height maps but not vica versa. My current solution in HLSL shader looks like this (code bellow). I take my Camera class and set position and rotation so I look perpendicular to the terrain I'm rendering. Then I multiply all matrices and set position to depth variable (for precision). In pixel shader I do logarithmic calculation of depth value that ranges from 0.0f (near plane) to 1.0f (far plane) so I have more range for depth values (most of them is between 0.95f and 0.99f). And by some trial-error process I found two values minRange and maxRange where my model is visible. Then I scale values from 0.0 to 1.0 to indicate how much hight is there. When I asked my friend what he thinks about this solution he replied that it's kinda weird and I should reconsider it. So question number one is: Is there any other elegant and intuitive way to create heightfiled map? SOLUTION: There is much easier way to do this. Just take distance from camera to vertex and send it to pixel shader, then depending on maximum height you set for 1.0f value compute right color value. Vertex shader //Globals cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; //Typedefs struct VertexInputType { float4 position : POSITION; float4 texCoords : TEXCOORD0; float3 normal : NORMAL; }; struct PixelInputType { float4 position : SV_POSITION; float distance : TEXCOORD0; }; //Vertex Shader PixelInputType main(VertexInputType input) { PixelInputType output; //Change the position vector to 4 units for proper matrix calculations input.position.w = 1.0f; //Calculate the position output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); //Get distance from camera output.distance = output.position.z; output.position = mul(output.position, projectionMatrix); return output; } Pixel shader cbuffer RangeBuffer { float3 cameraPosition; float maximumHeight; }; //Typedefs struct PixelInputType { float4 position : VS_POSITION; float distance : TEXCOORD0; }; float4 main(PixelInputType input) : SV_TARGET { float rangeValue = 1.0f / maximumHeight; float height = cameraPosition.y - input.distance; float colorValue = rangeValue * height; float4 color = float4(colorValue, colorValue, colorValue, 1.0f); return color; } 2) Gradient question: Next step is to compute gradient from heightmap texture. This part is little fuzzy for me. From mathematical description I know that gradient is derivation in horizontal and vertical direction. When I searched on the internet I found 2 possible solutions. One mentioned that gradient equals Sobel edge detection. I don't think this one is right. Other one was mathematical with this equation (found here): (f(x+h) - f(x-h)) / 2h = f'(x) + O(h[sup]2[/sup]) Question here is: Is this the right way to calculate gradient? If so am I understanding it right that I take samples that lies left/right for X or up/down for Y part of vector from current sample position and then divide it by 2. Final gradient should be computed as square root from sum of X and Y gradient. Another thing that's bugging me is value representation inside texture. Image channel values are in positive range but when I am going down the values should be negative. How this should be done? 3) River height [SOLVED]: Most water simulations expects that ocean / pond / etc. have flat surface. So you just need to set some constant for water level to find out if you are above or inside water volume. That doesn't need to be true in river. You can have quickly flowing stream from some hill that ends in little pond and from the edge of the pond is waterfall. If I want to add some rigid objects to flowfield map for splashing effects I first need to know how hight is actual water level at any position. I thought I could render riverbed with heightmap shader and add some constant that would indicate where and how hight water is before adding visible part of rigid objects to calculation. But this would be bad idea if somewhere in the terrain could be found ocal extreme (pond) because here should be flat surface. Any ideas how to achieve this? SOLUTION: This is no easy task to do. Party my solution was correct. You are adding some constant for initialization over terrain height so you are building water heightmap. To create lakes, waterfalls and etc. you have to edit this heightmap according to preassure between surrounding cells. More on this topic in this paper. Thank you for your ideas / suggestions / solutions. They will be deeply appreciated.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!