• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By racarate
      Hey everybody!
      I am trying to replicate all these cool on-screen debug visuals I see in all the SIGGRAPH and GDC talks, but I really don't know where to start.  The only resource I know of is almost 16 years old:
      http://number-none.com/product/Interactive Profiling, Part 1/index.html
      Does anybody have a more up-to-date reference?  Do people use minimal UI libraries like Dear ImgGui?  Also, If I am profiling OpenGL ES 3.0 (which doesn't have timer queries) is there really anything I can do to measure performance GPU-wise?  Or should I just chart CPU-side frame time?  I feel like this is something people re-invent for every game there has gotta be a tutorial out there... right?
       
       
    • By Achivai
      Hey, I am semi-new to 3d-programming and I've hit a snag. I have one object, let's call it Object A. This object has a long int array of 3d xyz-positions stored in it's vbo as an instanced attribute. I am using these numbers to instance object A a couple of thousand times. So far so good. 
      Now I've hit a point where I want to remove one of these instances of object A while the game is running, but I'm not quite sure how to go about it. At first my thought was to update the instanced attribute of Object A and change the positions to some dummy number that I could catch in the vertex shader and then decide there whether to draw the instance of Object A or not, but I think that would be expensive to do while the game is running, considering that it might have to be done several times every frame in some cases. 
      I'm not sure how to proceed, anyone have any tips?
    • By fleissi
      Hey guys!

      I'm new here and I recently started developing my own rendering engine. It's open source, based on OpenGL/DirectX and C++.
      The full source code is hosted on github:
      https://github.com/fleissna/flyEngine

      I would appreciate if people with experience in game development / engine desgin could take a look at my source code. I'm looking for honest, constructive criticism on how to improve the engine.
      I'm currently writing my master's thesis in computer science and in the recent year I've gone through all the basics about graphics programming, learned DirectX and OpenGL, read some articles on Nvidia GPU Gems, read books and integrated some of this stuff step by step into the engine.

      I know about the basics, but I feel like there is some missing link that I didn't get yet to merge all those little pieces together.

      Features I have so far:
      - Dynamic shader generation based on material properties
      - Dynamic sorting of meshes to be renderd based on shader and material
      - Rendering large amounts of static meshes
      - Hierarchical culling (detail + view frustum)
      - Limited support for dynamic (i.e. moving) meshes
      - Normal, Parallax and Relief Mapping implementations
      - Wind animations based on vertex displacement
      - A very basic integration of the Bullet physics engine
      - Procedural Grass generation
      - Some post processing effects (Depth of Field, Light Volumes, Screen Space Reflections, God Rays)
      - Caching mechanisms for textures, shaders, materials and meshes

      Features I would like to have:
      - Global illumination methods
      - Scalable physics
      - Occlusion culling
      - A nice procedural terrain generator
      - Scripting
      - Level Editing
      - Sound system
      - Optimization techniques

      Books I have so far:
      - Real-Time Rendering Third Edition
      - 3D Game Programming with DirectX 11
      - Vulkan Cookbook (not started yet)

      I hope you guys can take a look at my source code and if you're really motivated, feel free to contribute :-)
      There are some videos on youtube that demonstrate some of the features:
      Procedural grass on the GPU
      Procedural Terrain Engine
      Quadtree detail and view frustum culling

      The long term goal is to turn this into a commercial game engine. I'm aware that this is a very ambitious goal, but I'm sure it's possible if you work hard for it.

      Bye,

      Phil
    • By tj8146
      I have attached my project in a .zip file if you wish to run it for yourself.
      I am making a simple 2d top-down game and I am trying to run my code to see if my window creation is working and to see if my timer is also working with it. Every time I run it though I get errors. And when I fix those errors, more come, then the same errors keep appearing. I end up just going round in circles.  Is there anyone who could help with this? 
       
      Errors when I build my code:
      1>Renderer.cpp 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2039: 'string': is not a member of 'std' 1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stddef.h(18): note: see declaration of 'std' 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2061: syntax error: identifier 'string' 1>c:\users\documents\opengl\game\game\renderer.cpp(28): error C2511: 'bool Game::Rendering::initialize(int,int,bool,std::string)': overloaded member function not found in 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.h(9): note: see declaration of 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.cpp(35): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(36): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(43): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>Done building project "Game.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
       
      Renderer.cpp
      #include <GL/glew.h> #include <GLFW/glfw3.h> #include "Renderer.h" #include "Timer.h" #include <iostream> namespace Game { GLFWwindow* window; /* Initialize the library */ Rendering::Rendering() { mClock = new Clock; } Rendering::~Rendering() { shutdown(); } bool Rendering::initialize(uint width, uint height, bool fullscreen, std::string window_title) { if (!glfwInit()) { return -1; } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); glViewport(0, 0, (GLsizei)width, (GLsizei)height); glOrtho(0, (GLsizei)width, (GLsizei)height, 0, 1, -1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glfwSwapInterval(1); glEnable(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); glLoadIdentity(); return true; } bool Rendering::render() { /* Loop until the user closes the window */ if (!glfwWindowShouldClose(window)) return false; /* Render here */ mClock->reset(); glfwPollEvents(); if (mClock->step()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glfwSwapBuffers(window); mClock->update(); } return true; } void Rendering::shutdown() { glfwDestroyWindow(window); glfwTerminate(); } GLFWwindow* Rendering::getCurrentWindow() { return window; } } Renderer.h
      #pragma once namespace Game { class Clock; class Rendering { public: Rendering(); ~Rendering(); bool initialize(uint width, uint height, bool fullscreen, std::string window_title = "Rendering window"); void shutdown(); bool render(); GLFWwindow* getCurrentWindow(); private: GLFWwindow * window; Clock* mClock; }; } Timer.cpp
      #include <GL/glew.h> #include <GLFW/glfw3.h> #include <time.h> #include "Timer.h" namespace Game { Clock::Clock() : mTicksPerSecond(50), mSkipTics(1000 / mTicksPerSecond), mMaxFrameSkip(10), mLoops(0) { mLastTick = tick(); } Clock::~Clock() { } bool Clock::step() { if (tick() > mLastTick && mLoops < mMaxFrameSkip) return true; return false; } void Clock::reset() { mLoops = 0; } void Clock::update() { mLastTick += mSkipTics; mLoops++; } clock_t Clock::tick() { return clock(); } } TImer.h
      #pragma once #include "Common.h" namespace Game { class Clock { public: Clock(); ~Clock(); void update(); bool step(); void reset(); clock_t tick(); private: uint mTicksPerSecond; ufloat mSkipTics; uint mMaxFrameSkip; uint mLoops; uint mLastTick; }; } Common.h
      #pragma once #include <cstdio> #include <cstdlib> #include <ctime> #include <cstring> #include <cmath> #include <iostream> namespace Game { typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef float ufloat; }  
      Game.zip
    • By lxjk
      Hi guys,
      There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
      Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
      On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
      This method can be naturally extended to clustered light culling as well.
      The following image shows the general ideas

       
      Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test
       

       
      I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!
       
      Eric
  • Advertisement
  • Advertisement
Sign in to follow this  

OpenGL Stencil Shadows

This topic is 883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, got a two part question for you all.

 

First off, i'm a bit confused as to how to implement stencil shadows. I did a quick google and a lot of resources come up on different techniques, some are just high level descriptions others are specific code examples.

 

I'm looking for something in the middle, like a "theory AND implementation" style tutorial / article / book. Any suggestions? I'm really looking for resources that use legacy (Non-Shader) OpenGL.

 

Second, seems like a lot of tutorials focus on issues with the near clipping plane being inside the shadow volume. Other articles mention "Carmacks reverse" as the solution, but warn that it is patented. How did they work around this patent issue in the open source release of Doom 3?

Share this post


Link to post
Share on other sites
Advertisement

Other articles mention "Carmacks reverse" as the solution, but warn that it is patented. How did they work around this patent issue in the open source release of Doom 3?

Carmack's reverse is the solution smile.png

You could check out the Doom 3 source code - I hear they modified it to remove the patented algorithm before releasing the source code.

@ID_AA_Carmack: Lawyers are still skittish about the patent issue around "Carmack's reverse", so I am going to write some new code for the doom3 release.
This demonstrates the idiocy of the patent -- the workaround added four lines of code and changed two.

 

I've personally used it in a game before. I read the actual patent and compared their claims against my implementation of the "Carmack's reverse" algorithm, and in my professional opinion, my method did not overlap with their claims. My lead agreed with me, so we shipped it smile.png So, IMHO, it's possible to implement the algorithm without using the patented method, but maybe I'm wrong, and maybe we opened our employer up to a lawsuit... Yay for patents.

 

However, stencil shadows are rarely used these days. Almost everyone uses shadow mapping methods instead - unless you specifically need pixel-perfect hard-edged shadows.

Share this post


Link to post
Share on other sites

most annoying thing in stencil shadows (for z fail) is that you need properly drawn shadow volumes (clockwise or counterclockwise - depending on implementation) they need to face all inside or all outside (as far as i remember)

 

 

anyway heres old code (was working last time i used it ;])

 

VBO_BE -> array of face info (provides length of each face, and index in VBO_V]

VBO_V array of vertices

//---------------------------------------------------------------------------

#ifndef STENCIL_SHADOW_TACHOGL_DRAWINGH
#define STENCIL_SHADOW_TACHOGL_DRAWINGH
//---------------------------------------------------------------------------
#include "DxcMath.h"
#include "DxcMatrix.h"
#include "OPENGL_ATTACH.h"
#include "SysUtils.hpp"
#include "Dialogs.hpp"
#include "Math.hpp"
#include "Math.h"
#include "gl/glew.h"
#include "gl/gl.h"
#include "TachoGLModelSRC.h"

struct ShadowFaceNFO
{
int index;
int len;
};

struct TStencilShadowEffect
{
//t3dpoint<double> VERT_ARR[12*4]; //for drawing // note that face vert count cant exceed 12

Matrix44<double> AMODEL;
Matrix44<double> AVIEW;
Matrix44<double> APROJ;
int 			 AVIEWP[4];



t3dpoint<double> * START_CAP_VBO;

t3dpoint<double> * CAP_CENTER;

t3dpoint<double> * END_CAP_VBO;

t3dpoint<double> * SIDE_CAP_VBO;



void CalcStartCaps(TachoGLModel<double> * model)
{
START_CAP_VBO = new t3dpoint<double> [ model->header.LENGTH ];
int i,j;
for (i=0; i < model->header.LENGTH; i++) START_CAP_VBO[i] = model->VBO_V[i];

}


void CalcEndCaps(TachoGLModel<double> * model, t3dpoint<double> lpos)
{
t3dpoint<double> LDIR;
END_CAP_VBO = new t3dpoint<double> [ model->header.LENGTH ];
int i,j;
for (i=0; i < model->header.LENGTH; i++)
{

LDIR = Normalize( model->VBO_V[i] - lpos );
END_CAP_VBO[i]  = model->VBO_V[i] + LDIR * infinity; 

}

}

void CalcCenterCap(TachoGLModel<double> * model)
{
CAP_CENTER = new t3dpoint<double> [ model->VBO_BE.Length ];

int i,j;         t3dpoint<double> center;
for (i=0; i < model->VBO_BE.Length; i++)
{
center = t3dpoint<double>(0.0,0.0,0.0);
for (j=0; j < model->VBO_BE[i].length; j++)
{
center = center + START_CAP_VBO[	model->VBO_BE[i].INDEX_START	+	j	];
center = center + END_CAP_VBO[		model->VBO_BE[i].INDEX_START	+	j	];
}


CAP_CENTER[i] = center / double( model->VBO_BE[i].length * 2.0 );
}
}


void CalcSideCaps(TachoGLModel<double> * model)
{
int cnt = 0;

int i,j,x,index;

for (i=0; i < model->VBO_BE.Length; i++)
for (j=0; j < model->VBO_BE[i].length; j++)
cnt = cnt + 4;

int mmax = cnt;
SIDE_CAP_VBO = new t3dpoint<double> [cnt];

t3dpoint<double> tmp;
t3dpoint<double> tmp2;
//now calculate side caps

cnt = -1;
for (i=0; i < model->VBO_BE.Length; i++)
{
if (i == model->VBO_BE.Length-10)
{
 int super = 3;
}
index = model->VBO_BE[i].INDEX_START;

for (x=0; x < model->VBO_BE[i].length; x++)
{
cnt = cnt + 1;
if (cnt > mmax-1) cnt = mmax - 1;
SIDE_CAP_VBO[cnt] = END_CAP_VBO[index + x]; //50 km away


cnt = cnt + 1;
if (cnt > mmax-1) cnt = mmax - 1;
SIDE_CAP_VBO[cnt] = START_CAP_VBO[index + x];

if (x != model->VBO_BE[i].length - 1)
{
tmp  = START_CAP_VBO[	index + x + 1];
tmp2 = END_CAP_VBO[		index + x + 1];
} else
{
tmp  = START_CAP_VBO[index];
tmp2 = END_CAP_VBO[index];
}

cnt = cnt + 1;
if (cnt > mmax-1) cnt = mmax - 1;
SIDE_CAP_VBO[cnt] = tmp;


cnt = cnt + 1;
if (cnt > mmax-1) cnt = mmax - 1;
SIDE_CAP_VBO[cnt] = tmp2;

}



}




}



void FaceAllCapsOutside(TachoGLModel<double> * model)
{
t3dpoint<double> TMP_BUFF[55]; //each poly can have maximum of 22 verts (its likely it will never exceed that much)



int i,x, index, j,cnt;
t3dpoint<double> V1, V2, V3, NORMAL;
double D;


//first we check start caps,


for (i=0; i < model->VBO_BE.Length; i++)
{
index = model->VBO_BE[i].INDEX_START;
V1 = START_CAP_VBO[index];
V2 = START_CAP_VBO[index+1];
V3 = START_CAP_VBO[index+2];

NORMAL = Normal(V1, V2, V3, true);

D = getplaneD(NORMAL, V1);

//====================================CHECK IF WE NEED TO SWAP FACE==============================
if ( classifyapointagainstaplane(CAP_CENTER[i], NORMAL, D) == isBack )
{
cnt = -1;
for (j=model->VBO_BE[i].length-1; j > -1; j--)
{
cnt = cnt + 1;
TMP_BUFF[cnt]  = START_CAP_VBO[ index + j ];
}
for (j=0; j < model->VBO_BE[i].length; j++)
START_CAP_VBO[ index + j ] 	= TMP_BUFF[j]; //actual swap


}
//====================================CHECK IF WE NEED TO SWAP FACE==============================


}

//end caps


for (i=0; i < model->VBO_BE.Length; i++)
{
index = model->VBO_BE[i].INDEX_START;
V1 = END_CAP_VBO[index];
V2 = END_CAP_VBO[index+1];
V3 = END_CAP_VBO[index+2];

NORMAL = Normal(V1, V2, V3, true);

D = getplaneD(NORMAL, V1);

//====================================CHECK IF WE NEED TO SWAP FACE==============================
if ( classifyapointagainstaplane(CAP_CENTER[i], NORMAL, D) == isBack )
{
cnt = -1;
for (j=model->VBO_BE[i].length-1; j > -1; j--)
{
cnt = cnt + 1;
TMP_BUFF[cnt]  = END_CAP_VBO[ index + j ];
}

for (j=0; j < model->VBO_BE[i].length; j++)
END_CAP_VBO[ index + j ] 	= TMP_BUFF[j]; //actual swap


}
//====================================CHECK IF WE NEED TO SWAP FACE==============================


}



//now check for sides


    int acnt;
cnt = 0;
for (i=0; i < model->VBO_BE.Length; i++)
{

for (x=0; x < model->VBO_BE[i].length; x++)
{

V1 = SIDE_CAP_VBO[cnt];

V2 = SIDE_CAP_VBO[cnt+1];

V3 = SIDE_CAP_VBO[cnt+2];


NORMAL = Normal(V1, V2, V3, true);

D = getplaneD(NORMAL, V1);

                                             //check side face
if ( classifyapointagainstaplane(CAP_CENTER[i], NORMAL, D) == isBack )
{
acnt = -1;
for (j=3; j > -1; j--)
{
acnt = acnt + 1;
TMP_BUFF[acnt]  = SIDE_CAP_VBO[ cnt + j ];
}

for (j=0; j < 4; j++)SIDE_CAP_VBO[ j + cnt ] 	= TMP_BUFF[j]; //actual swap



}

cnt = cnt + 4;               //move along to new face
}

}


}



void DrawStartCaps(TachoGLModel<double> * model)
{


glVertexPointer(3, 		GL_DOUBLE, 	sizeof(t3dpoint<double>), 	&START_CAP_VBO[0]	);
int i;


for (i=0; i < model->VBO_BE.Length; i++)
glDrawArrays(GL_TRIANGLE_FAN, model->VBO_BE[i].INDEX_START , model->VBO_BE[i].length);




}

void DrawEndCaps(TachoGLModel<double> * model)
{

glVertexPointer(3, 		GL_DOUBLE, 	sizeof(t3dpoint<double>), 	&END_CAP_VBO[0]	);
int i; 

for (i=0; i < model->VBO_BE.Length; i++)
glDrawArrays(GL_TRIANGLE_FAN, model->VBO_BE[i].INDEX_START , model->VBO_BE[i].length);

}





void DrawSideCaps(TachoGLModel<double> * model)
{
glVertexPointer(3, 		GL_DOUBLE, 	sizeof(t3dpoint<double>), 	&SIDE_CAP_VBO[0]	);
int i;  int x;           int cnt = 0;

for (i=0; i < model->VBO_BE.Length; i++)
for (x=0; x < model->VBO_BE[i].length; x++)
{
glDrawArrays(GL_TRIANGLE_FAN,  cnt , 4);
cnt = cnt + 4;
}




}

































void RenderShadows(TachoGLModel<double> * model)
{
bool specialDepth = glIsEnabled(GL_DEPTH_TEST);
if (!specialDepth) glEnable(GL_DEPTH_TEST);

glDisableClientState(GL_NORMAL_ARRAY_EXT);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable( GL_VERTEX_PROGRAM_ARB );
PICK_SHADER.Bind();
SetShaderMatrix(AMODEL, AVIEW, APROJ);
SendParamToShader(0.0,0.0,0.0, 1.0,  5);



glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
model->DrawSimpleModel(NULL);


glDepthMask(GL_FALSE);

 glFrontFace(GL_CW);
glEnable(GL_CULL_FACE);


glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
 glDepthFunc(GL_LESS); // We change the z-testing function to LESS, to avoid little bugs in shadow

 glStencilFunc(GL_ALWAYS, 0, 0); // We always draw whatever we have in the stencil buffer




	glCullFace(GL_FRONT);
	glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);


	DrawStartCaps(model); DrawEndCaps(model); DrawSideCaps(model);


	glCullFace(GL_BACK);
	glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);

	DrawStartCaps(model); DrawEndCaps(model); DrawSideCaps(model);


	 glDepthFunc(GL_LEQUAL);


		 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // We enable color buffer
		 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // Drawing will not affect the stencil buffer
		 glStencilFunc(GL_EQUAL,  0x0, 0xff); // And the most important thing, the stencil function. Drawing if equal to 0



SendParamToShader(1.0,1.0,1.0, 1.0,  5);

	model->DrawSimpleModel(NULL);
 	 glDepthMask(GL_TRUE);
		 glDisable(GL_CULL_FACE);
	glDisable(GL_STENCIL_TEST);


glDisable( GL_VERTEX_PROGRAM_ARB );
glEnableClientState(GL_NORMAL_ARRAY_EXT);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
          

};




#endif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement