Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Mar 2009
Offline Last Active Nov 21 2015 08:31 PM

#5237330 Any other way to draw shadows ?

Posted by CaptainMurphy on 28 June 2015 - 03:18 PM

Looks like a cut down version of stencil shadow volumes. Where it draws the shadows quads to the stencil buffer, and then the lit things are drawn except for the pixels marked by the stencil buffer. Pretty neat idea, looks like it would work for any N sided polygon.


You can't do it in a vertex shader since you can only access one vertex at a time, where as that algorithm needs access to two. Also I think vertex shaders can spit out only one vertex at a time, where that spits out 4. If you had geometry shaders you could do it there but that's opengl 3.3+.



Actually you could pass more than one vertex to the shader by doing something like

for verts in quad or triangle {




But I don't know if you are able to emit more than 1 vertex from the shader. If you could, it might be possible...




Actually I just realised another idea, where you send a quad for each edge,


for each edge {




  glVertex3f(cur.x,cur.y,0);//0 represents the vertex on the edge to not extrude



  glVertex3f(next.x,next.y,0); //0 represents the vertex on the edge to not extrude



  glVertex3f(cur.x,cur.y,1); //1 represents the extruded vertex



  glVertex3f(next.x,next.y,1);//1 represents the extruded vertex




Basically in the vertex shader you:

1. redundently do the dot product check to see if a shadow should be extruded. Pass a varying float to there fragment shader, where if shadow pass 1, else pass 0

2. If the vertex.z ==1, extrude the vertex along the light direction.


Fragment shader:

1. Check the varying float passed from the vertex shader, if == 0 then call discard to abort drawing the shadow


Kind of convoluted, but it should/could work.

#5173967 Font Rendering

Posted by CaptainMurphy on 15 August 2014 - 01:38 PM

This library really needs some kind of docs or at least example code, I wasn't able to figure it out.

#5165979 Calculate if angle between two triangles connected by edge

Posted by CaptainMurphy on 10 July 2014 - 03:28 AM

Okay, after Álvaro's question I realised I was confusing the problem. for two triangles sharing an edge I want to find out whether they are facing away from each other, facing towards each other or laying flat (same normal).


So a slight change from  C0lumbo's method, I dot product the normal from the first triangle to the non shared edge of the second triangle, where dotproduct=0 is both triangles laying flat, dotproduct<0 facing away (convex), dotproduct>0 facing towards (concave).


Seems like it should work.

#5000703 Ideas for Lua integration in a game engine.

Posted by CaptainMurphy on 13 November 2012 - 05:01 PM

I'm not sure what LuaJIT is,

Well one thing you can do is use c code from within it.

I've just started looking at LuaJIT recently, and an idea I had apart from scripting world objects, was to use it to setup all the monotonous code, such geometry data (eg vertexarrayobjects, vertex buffers, attribute bindings, index buffers etc), shader programs, textures, texture samplers etc. Using luajit ffi to minimise the amount of cbindings necessary.

And then in your main program, load those 'resource files' into a table and just say:
GLuint program = *((GLuint*)lua_touserdata(L,-1));


A resource file might look like:
prog = CreateShaderProgram {
	  attribute vec3 a_pos;
	  void main() {

	  void main() {
   {"attrib", "a_pos", 0}}

vao = CreateVertexArrayObject {

#4952251 Please simplify my code.

Posted by CaptainMurphy on 24 June 2012 - 12:58 AM

but C++ does not run on a virtual machine like Java does.

That does not have anything to do with why c++ doesn't have an "Application" class for the main.

riverreal is correct in that c++ is a multi paradigm language, which means you use oop where it helps, and procedural or functional (limited) programming etc where they help.

And I don't think having an "Application" class helps at all, making a class to be instantiated once (except for cases of inheritance) seems like a wasted effort.

#4895176 Functional languages in gamedev

Posted by CaptainMurphy on 18 December 2011 - 09:51 PM

Well I'm using racket scheme to make small demos, though not a game. The advantages for are that it's functional, and has all the advantages that come with that (Of which I'm never going back to an imperative language for personal use). You can mix imperative code with functional, which is necessary for doing inputs and outputs, e.g. drawing graphics, loading files, keyboard input etc.

Also it has macros which allow you do add extensions to the language, e.g. I used this to make a system for loading and setting shaders.

(define (some-effect)
 	(attribute "a_pos" 0)
 	(attribute "a_nor" 1)

 	(uniform "a" 0.0 0.3 0.0)
 	(uniform "b" 0.9)

 	(vertex "
   	#version 150
   	attribute vec3 a_pos, a_nor;
   	uniform mat4 u_modelViewProjMat;
   	varying vec3 c;

   	void main() {
       	gl_Position = u_modelViewProjMat * vec4(a_pos,1.0);
		c = abs(normalize(a_nor));

 	(fragment "
   	#version 150
   	varying vec3 c;
   	uniform float b[2];
   	uniform vec3 a;

   	void main() {
       	gl_FragColor = vec4(c+a+vec3(0.0,b[1],b[0]),1.0);

The disadvantages are that you have to write interfaces to c shared libraries to do anything useful, e.g. latest version of opengl, physics, sound, window etc. Though some of the other lisps might have bindings for those things already (I know common lisp does, but I prefer scheme).

I'm currently in the process of writing a library that auto generates bindings from c header files (nearly complete), it uses macros so that you just make a module and call a macro from my library which when compiled will auto generate the bindings for you.

I have a feeling writing a physics engine in it wouldn't be as fast as one written in c/c++, but for a game, if all the intensive code is imported from c bindings leaving the the rest in scheme, it should be fine.