Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 22 Jun 2012
Offline Last Active Today, 10:28 AM

Topics I've Started

[SOLVED] [GLSL] Weird behavior with interface blocks.

03 February 2015 - 05:36 PM

Hello friends!

I have a strange behaviour with my glsl code..

I am trying to pass a simple 'uint' variable between stages (from vertex shader to fragment shader), but it seems like I'm doing something wrong.

I have an interface block like this:

// Vertex Shader
out InterfBlock {
	vec4 WorldPos;
	vec3 WorldNormal;
	vec2 TexCoord[2];
	vec3 CamDir;
 	uint DrawID;
} OUT;	

//Fragment Shader
in InterfBlock {
	vec4 WorldPos;
	vec3 WorldNormal;
	vec2 TexCoord[2];
	vec3 CamDir;
	uint DrawID; // This line is the problem, works if I remove.
} IN;

When I run my program, it simply generates no error.
(There is an error checker already that uses glGetShaderInfoLog() and works when I simply forget to put a semicolon, so I know it works,)

But also my GpuProgram class gives me the number of Uniforms in my shaders. But it says 0 (zero). (But there are a few uniforms)

The strange thing is, the shader works perfectly when I simply remove the "uint DrawID;" from FRAGMENT SHADER.. (Also shows the correct amount of Uniforms if I remove).

It doesn't matter if I keep it in Vertex Shader, it works. But when I add the line "uint DrawID;" in interface block of frag shader, It stops working.
Any ideas?


NVIDIA Driver Version: 331.113
OS: Linux-x86_64

OpenGL version from glxinfo: 3.3.0 NVIDIA 331.113

glMultiDrawElements with Transformation matrices

16 August 2014 - 04:14 PM

Hello guys,
I have a problem with using glMultiDrawElements;

In a typical drawing, I would do something like this: (Pseudo-code)


foreach obj in objects {






As you can see, I can set Model Matrices of every model.
But with glMultiDrawElements, How can I achive something like this? How can I give a different matrix for every object?
Is there a shader counter for draw calls? (So I can grab their matrices from something like a uniform.)

If yes. How will this counter increased if some of the calls are instanced when I use glMultiDrawElementsIndirect()?

Vertex Buffers in OpenGL

19 January 2013 - 05:26 PM

Actually, It's not an OpenGL question.

This is how I draw things in OpenGL:

glEnableClientState (GL_VERTEX_ARRAY);	
glEnableClientState (GL_NORMAL_ARRAY);	
glEnableClientState (GL_TEXTURE_COORD_ARRAY);		
glVertexPointer(3, GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].vertex);	
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].texCoord);	
glNormalPointer(GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].normal);			
glDrawElements (GL_TRIANGLES, obj->indicesCount, GL_UNSIGNED_INT, obj->indices);					glDisableClientState (GL_VERTEX_ARRAY);	
glDisableClientState (GL_NORMAL_ARRAY);	
glDisableClientState (GL_TEXTURE_COORD_ARRAY);

As you see here, I don't use any memcpy..

And this is how I have to draw in DirectX: (Pseudo)

vertex_buffer->Lock(0, 0, (void**)&ptr, 0);
memcpy((void*)ptr, (void*)vetices_of_quad, sizeof(vetices_of_quad));

As you see here, I have to use a "memcpy" each frame.. Why each frame, because I can't keep my LPDIRECT3DVERTEXBUFFER9 object..

I just want to hold my vertex data in my own vertex buffer class (VertexBuffer), and be able to use it in both OpenGL and DirectX, without copying the data each frame..

I don't know DirectX much.. I'm a newbie.
Please help sad.png

(BTW, sorry for my bad English)

UDP Clients

07 December 2012 - 05:45 PM

First of all sorry for my bad English..

I have a question about UDP sockets..

I have used TCP lots of times, and when I need to create a multi-client server, I create a Client class, and call a Receive function which calls "recv" using its socket number.. So I can easily read data that related to this client from socket..

But now, I want to use UDP..
in UDP, there is no socket numbers as in TCP.. I use recvfrom and it gives me a address.. How can I bind an address to a Client (a pointer)..
When a data received, how can I know whose data is this?

Do I have to create a table like hashtable? Or is there any methods that commonly used to handle hundreds of client ?

Ortho Shadow Problem.

22 June 2012 - 11:11 AM

"Sorry for my bad English..."

I made a shadow shader for my project.
When I use Perspective projection when rendering Depth buffer(Shadow map), there is no problem..
But when I simply switch to the Ortho Projection, every fragment become black. (I mean under shadow..)

I didn't understand why.

Here is the screenshots: (Sorry for the textures :D )
With Perspective:
gluPerspective(60.0f,  (float)(displayWidth) / (float)(displayHeight), 1.0f, 1000.0f);
gluLookAt(position_x, position_y, position_z, lookAt_x, lookAt_y, lookAt_z, 0.0, 1.0, 0.0);
Posted Image

But with Orthographic mode:
(Also a debug window at right top corner that shows depth texture.)

glOrtho(-10, 10,-10, 10, -1.0, 100.0f);
gluLookAt(position_x, position_y, position_z, lookAt_x, lookAt_y, lookAt_z, 0.0, 1.0, 0.0);

Posted Image

Also my shaders:

uniform sampler2DShadow ShadowMap;
uniform sampler2D textureSampler;

uniform vec4 LightColor;

varying vec4 ShadowCoord;
varying vec2 TexCoord0;
varying vec3 WorldNormal;
varying vec3 LightDir;

float xPixelOffset = 1.0 / (1366.0 * 1.0);
float yPixelOffset = 1.0 / (768.0 * 1.0);

float lookup(vec2 offSet)
return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.005, 0.0) ).w;

void main()
vec3 FinalDiffuse = vec3(0.0, 0.0, 0.0);
vec3 AmbientLight = vec3(0.0, 0.1, 0.1);
vec4 TexColor = vec4(texture2D(textureSampler, TexCoord0));
float shadow;
float attenuation;

float LenSq = length(LightDir);
vec3 N = normalize(WorldNormal);
vec3 L = normalize(LightDir);

float lambertTerm = max(dot(N, L), 0.0);
attenuation = min((LightColor.w * LightColor.w) / (LenSq * LenSq), 1.0);
FinalDiffuse += LightColor * lambertTerm;// * attenuation;

if (ShadowCoord.w > 1.0)
float x,y;
for (y = -1.5 ; y <=1.5 ; y+=1.0)
for (x = -1.5 ; x <=1.5 ; x+=1.0)
shadow += lookup(vec2(x,y));

shadow /= 16.0 ;

FinalDiffuse *= shadow;

vec4 outColor = vec4(vec3(TexColor.xyz * (FinalDiffuse + AmbientLight.xyz)) , TexColor.a);
gl_FragColor = outColor;

And Vertex Shader:
varying vec3 WorldNormal;
varying vec4 ShadowCoord;
varying vec2 TexCoord0;
varying vec3 LightDir;
uniform vec4 LightPosition;
void main()
ShadowCoord = gl_TextureMatrix[7] * gl_Vertex;
gl_Position = ftransform();//gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 WorldPos = gl_ModelViewMatrix * gl_Vertex;
WorldNormal = gl_NormalMatrix * gl_Normal;
LightDir = vec3(LightPosition - WorldPos);
TexCoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
gl_FrontColor = gl_Color;

Any ideas?? Posted Image
Or need more info?? Posted Image