Jump to content

SpiderPig

Members
  • Posts

    2,348
  • Joined

  • Last visited

Everything posted by SpiderPig

  1. Your right, I eventually found that out. And it works really well. On my GTX 980Ti I rendered 1.6 million billboard trees at 100fps. Can't complain with that.
  2. I ended up finding a way, below is a snippet of code on how i got it to work. It's not as exact as using trig functions like cos(), sin() and atan2(), but the speed outweighs the accuracy. And it's not off by much. There's still a few things I can do to perfect it. ? float _diffX = _camPos.x - _mdlPos.x; float _diffZ = _camPos.z - _mdlPos.z; Vec2 _yVec = Vec2(_diffX, _camPos.z - _mdlPos.z).Normalize(); float _xzPart = sqrt((_diffX * _diffX) + (_diffZ * _diffZ)); Vec2 _xVec = Vec2(_camPos.y - _mdlPos.y, _xzPart).Normalize(); const float magicNumber = 6.343830794f; const float radToPi = 57.29577951f; const float sinCos45 = 0.707106781f; if (_yVec.x <= 0.0f && _yVec.y <= 0.0f) {//bottomLeft if (_yVec.x >= -sinCos45) { _yAngle = ((-_yVec.x) * radToPi) + (-_yVec.x * magicNumber); } else { _yAngle = 90.0f - (((-_yVec.y) * radToPi) + (-_yVec.y * magicNumber)); } } else if (_yVec.x > 0.0f && _yVec.y < 0.0f) {//bottomRight if (_yVec.x <= sinCos45) { _yAngle = -((_yVec.x * radToPi) + (_yVec.x * magicNumber)); } else { _yAngle = -90.0f + (((-_yVec.y) * radToPi) + (-_yVec.y * magicNumber)); } } else if (_yVec.x > 0.0f && _yVec.y > 0.0f) {//TopRight if (_yVec.x <= sinCos45) { _yAngle = (_yVec.x * radToPi) + (_yVec.x * magicNumber) - 180.0f; } else { _yAngle = (((-_yVec.y) * radToPi) + (-_yVec.y * magicNumber)) - 90.0f; } } else if (_yVec.x <= 0.0f && _yVec.y > 0.0f) {//TopLeft if (_yVec.x >= -sinCos45) { _yAngle = 180.0f - ((-_yVec.x * radToPi) + (-_yVec.x * magicNumber)); } else { _yAngle = 90.0f + ((_yVec.y * radToPi) + (_yVec.y * magicNumber)); } } if (_xVec.x <= 0.0f && _xVec.y <= 0.0f) {//bottomLeft if (_xVec.x >= -sinCos45) { _xAngle = ((-_xVec.x) * radToPi) + (-_xVec.x * magicNumber); } else { _xAngle = 90.0f - (((-_xVec.y) * radToPi) + (-_xVec.y * magicNumber)); } } else if (_xVec.x > 0.0f && _xVec.y < 0.0f) {//bottomRight if (_xVec.x <= sinCos45) { _xAngle = -((_xVec.x * radToPi) + (_xVec.x * magicNumber)); } else { _xAngle = -90.0f + (((-_xVec.y) * radToPi) + (-_xVec.y * magicNumber)); } } else if (_xVec.x > 0.0f && _xVec.y > 0.0f) {//TopRight if (_xVec.x <= sinCos45) { _xAngle = (_xVec.x * radToPi) + (_xVec.x * magicNumber) - 180.0f; } else { _xAngle = (((-_xVec.y) * radToPi) + (-_xVec.y * magicNumber)) - 90.0f; } } else if (_xVec.x <= 0.0f && _xVec.y > 0.0f) {//TopLeft if (_xVec.x >= -sinCos45) { _xAngle = 180.0f - ((-_xVec.x * radToPi) + (-_xVec.x * magicNumber)); } else { _xAngle = 90.0f + ((_xVec.y * radToPi) + (_xVec.y * magicNumber)); } }
  3. I'm currently trying to write a shader that makes every triangle of the mesh point to the position of the camera regardless of the camera's rotation. I think I can multiply the vertex positions in the vertex shader by a one of the matrices but I'm not sure which one or how. And I think the camera matrix will rotate the triangle to the same orientation as the camera and not just point to it's position? Basically I need the vertex shader (or geometry if it's easier) to do what Entity::Point() does but on each triangle and not the mesh as a whole. Anyone got any ideas on how to do this? ? EDIT : I've been getting the direction the camera like this; normalize(vsModelVertexPosition.xyz - cameraposition)
  4. Love it! Can't wait to see some awsome games made with "Turbo Game Engine"
  5. Looking forward to hearing more on this. On the subject of lighting, are there techniques around that allow infinite distance shadow rendering?
  6. I would like to see your approach to lighting. Very interested to see how it effects performance.
  7. Works now, thanks Ma-Shell!
  8. I had a GUI class before the in built system was available and I'd rather not go through and replace everything if I can help it. Run this code and you'll see the issue. Your code macklebee draws the text with transparency on a solid background. I want the entire image to be completely transparent. Then I will draw what I need to on it. Then it will be drawn over the top of previously drawn items. Buffer* buffer; bool App::Start() { window = Window::Create("Test"); window->Show(); context = Context::Create(window); world = World::Create(); Camera* camera = Camera::Create(); buffer = Buffer::Create(1024, 768, 1, 0); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); buffer->Enable(); buffer->SetColor(0, 0, 0, 0); buffer->Clear(); //buffer alpha is not being cleared context->SetColor(1, 0, 0, 1); context->DrawRect(80, 50, 100, 100); context->Enable(); context->SetColor(1, 1, 1, 1); context->DrawRect(10, 10, 100, 100); //white rectangle not showing. context->DrawImage(buffer->GetColorTexture(), 0, 0); context->SetBlendMode(Blend::Solid); context->Sync(); return true; } If I set the buffers alpha to 0, shouldn't it be transparent except for the red rectangle?
  9. I accidentally added an extra 1 in SetColor() when typing the post, sorry. Besides that, all the info is there. I've created a buffer and am drawing it to the context (not a materiel). The reason is so that any UI that may overlap other UI can be drawn to this buffer and then drawn last with context->DrawImage() on top of the whole screen. The drawing to the buffer works fine, but the buffer has to be cleared every frame so that previous drawings are gone. Which brings me to asking, how to clear the buffer with transparency because SetColor(1,1,1,0) (I think) should set it to complete transparency regardless of the RGB values. But it's not. I tried your suggestion with setting it as the current buffer first then calling context->SetBlendMode() but it still is just the RGB values, no alpha. If I draw the newly made buffer without clearing first, the image is totally transparent and only shows the drawings like it should, but it needs to be cleared ready for the next frame.
  10. I'm using a buffer to draw some 2D graphics too but can't seam to clear the buffer with transparency. I looked at the forum here for the info regarding buffers and 2D drawing; I tried clearing the buffer with this code but only get a white screen; //App Start Buffer* topLevelBuffer = Buffer::Create(1024, 768, 1, 0); //Draw Loop topLevelBuffer->SetColor(1, 1, 1, 0); topLevelBuffer->Clear(); topLevelBuffer->Enable(); DrawUI(topLevelBuffer); _context->Enable(); _context->DrawImage(topLevelBuffer->GetColorTexture(), 0, 0); Anyone had any luck with clearing to a transparent buffer?
  11. In C++, after you render the world you can just draw to the context. World->Update() World->Render() Context->DrawRect() Context->Sync()
  12. Hi, you can call Window::GetCurrent () and Context:: GetCurrent(). To access the camera in all classes however, I create a global variable that each class can access.
  13. I tried that and and it seems to do the exact same thing. With the following code though, GetRotation(false) works but GetRotation(true) dosn't. I think the global xy & z will vary to the local rotation due to rotation on multiple axis's, but it shouldn't set to zero suddenly then back to some other number should it? Vec3 rot = box->GetRotation(); rot.x += 0.2f; rot.y += 0.2f; rot.z += 0.2f; box->SetRotation(rot); Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); std::stringstream ss; ss << "rot = " << box->GetRotation().ToString(); context->DrawShadowText(ss.str(), 20, 20); ss.str(""); ss << "rot = " << box->GetRotation(true).ToString(); context->DrawShadowText(ss.str(), 20, 40);
  14. When turning an entity, GetRotation() will return correct for a while then the Z axis will pop to zero for a bit before it starts reading properly again. Below is some test code showing the problem. On my current project, sometimes the Turn() function will suddenly pop to random values, but I'm unable to reproduce this here yet. I'm using the latest BETA build. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* box; bool App::Start() { window = Window::Create("Turn Test",50,50, 1024, 768); window->Show(); context = Context::Create(window); world = World::Create(); DirectionalLight* light = DirectionalLight::Create(); light->SetRotation(35, 35, 35); Camera* camera = Camera::Create(); box = Model::Box(); box->Move(0, 0, 2); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } box->Turn(0.2, 0.2, 0.2); Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); std::stringstream ss; ss << "rot = " << box->GetRotation().ToString(); context->DrawShadowText(ss.str(), 20, 20); context->Sync(true); return true; }
  15. SpiderPig

    4.5 Beta Update 3

    Awesome! After updating though I get the following error; Cannot open include file: 'isteamparentalsettings.h': No such file or directory In the "steam_api.h" file.
  16. Lately I've been getting heaps of seemingly random errors. I traced a few of these problems to memory leaks which is why I started using smart pointers. But still I get random "Access Violations". Sometimes it will be inside a Leadwerks function and other times it will be in mine. I can stop the program and run again without cleaning the solution and it will crash somewhere else or it wont crash at all. Seems to be random and the only thing I think it could be is memory leaks. I'm not sure what else could cause random errors like this. Has anyone had similar problems or know of possible other causes / solutions?
  17. Thanks for the reply. I'll make sure they're setup right now.
  18. I just want to verify the way the physics commands should work. I'm assuming that Newton Game Dynamics uses real world equations to calculate the final force and velocity of objects. So if that's the case, what are the units of measurements that should be passed to each of the physics commands? If I set an entities mass to 100.0f, and say this is 100 kg, what should input into into "AddForce()"? m/s² or Newtons? It would make sense to be newtons because that's the measurement of force. And also "SetFriction()". Is this the friction coefficient or the force in newtons that has to be over come? Physics are not behaving the way I think they should in my game and I just want to make sure I'm feeding the commands the right values.
  19. I have the shader now and am making it work with Leadwerks at the moment. What texture bindings are you referring to? More textures would be good.
  20. Thanks Shadmar, the code helps a lot. I'm still looking for someone who can do it for me. I've posted the job on UpWork too. https://www.upwork.com/ab/applicants/866045947490144256/job-details
  21. I'm looking for someone to write a terrain shader that will texture a terrain model based on height and slope. I want it to use uniforms for the height and slope of each layer so I can change them through code. It will need to use at least four layers - each with diffuse, normal and specular maps. If it can use more layers that would be better. Also I would like the option to use an alpha map to further control where textures are shown. The terrain is a cube, pictured below; Would like it by the end of the month if possible. Will pay for the work too. PM me if interested.
  22. Thanks for the explanation it makes sense now. This is the code I use now for the normal; Vec3 Normal = Vec3(2.0*(center_r-center_l),2.0*(center_d-center_u),-4.0).Normalize(); I must be doing something else wrong somewhere though. This image is with the code above; And this image is with the command Surface->UpdateNormals() You can see the difference, the later being the desired result. I can see that the higher detailed mesh in the center of the terrain is pretty good in the first image as well as the second, but it's the lower detailed mesh that doesn't look great. Does the size of the LOD patches need to influence the length of the normal to get a softer transition? Or perhaps it's because I'm pre-calculating all the normal's for the different LOD levels and storing each LOD level in an array of Vec3's. One Vec3 for each vertex (or pixel of the height-map). This is the entire code for one 16 bit height-map; unsigned int total_indices = map_size * map_size; hills = (float*)malloc(total_indices * sizeof(float)); cFile* map = new cFile(); unsigned short* data_buffer = (unsigned short*)map->LoadBinary("Maps/Hills.r16", DATA_TYPE::UNSIGNED_SHORT); for (int e = 0; e < total_indices; e++) { hills[e] = data_buffer[e] * 0.00390625; } //this should be save as floats in a file //MAKE NORMAL BUFFERS FOR EACH LOD LEVEL////////////////////////////////////// int lod_levels = 7; int _skip_value[7] = { 1,2,4,8,16,32,64 }; n_x = (float**)malloc(_start_lod * sizeof(float)); n_y = (float**)malloc(_start_lod * sizeof(float)); n_z = (float**)malloc(_start_lod * sizeof(float)); for (int n_index = 0; n_index < 7; n_index++)//_start_lod { //perhaps make each array only the size of the vertexes needed int _lodsize = ((map_size - 1) / _skip_value[n_index]) + 1; n_x[n_index] = (float*)malloc(_lodsize*_lodsize * sizeof(float)); n_y[n_index] = (float*)malloc(_lodsize*_lodsize * sizeof(float)); n_z[n_index] = (float*)malloc(_lodsize*_lodsize * sizeof(float)); unsigned int id = 0, map_index = 0, current_index = 0; float center_l, center_r, center_u, center_d, center; Vec3 normal_buffer; //get the normals for each lod level? //int skip_value = (map_size - 1) / _lodsize; for (int y = 0; y < map_size; y += _skip_value[n_index]) { for (int x = 0; x < map_size; x += _skip_value[n_index]) { //if (x != 0 && x != map_size - 1 && y != 0 && y != map_size - 1) //{ //all the normals can be pre-calculated for speed increase //make a normal collection for each lod level current_index = (y * map_size) + x; center = HeightMaps->hills[current_index]; //HANDLE THE LEFT VERTEX////////////////////////////////////////// if (x == 0) { center_l = center; } else { map_index = (y * map_size) + (x - _skip_value[n_index]); center_l = HeightMaps->hills[map_index]; } ///////////////////////////////////////////////////////////////// if(x == (map_size - 1)){ center_r = HeightMaps->hills[current_index]; } else { map_index = (y * map_size) + (x + _skip_value[n_index]); center_r = HeightMaps->hills[map_index]; } if (y == 0) { center_d = HeightMaps->hills[current_index]; } else { map_index = ((y - _skip_value[n_index]) * map_size) + x; center_d = HeightMaps->hills[map_index]; } if (y == (map_size - 1)) { center_u = HeightMaps->hills[current_index]; } else { map_index = ((y + _skip_value[n_index]) * map_size) + x; center_u = HeightMaps->hills[map_index]; } normal_buffer = Vec3(2.0*(center_r-center_l),2.0*(center_d-center_u),-4.0).Normalize(); n_x[n_index][id] = normal_buffer.x; n_y[n_index][id] = normal_buffer.y; n_z[n_index][id] = normal_buffer.z; id++; } } } EDIT : I think I've found the issue. The problem was not setting the normal_buffer up to use the large distance between the vertices on the lower LOD levels. I used the following line and it looks good now; normal_buffer = Vec3(center_r-center_l, center_d-center_u,-(_skip_value[n_index]*10.0)).Normalize(); Multiplying by 10 made it less dark.
×
×
  • Create New...