# Lewa

Member

36

421 Neutral

• Rank
Member

• Interests
Programming
1. ## OpenGL Calculate depth of front sphere from back side

That is EXACTLY what i needed/what i was looking for. Thank you! Although i'm having a hard time understanding why this formula works. (As i seem to misunderstand how the viewspace works.) What exactly do you mean with "parallel"? If they are axis aligned in view space?
2. ## OpenGL Calculate depth of front sphere from back side

I nearly got it working. But there still seems to be a minor error in the calculation of the mirrored depth value. Here is the current fragment shader (vertex shader is the same as above:) #version 330 in vec4 oColor; in vec2 vTexcoord; out vec4 outputF; in vec4 gl_FragCoord; uniform sampler2D sGeometryDepth; in vec4 gl_FragCoord; in vec4 vFragWorldPos; in vec4 vOriginWorldPos; in mat4 vProjectionMatrix; float linearizeDepth(float depthVal,float zNear,float zFar) { float n = zNear; // camera z near float f = zFar; // camera z far float z = depthVal; return (2.0 * n) / (f + n - z * (f - n)); } void main() { float uZnear = 0.01; float uZfar = 500.0; //get texture coordinates of the screenspace depthbuffer vec2 relativeTexCoord = vec2(gl_FragCoord.x,gl_FragCoord.y); relativeTexCoord = relativeTexCoord-0.5+1.0; relativeTexCoord.x = relativeTexCoord.x/1280.0; relativeTexCoord.y = relativeTexCoord.y/720.0; //depth of the backfacing sphere pixels and of the level geometry (depth texture of different FBO) float backDepth = linearizeDepth(gl_FragCoord.z,uZnear,uZfar);//back depth float geometryDepth = linearizeDepth(texture2D(sGeometryDepth,relativeTexCoord).r,uZnear,uZfar);//geometry depth //Now we have to calculate the front depth //--------------- Calculation of front depth--------------- //get distance from origin to the fragment (in viewspace) float depthDiff = (vFragWorldPos.z-vOriginWorldPos.z); //substract depth difference from origin point in order to get the mirrored coordinate point of the sphere vec4 sphereMirrorPos = vec4(vFragWorldPos.xy,vOriginWorldPos.z - depthDiff,vOriginWorldPos.w); //apply perspective calculation vec4 projectedMirrorPos = vProjectionMatrix * sphereMirrorPos; projectedMirrorPos/=projectedMirrorPos.w; //depth calculation float frontDepth = (projectedMirrorPos.z + 1.0) / 2.0; frontDepth = linearizeDepth(frontDepth,uZnear,uZfar); //want to color only the pixels where the scene depth (provided by a screen space texture which is a depthbuffer of a different FBO) //is exactly in between the min/max depth values of the sphere if(backDepth>geometryDepth && frontDepth<geometryDepth){ outputF = vec4(1.0,1.0,1.0,1.0); }else{ discard; } } I believe the issue is somewhere here: float depthDiff = (vFragWorldPos.z-vOriginWorldPos.z); //add normal to origin point in order to get the mirrored coordinate point of the sphere vec4 sphereMirrorPos = vec4(vFragWorldPos.xy,vOriginWorldPos.z - depthDiff,vOriginWorldPos.w); "vFragWorldPos" is the position of the current vertex in ModelviewSpace. "vOriginWorldPos" is the origin of the sphere in modelviewSpace. I simply calculate the z difference of both points by substracting the z components of both vectors. Then i reconstruct the mirrored vertex coordinate by using the xy coordiantes of "vFragWorldPos" while the z-coordinate is calculated by substracting the depthDifference from the origin z-coordinate. The issue is that it doesn't seem to give correct results by doing so. I tested if this reconstruction method by changing this line: vec4 sphereMirrorPos = vec4(vFragWorldPos.xy,vOriginWorldPos.z - depthDiff,vOriginWorldPos.w); to this: vec4 sphereMirrorPos = vec4(vFragWorldPos.xy,vOriginWorldPos.z + depthDiff,vOriginWorldPos.w); which effectively calculates the depth of the back side of the sphere which i then compared with the values of the depth buffer. They are exactly the same. (which is correct.) But substracting the depthDiff value doesn't yield correct results. Is there something that i'm missing? Maybe the z coordinates of the vertices which were transformed to modelview space aren't linear?

4. ## Locked Update, unlocked Framerate - interpolation latency

Glad to hear that this solution isn't that uncommon. :)   That's a lot. o.O I'm curios now: what are the "common" tickrates used for games? (I know that this will depend heavily on the genre and gametype and has to be determined individually for each game.) Given that the this approach requires the CPU to be fast enough in order to process X amount of ticks per second (otherwise we would have a CPU bottleneck and the game would slow down) you need to make sure that every operation (physics, collission detection, AI, etc...) can be crammed into 1/600 of a second in order to run properly (at the desired speed), am i right? (Such a high tickrate wouldn't cope well with open world games which have way to much random variables influencing the load on the CPU?)
5. ## Locked Update, unlocked Framerate - interpolation latency

So is this a common thing in todays games? Running the simulation at 100+ ticks on the CPU and interpolating between the old- and current gamestate for smooth unlocked rendering? What about the introduced latency? (by being always one frame behind?)   Trackmanias implementation interested me as they have the same requirements as i do (consistency in the physics) but they manage to unlock the rendering framerate as well. (I suppose without introducing latency?) I wasn't able to find anything about their implementation on the internet though.   I have the same requirements. > Consistency in the physics but i would also like to have an unlocked framerate (without introducing additional latency due to the interpolation technique.)
6. ## Locked Update, unlocked Framerate - interpolation latency

I realise that this is one of those questions that gets asked multiple times a day, but after extensive research i wasn't able to answer one specific question (which i will get to.) (And yes, i've also read the "Fix Your Timestep" article.) So what i wanted to implement was a fixed update tickrate (like 60FPS) with the ability to unlock the rendering framerate to render the game as fast (and as smooth as possible.) The "easiest" approach would be to use a variable timestep (delta time) but i don't want to do that. Mainly due to consistency of the game physics/behaviour across multiple playthroughs.   So from what i was able to gather, there are two ways in implementing a gameloop with a fixed tickrate and an unlocked (variable) framerate: > Interpolation and Extrapolation. Extrapolation is basically a "prediction" of the gamestate in the next frame (which wasn't calculated yet on the CPU side.) So you do something like position + velocity * interpolationvalue during rendering. This may work, the issue is that the extrapolation can have wrong results (objects passing through geometry for a short timespan) before the position is corrected. Also movement which is non-linear like rotation, acceleration, etc... would also have wrong results.   The other things is interpolation. I like the idea of the approach. We take the last frame and the current frame and interpolate between them while the next game update is being processed resulting in smooth motion and it allows us to render the game at a higher framerate. Now the caveat here is latency. Because you interpolate between the last frame and the current frame, your game state is (visually) always 1 frame behind. This essentially increases the latency/responsiveness of the game. (At 30 fps its 33.33ms, at 60 FPS its 16.66ms) In my opinion this depends entirely on the gametype if this latency is acceptable or not. RPGs might get away with it, but fast paced games with emphasis on fast/reactive gameplay can suffer. And given that i'm working on a game which emphasizes fast/reaction based gameplay, this is an issue which i want to circumvent. (Currently i update at a fixed rate of 60 FPS.)   So my question is: How do games with the requirement of consistent physics/behaviour implement their gameloop while retaining the ability to render at an unlocked framerate? Competetive games come to my mind. But especially the Trackmania Series. AFAIK Trackmania has consistent physics (Otherwise all those "press forward and let the car magically drive through the whole track" maps wouldn't be possible) . But it's also able to render at an unlocked framerate.  Here is a video where someone did a benchmark and was able to run the game at 200-400 FPS: [media]https://www.youtube.com/watch?v=Jk_N09Z4YXE[/media] My question is: How is that possible? Trackmania is a fast paced racer which needs low-latency input (I can't imagine that they are sacrificing substantial latency for framerate independence). Are they using interpolation at all? How is their gameloop implemented?   The only solution i'm able to come up with with regards to interpolation is making the game update at a very high (fixed) rate (like 200 ticks per second.) in order to reduce the latency as much as possible.
7. ## (First) commercial indie game - is it that hard?

I get the feeling that Austria is (in general) very unfriendly for small businesses/sole-proprietors due to the mandatory insurance. (No one who only earns 5-6K in a year will be able to pay 2.5K or more for insurance and live from that effectively.) It sounds somewhat funny that you can be executed by the local "self-employment/business" social insurance ... (which is seperate from the social insurance which normal employed people get.) Oh well...      It may be a possibility, but i would like to avoid any kind of legal trouble by doing so. Not to mention the language barrier and the lack of knowledge about the specific laws.   Although a possibility which i'll look into is the LLC in poland. (I'm polish after all and i'm visiting my grandmother/family in poland anyway on every vacation.)     I informed myself a bit about the polish LLC last night. There is a yearly cost that you have to consider. 1) around 440 Z?otych to pay to the KRS (some form of yearly documentation of the LLC) per year (is around 110 euros) 2) monthly payment of around 300-500 Z?otych (around 75-125 euros, can be even higher) to pay for "bookkeeping services" LLCs in poland have to do "full bookkeeping" (at least that's how it's called here. Sole-proprietors/Self-employers don't need to do that.). From what i've heard/read you can do it yourself (which would save you the monthly payment) but it's strongly recommended to pay an accountant/bookkeeper to do it for you. (As it seems to be rather complex?)   But i'll inform myself further on this and search an accountant. (Before i start to post more uninformed/false information. :P )     Still, i'm open for more input/insight as to how that stuff looks like/works in other countries. (To get an idea if such costs are the norm or if i happen to live in a country which is rather "business-unfriendly" for small companies)
8. ## (First) commercial indie game - is it that hard?

And there is no additional cost involved (up to the 18k limit) which might eat away your income? (Like the said social insurance or any other stuff like that which you "have" to pay yearly and/or is mandatory.)   A friend of mine who already sells a game on steam faced the problem that his income was going above the 5k limit. In order to avoid the mandatory insurance (which would cut his income in half and would generate costs over the next years) he had to generate cost in order to stay below that level. (he even stopped advertising/talking about the game on his blog/twitter/youtube and reduced the price of the game on steam...)       At first, i was also considering an LLC as an option. (Especially because of the legal insulation which you have mentioned.) But it turns out that it's even more costly/complicated to create said company here. As an example, in Austria you need to have a at least a capital stock of 35k€ in order to start a GMBH (which is the austrian/german equivalent of an LLC.)   The other option would be to open an LLC in poland. The requirements in poland are far less restrictive (You can start an LLC with a capital stock of just 5000 Z?otych which is around 1200 euros.) But you still have ongoing costs of running an LLC (in addition to paying the insurance in Poland, which is around 3000 euros in a year) and it's (as far as i know from reading on the internet) harder to manage compared to a sole proprietorship. (But i'll look into that further.)       Well, i probably should. Although, i'm not sure if i'll be able to avoid the insurance costs. (It's mandatory for everyone, even if you have a job and doing indie-dev as a part-time job.) (Best part is that if you work full time and do part-time self employment, you pay insurance twice. Once as self-employment and a second time from the full-time job...)   I don't want to dive into gamedev full-time (still studying). Just wanting to tap my toe into the water to gain some experience and see how well indie dev would work out for me.

10. ## (Managed) Master Server - hardware requirements and cost?

I tried to come up with a "worst-case" scenario. Though, i might overestimate this number. (Again, no experience. Never released a commercial game so i can't even roughly estimate how many active players there would be.)   Question: There are for sure mobile and PC games which host their own leaderboards/stats on seperate servers. Are all of them always using dedicated machines or is there a scenario where a v-server (or virtual webserver) would suffice?