Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


blubberbert

Member Since 03 Apr 2009
Offline Last Active Jun 11 2014 09:51 AM

Topics I've Started

C++ template default parameter with enable_if

21 November 2013 - 09:17 PM

my question is simple (i think)

 

consider this

class Base { ... };
 
class A {
public:
  template <class T = std::enable_if<std::is_base_of<Base, T>::value>::type>
  void Test1() { }

  template <class T, T = std::enable_if<std::is_base_of<Base, T>::value>::type>
  void Test2() { }

};
 
a.Test1<int>(); //compiles
a.Test2<int>(); //doesn't compile

why does the Test1 call compile when it shouldnt, because int isnt derived from Base

ive already found the correct syntax (wich seems to be the one of Test2)

but i dont get why the enable_if doesnt create an error in Test1

 

by the way im using Visual Studio


expected template ambiguity

22 May 2013 - 05:42 PM

i expected the following code to raise an error because the compiler doesnt know wich func to use, the template or non-template one
#include <string>
#include <iostream>
#include <cstdlib>
 
template<typename T>
T func(T arg) { return arg; }
 
std::string func(std::string arg) { return "surprise!"; }
 
 
int main(int argc, char **argv) {
    std::cout << func(std::string("no surprise please!") );
    system("PAUSE");
    return 0;
}
however the code always calls the non-template function. 
1.Why is that?
2.If that kind of behaviour is part of the standard (calling non-template functions rather than fitting templates), whats the point of the special syntax for template specialization?
i.e.
template<>
std::string func<std::string>(std::string arg) { return "surprise!"; }

Overlapping textures in deferred renderer

22 January 2012 - 07:52 AM

im currently working on a deferred renderer with SSGI and came across a problem:

iam doing 4 passes to render the final image, but i want to reuse one Gbuffer wich is written in the 1st and read in the 2nd pass to be written in the 3rd and read in the 4th pass
that rendertarget stores the indirect illumination color and the ao.
however since my good old ATI 4650M isnt that fast, i compute the SSGI on a 4 times smaller resolution.
so after the third pass, some of the rendertarget holds the new SSGI data, while some part still stores the data written in the 1st pass wich is not needed anymore.

it would look like this:
OOOO
OOOO
NNOO
NNOO
where O is old data and N new data

the problem is that now when i read the SSGI data (N) in the 4th pass, i get some artifacts when i read data from the right or top border, because im actually reading 'O' data, wich is not what i want...

the shader for the fourth pass looks like this:

uniform sampler2D ssdiMap;
uniform sampler2D ssgiMap;
varying vec2 texCoord0;
varying vec2 texCoord1;

vec4 getGI(in vec2 coord)
{
    coord = clamp(coord, 0.0, 0.25);
    return texture2D(ssgiMap, coord);
}

void main()
{
    float rad = 0.0005;
    vec2 offsets[8] = vec2[8](vec2(rad,rad),vec2(-rad,rad),vec2(-rad,-rad),vec2(rad,-rad),
    vec2(0.0,rad),vec2(0.0,-rad),vec2(rad,0.0),vec2(-rad,0.0));
    vec4 gi = vec4(0.0);
    for(int i = 0; i < 8; i++)
        gi += getGI(texCoord1 + offsets[i]);
    for(int i = 0; i < 8; i++)
        gi += getGI(texCoord1 + offsets[i] * 2.0);
    gi /= 16.0;
    vec4 di = texture2D(ssdiMap, texCoord0);
    vec3 final = (di.xyz*gi.w) + gi.xyz; //gi.xyz is GI color, gi.w is AO
    gl_FragColor = vec4(final, 1.0);
}

experminental shader extensions

15 September 2011 - 11:00 AM

i wanna try the GL_EXT_shader_image_load_store extension, but my graphics card only supports
OpenGL 3.3 (Ati mobility 4650)

the extension is not in the extension string and glew doesnt load it normally but when i set glewExperimental to true, it says GL_EXT_shader_image_load_store is supported.
the functions also do have a valid entry point.

unfortunately that wasnt true for the shader since
#extension GL_EXT_shader_image_load_store : enable
didnt compile Posted Image

long story short, does anyone know how to enable experimental driver functionality for shaders?

Geometry shaders & render to 3D texture

29 August 2011 - 11:56 AM

recently i asked on the forums on how to render to 3D textures
i ended up with binding each texture layer in each frame and then rendering to it wich is a solution, but quite slow

i now tried to go with geometry shaders and got the rendering working, however only half of the texture is filled
gDebugger shows that layer 63 is black, while layer 64 is filled normally (on a 128*128*128 texture)

here is my geometry shader

layout (points) in;
layout (triangle_strip, max_vertices = 512) out;

void main()
{
	float f = 2.0 / 128.0;
	for(int i = 0; i < 128; i++)
	{
		float lz = (f * float(i)) - 2.0;
		gl_Position = vec4(-1.0,-1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4( 1.0,-1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4(-1.0, 1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4( 1.0, 1.0,lz,1.0); gl_Layer = i; EmitVertex();
		EndPrimitive();
	}
}
the fragment shader that is used to fill each of the layers

void main()
{
        vec3 coord = gl_FragCoord.xyz;
	//coordinates reach from 0.5 to 128.5
	coord.xy -= 0.5;
	coord.xy /= 128.0;
	coord.xy -= 0.5;
	gl_FragData[0] = vec4(coord,1.0);
}
and the code that fills the volume

void fillTarget()
{
	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
	glPushAttrib(GL_VIEWPORT_BIT);
	glViewport(0,0,volRes,volRes);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, volumetex->getId(), 0);
	glClearColor(0.0f,0.0f,0.0f,1.0f); //making this red shows that the layers still stay empty
	glClear(GL_COLOR_BUFFER_BIT);
	program->bind();
	glBegin(GL_POINTS);
	glVertex3f(0.0f,0.0f,0.0f);
	glEnd();
	Program::unbind();
	glPopAttrib();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

PARTNERS