Jump to content
  • Advertisement

NekoCode

Member
  • Content Count

    61
  • Joined

  • Last visited

Community Reputation

295 Neutral

About NekoCode

  • Rank
    Member

Personal Information

  • Role
    Programmer
  • Interests
    Art
    Audio
    Design
    Education
    Production
    Programming

Social

  • Steam
    jaydi2112
  1. NekoCode

    Asset storage

    Well, I already have rtti implementation, it does not need out-of-compiler scripts (like @Shaarigan's implementation). But until this moment I didn't know should I utilize rtti-style or not. Now I think I'll mostly use simple serialization/deserialization, but keep rtti system, may be one day it could be useful. Thanks for replies, opened my eyes a bit
  2. Hey everyone! Currently I am making my engine and I got one thing I am worried about. I am using text data format to store my assets (e.g. JSON objects or kinda "human-readable" formats), it requires to register every field I want to serialize and read it manually from file data: void Resource::Save(IFile* file) { file->Serialize("myField", myFieldValue); } void Resource::Load(IFile* file) { file->Deserialize("myField", &myFieldValue) .. and so on, manually, nothing else! } But I can't breathe calmly since I saw UE4 serialization/asset storage system, it uses rtti, it's MUCH easier to serialize objects and now I am unsure which method I should use: should I give all responsibility to rtti system(with lots of code hidden) or load everything I need manually just like first code example? I know I can code rtti that way so it will output "human-readable" files, but is it good thing to use?
  3. NekoCode

    Cascaded shadow map cutting

    Gosh! I simply did a stupid mistake by following Nvidia source, what I just was needed to do is to attach shadow light caster to camera or frustum center origin! http://www.gamedev.net/topic/672664-fitting-directional-light-in-view-frustum/#entry5259129   But if You have any another idea, you can tell me.
  4. Good day everyone! I am following Nvidia's CSM demo code, I got it working great, but I noticed that if I move a bit far away shadow splits start to work "inverted" ( i.e. not applying a split, but removing it ), here's video ( Gyazo ): https://i.gyazo.com/595aff92b3b0a989362c24cec6351b95.mp4   I even made code the same as Nvidia's code, but this artifact won't go away.  My camera setup: fov= 65.0f near = 0.1 ( 1.0 for shadow ) far = 3000   I tried to transpose light view matrix, but it results the same problem. I am generating "LookAt" matrix using the following code:   mLightView = ncMatrix4x4::LookAt( SVec3(0.0f), SVec3(-DirL.x, -DirL.y, -DirL.z ), SVec3(.0f, 1.0f, 0.0f) ) ;//DirL * dist, Lighttarget, Lightup);   "LookAt" method is fine. Could someone tell me what I am doing wrong if someone faced similar problem?   I can upload the whole code here, but it's 99.9% same as Nvidia's code. Thanks in advance!   EDIT: As I have noticed, shadow disappears only on first lod:
  5. NekoCode

    CSM depth artifacts

    Well, this issue got solved now. I've had different NEAR values for camera and split distances. Now I got another strange things: random black squares appear next to camera and follows it. :(
  6. Hello everyone!   I was learning and trying to adapt Nvidia's Cascaded shadow mapping technique, everything works fine but one problem. I hope my explanation will be good:   I got dynamic world with day/night change and I found a strange artifact. When it's sunrise/sunset time AND when I look straight to the sun camera I see strange black lines on the ground. I think its because of light's camera projection AND depth values.      My thoughts are that light view looks too horizontal depending on player's camera frustum, because that also happens when I look straight on the sun. NOTE: LIGHT CAMERA sees EVERYTHING except sky. That means that there are nothing! How can I set depth value so light camera won't see that as "empty space"?    Thanks in advance!   Here's my shader code: float csm_shadow( vec4 worldPos, float depthZ /* gl_FragCoord.z, not linear */ ) {     int index = 0;     mat4 mat = texMatrix0;       if( depthZ < far_d.x ) {         index = 0;         mat = texMatrix0; //        col = vec4(1.0, 0.0, 0.0, 1.0 );     }     else if( depthZ < far_d.y ) {         index = 1;         mat = texMatrix1; //        col = vec4(0.0, 1.0, 0.0, 1.0 );     }     else if( depthZ < far_d.z ) {         index = 2;         mat = texMatrix2; //        col = vec4(0.0, 0.0, 1.0, 1.0 );     }     else {         index = 0;         mat = texMatrix0;                  return 1.0;     }       vec3 worldPos2 = worldPos.xyz / worldPos.w;     vec4 shadow_coord = mat * vec4(worldPos2.rgb, 1.0);          float zLight = shadow_coord.z / shadow_coord.w; // Even if I am just keeping it as .z without /w it's the same result.          shadow_coord.w = shadow_coord.z;     shadow_coord.z = float(index);          // 3x3 filter blur.     vec2 offset = vec2( 0.000244,0.000244 );     float shadowTerm = 1.0f;          for( float x = -1.0; x < 2.0; x+=1.0 )     {         for( float y = -1.0; y < 2.0; y+=2.0 )         {             float lightDepth = texture( shadowSamplers, vec3(shadow_coord.xy + vec2(offset.x * x,offset.y * y), shadow_coord.z) ).x;                          if( zLight > lightDepth ) {                 shadowTerm -= 0.10;             }         }     }          return shadowTerm; }  
  7. Thanks for help! I am trying to figure it out by the method you suggested me, but I also have finished it in different way: drop a ray to the landscape chunk! float normalRay = dot( vNormal, vRayDir ); // vRayDir in current case is a vector down ( 0.0f, -1.0f, 0.0f ).   if( normalRay > 0.0f ) {                           float fDistance = (dot(vNormal, vOrigin) + D) / NdotR; // D = -dot( vNormal, vTriangle[0] );                          if( fDistance >= 0.0f && fDistance < fMaxDistance ) // fMaxDistance in current case is 1024.0f             {                 vOriginOut = vRay * fDistance + vOrigin;                                    return IsInside(vOriginOut);             } }
  8. Hey everyone,   I am doing infinite procedural landscape in my game engine and I've stuck with one problem. For example, every chunk is 512x512 size and has local coordinates ( 0....512 with different x,z values ) AND information about its placement in the world: m_chunkPosX and m_chunkPosZ..    So, HOW can I convert camera position to chunk's local space ( 0, 512 ), so I will be able to use the following method to get correct height: // X and Z can be only local space ( 0.. 512 ), but my camera can be everywhere!! inline float GetHeightAt( int32_t x, int32_t z ) {       return m_mapData[ z * m_iChunkSize /* 512 */ + x ].y; } Thanks!
  9. Hey everyone,    I just made two composite passes in my engine, but I am not sure if I am doing this right, let me explain.. I had something like this:   ( really simple render to texture method ) <pseudocode> sceneFBO->Bind() renderWorld() // Draw my world sceneFBO->Unbind()   // Now render to texture glUseShader( compositeShader ) glBindTexture( sceneFBO->colorTexture.. depth etc )   glBindVertexArray( r2tVAO ) glDrawArrays( GL_TRIANGLES, 0, 6 ) // Draw quad on the screen glBindVertexArray( 0 ) glUseShader(0); </pseudocode>   But since I got also post process effects I came up with an idea, I described below how I made my code now:   <pseudocode> // Draw my scene again sceneFBO->Bind() renderWorld() // Draw my world sceneFBO->Unbind()   // Now render to texture to another FRAMEBUFFER, so process Deferred Lighting and another non-postprocess stuff here compositeFBO->Bind() glClear(....) // do the same stuff to draw the quad glUseShader( compositeShader ) glBindTexture( sceneFBO->colorTexture.. depth etc )   glBindVertexArray( r2tVAO ) glDrawArrays( GL_TRIANGLES, 0, 6 ) // Draw quad on the screen glBindVertexArray( 0 ) glUseShader(0); compositeFBO->Unbind()   // // New step, render another composite with prepared texture from compositeFBO glUseShader( anotherCompositeShader ) glBindTexture( compositeFBO->colorTexture.. depth etc )   glBindVertexArray( r2tVAO ) glDrawArrays( GL_TRIANGLES, 0, 6 ) // Draw quad on the screen glBindVertexArray( 0 ) </pseudocode>   tl;dr I render to texture twice, but first pass is to FBO(screen quad!!) and second pass to screen.    I haven't noticed any performance drops, but is it correct to do something like this? I really don't want to render my scene (more than 1m meshes) and I don't want to use ping-pong method.   Thanks in advance. 
  10. NekoCode

    How to handle multiple lights?

    I recommend using deferred lighting if you want A LOT of lights.
  11. Hey everyone, after porting my application to Windows I've noticed that noise generation through GLSL gives better results nor on Mac. Both platforms are using OpenGL 4.0 and higher and has 1366x768 resolution.   Here are screenshots, LOOK at sky and clouds, clouds are looking "softer on Windows":       Here's Mac OS X:     ( Sorry, I couldn't take it from one position of course, it's procedural world ).   Here's shader, "clouds" method generates random things. // //          *                  * //             __                * //           ,db'    *     * //          ,d8/       *        *    * //          888 //          `db\       *     * //            `o`_                    ** //         *               *   *    _      * //               *                 / ) //             *    /\__/\ *       ( (  * //           ,-.,-.,)    (.,-.,-.,-.) ).,-.,-. //          | @|  ={      }= | @|  / / | @|o | //         _j__j__j_)     `-------/ /__j__j__j_ //          ________(               /___________ //          |  | @| \              || o|O | @| //          |o |  |,'\       ,   ,'"|  |  |  |  hjw //          vV\|/vV|`-'\  ,---\   | \Vv\hjwVv\//v //                     _) )    `. \ / //                    (__/       ) ) //    _   _        _                                _ //   | \ | |  ___ | | __ ___     ___  _ __    __ _ (_) _ __    ___ //   |  \| | / _ \| |/ // _ \   / _ \| '_ \  / _` || || '_ \  / _ \ //   | |\  ||  __/|   <| (_) | |  __/| | | || (_| || || | | ||  __/ //   |_| \_| \___||_|\_\\___/   \___||_| |_| \__, ||_||_| |_| \___| //                                           |___/ // //  OpenGL skyscatter shader. //   //  Based on Sean O'Neil's GPU atmospheric scatetring algorithm.   #ifdef USE_PRECISION precision PRECISION_TYPE float; #endif   #ifdef _VERTEX_   layout(location = 0) in vec3 inPosition;   uniform vec3 v3CameraPos; // The camera's current position. uniform vec3 v3LightPos; // The direction vector to the light source. uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels. uniform float fCameraHeight; // The camera's current height. uniform float fCameraHeight2; // fCameraHeight^2 uniform float fOuterRadius; // The outer (atmosphere) radius. uniform float fOuterRadius2; // fOuterRadius^2 uniform float fInnerRadius; // The inner (planetary) radius. uniform float fInnerRadius2; // fInnerRadius^2 uniform float fKrESun; // Kr * ESun uniform float fKmESun; // Km * ESun uniform float fKr4PI; // Kr * 4 * PI uniform float fKm4PI; // Km * 4 * PI uniform float fScale; // 1 / (fOuterRadius - fInnerRadius) uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found). uniform float fScaleOverScaleDepth; // fScale / fScaleDepth   uniform float Samples;  // Not integer, no need to cast back then.   uniform mat4 MVP;   out vec3 v3Direction; out vec3 mSecColor; out vec3 mFronColor; out vec3 mWorldPos;   float scale(float fCos) { float x = 1.0 - fCos; return fScaleDepth * exp(-0.00287 + x * (0.459 + x * (3.83 + x * (-6.80 + x * 5.25)))); }   void main( void ) { // Get the ray from the camera. vec3 v3Pos = inPosition; vec3 v3Ray = v3Pos - v3CameraPos;          // Length. float fFar = length( v3Ray );      v3Ray /= fFar;   // Ray starting position. vec3 v3Start = v3CameraPos; float fHeight = length( v3Start ); float fDepth = exp( fScaleOverScaleDepth * (fInnerRadius - fCameraHeight) );      float fStartAngle = dot( v3Ray, v3Start ) / fHeight; float fStartOffset = fDepth * scale( fStartAngle );   // Scattering. float fSampleLength = fFar / Samples; float fScaledLength = fSampleLength * fScale;      vec3 v3SampleRay = v3Ray * fSampleLength; vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;   // Now loop through the sample rays vec3 v3FrontColor = vec3(0.0); for( int i = 0; i < int(Samples); i++ ) { float fHeight = length( v3SamplePoint ); float fDepth = exp( fScaleOverScaleDepth * ( fInnerRadius - fHeight ) );          float fLightAngle = dot( v3LightPos, v3SamplePoint ) / fHeight; float fCameraAngle = dot( v3Ray, v3SamplePoint ) / fHeight; float fScatter = ( fStartOffset + fDepth * ( scale( fLightAngle ) - scale( fCameraAngle ) ) ); vec3 v3Attenuate = vec3( exp( -fScatter * ( v3InvWavelength * fKr4PI + fKm4PI ) ) );          v3FrontColor += v3Attenuate * (fDepth * fScaledLength); v3SamplePoint += v3SampleRay; }     // Mie and Rayleigh colors. mSecColor = v3FrontColor * fKmESun; mFronColor = v3FrontColor * (v3InvWavelength * fKrESun);      gl_Position = MVP * vec4(inPosition, 1.0);   v3Direction = v3CameraPos - v3Pos;   mWorldPos = vec4( inPosition, 1.0 ).rgb; } #endif   #ifdef _FRAGMENT_   const float cloudsZoom = 0.01;   uniform float mTime; uniform sampler2D fNoiseTex; //uniform sampler2D fStarsTex; uniform vec3 v3LightPos;   uniform float g; uniform float g2;   uniform float mNightPerc;   in vec3 v3Direction; in vec3 mSecColor; in vec3 mFronColor; in vec3 mWorldPos;   layout(location = 0) out vec4 mColor; layout(location = 2) out vec4 noLight;     #ifdef USE_CLOUDS vec3 noise( const vec3 tex, float t, const vec2 vel ) {     vec2 dt   = vec2( vel ) * t;     vec2 tex1 = vec2( tex.xz ) + dt;          vec3 n1   = texture( fNoiseTex, tex1       ).xyz / 2.0;     vec3 n2   = texture( fNoiseTex, tex1 * 2.0 ).xyz / 4.0;     vec3 n3   = texture( fNoiseTex, tex1 * 4.0 ).xyz / 8.0;     vec3 n4   = texture( fNoiseTex, tex1 * 8.0 ).xyz / 16.0;       return ( n1 + n2 + n3 + n4 ) / ( 0.5 + 0.25 + 0.125 + 0.0625 ); }   const float cloudDensity = 2.6; float density ( float v ) {     return clamp( (1.0 + cloudDensity) * pow ( v, 4.0 ) - 0.3, 0.0, 1.0 ); }   #endif     const vec3 fullSkyColorModifier = vec3( 0.2, 0.45, 3.3 ); const vec3 sunColorModifier = vec3( 0.3, 0.55, 0.9 );   void main( void ) { float fCos = dot(v3LightPos, v3Direction) / length(v3Direction); float fRayleighPhase = 1.0 + fCos * fCos; float fMiePhase = (1.0 - g2) / (2.0 + g2) * (1.0 + fCos * fCos) / pow(1.0 + g2 - 2.0 * g * fCos, 1.5); fMiePhase *= 5.5;   vec3 mBlued = mFronColor * fullSkyColorModifier; vec3 mSeced = mSecColor * sunColorModifier;       // Add color layer.. #ifdef USE_CLOUDS     const vec4  cloudColor     = vec4 ( 1.0, 1.0, 1.0, 1.0 );     const vec4  cloudColor2    = vec4 ( 0.87, 0.8, 0.8, 1.0 );     const float cloudDensity1  = 1.7;     const float cloudDensity2  = 2.9;          vec3 n1       = noise( mWorldPos * 0.03, 0.06 * mTime, vec2( 0.2, 0.05 ) );     vec3 n2       = noise( mWorldPos * 0.03, mTime * 0.2, vec2( 0.2, 1.1 ) );          vec4 skyColor = vec4( 1.0 - exp( -1.5 * (fRayleighPhase * mBlued + fMiePhase * mSecColor ) ), 1.0 );     vec4 clouda    = mix( skyColor, cloudColor, density( n1.x ) );       // Big sky noise. vec3 n11 = noise( cloudsZoom * mWorldPos, mTime, vec2( 0.2, 0.1 ) );   #endif        noLight = vec4( 1.0 - exp( -1.5 * ( fMiePhase * mSeced ) ), 1.0 );       // Add cloud layer to final color out. #ifdef USE_CLOUDS vec4 dayLightColor = fRayleighPhase * ( vec4(n11, 1.0) + mix( clouda, cloudColor2, density ( n2.x ) ) ) * vec4(mFronColor, 1.0); vec4 nightLightColor =  fRayleighPhase * ( vec4(n11, 1.0) + mix( clouda, cloudColor2, density ( n2.x ) ) ) * vec4(0.2, 0.45, 0.9, 1.0);         mColor = mix( dayLightColor, nightLightColor, mNightPerc );// vec4(1.0 - exp(-1.5 * (fRayleighPhase * mBlued + fMiePhase * mSeced + n1)), 1.0); #else mColor = vec4( 1.0 - exp(-1.5 * (fRayleighPhase * mBlued + fMiePhase * mSeced )), 1.0 ); #endif }   #endif I tried to change precision, but still nothing. What it can be? Thanks in advance!
  12. NekoCode

    Adding colors in GLSL problem

    Eh, solved by recalculating normals in post process sampling. Stoooopid, but results are great!
  13. NekoCode

    Adding colors in GLSL problem

      It's not that important, it looks the same everywhere. But I think I found a problem, but I don't know how to fix it. i.e. I have "postprocessColor" variable in glsl and it has any effect inside which samples 10-20 times ( texture += texture+something ). So when I add "postprocessColor" to anything else it "overlaps" just because it has a lot of samples in it. I need any other alternative to "add" which doesn't add, but blends with no color lost.   EDIT: I found a good formula, it works good, but there are still not full blur as it must to be. float fInterpValue = 0.5; vec4 finalcol =  ( 1.0 - fInterpValue )* dlight_color + fInterpValue * ppcol;
  14. Hello everyone. I faced one problem - mixing two colors giving me wrong results. Let me explain: 1) I have Deferred lighting code and it gives good results, I called it "defLight" in GLSL. 2) I have Post-processing things in same code, I got Depth of Field here. 3) When doing the following thing: vec4 finalColor = defLight + postProcess; gives me wrong result, I can't see lighting at all, just diffuse light.  Is there another way to add colors to one variable so they won't mix?    Here are screenshots,   With lighting and no PP   With Post processing and Lighting:   Also, postprocessing after adding looks ugly ( look at blur in second pic ).   Thanks in advance!
  15. Hey everyone, I am trying to implement OpenGL 2.1 and lower versions context support.  When creating empty context it returns me actual version which is 4.1.. what if I want 2.1 and lower? And as I know, wglCreateContextAttribs can't apply 2.1 version as parameter ( only higher... and yep, it doesn't work with 2.1 or 2.0 ).   My current card is Intel HD 4000, it supports 1.2, 2.0, 3.X, 4.X. Code is extremly simple - choose pixel format, set pixel format, do wglCreateContext(hdc) and wglMakeCurrent what returns me as I said, 4.0 or higher.   Thanks in advance!
  • 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!