Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
heeen
May 14, 2005

CAT NEVER STOPS

gra posted:

I'm working in DirectX/C++ just now. At the moment, I move things along the x and y axis and rotate them around the z axis - but I want to move the object "forward" along the heading it's been rotated to (I'm thinking asteroids - where the ship moves along the direction it's heading). Any idea/tutorials on how to do this?

If you display the ship rotated on screen, you probably have a matrix for that object. Take the rotation part of that matrix (the top left 3x3 part) and rotate the forward vector of the ship with it and push the ship in this direction.
The forward vector is the vector in model space that points from the origin of the model space to the nose of the space ship.
In most cases the model is aligned along the axes of the model space in which case your forward vector will be something like (0,1,0). So instead of multiplying the vector with the rotation matrix, you can use the respective column directly, in the above case that would be the middle column.

heeen fucked around with this message at 22:20 on Dec 2, 2007

Adbot
ADBOT LOVES YOU

heeen
May 14, 2005

CAT NEVER STOPS
OpenGL/GPU question:
Can I use different filtering for the same texture in the same Scene? does changing the filtering on a texture require a pipeline flush?
As I understand it filtering is done on the TMU, so when I change the filtering on the TMU, this would require all triangles currently in the pipeline for this TMU to be finished first before the new filtering can be applied to new triangles, right?

heeen
May 14, 2005

CAT NEVER STOPS

Pfhreak posted:

heat haze

Heat haze is a very simple effect, really. All you need is the current scene in a back buffer, which you perturbate either by using some sine/cosine or whatever function, or you get the distortion by overlaying some textures and using the resulting color as the distortion vector.
Additionally you can throw the distance into the mix, to modify the strength of the effect in the distance.
I implemented it as a post processing effect, rendering the whole scene into a buffer, then rendering one quad for the whole scene with the heat haze shader applied.

GLSL code follows:
code:
(...)
	//heat haze
	if (w_temperature > heatHazeLimit){
		strength = (w_temperature - heatHazeLimit) * 0.0002;
		distort = texture2D(heat, pos * 10.0 + vec2(time, -time)).rg * 2.0 - 1.0;
		distort += texture2D(heat, pos * 10.0 + vec2(-time, -time)).rg * 2.0 - 1.0;
		offset = distort * depthval * depthval * strength;
	} else {
		offset = vec2(0.0, 0.0);
	}

	col = texture2D(screen, pos + offset);
(...)
I suggest you check out the ATI Rendermonkey SDK, it contains many examples of shaders for you to play around with.

heeen
May 14, 2005

CAT NEVER STOPS
What's wrong with this shader?
Some vertices seem to move with the camera view.

code:
#version 120 
#extension GL_EXT_geometry_shader4 : enable
#extension GL_EXT_gpu_shader4 : enable
 
varying in vec3 norm[3];
 
void main() 
{ 
 
		gl_Position=gl_PositionIn[0];
		gl_Position.xyz+=norm[0];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		gl_Position=gl_PositionIn[1];
		gl_Position.xyz+=norm[1];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		gl_Position=gl_PositionIn[2];
		gl_Position.xyz+=norm[2];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		EndPrimitive();
 
 
}

heeen
May 14, 2005

CAT NEVER STOPS

HB posted:

I'm not really familiar with GLSL, but I have a hunch it's reacting badly to in-place editing of inputs. What happens if you copy gl_Position to a temp before messing with it?

Came here to post that this worked.

heeen
May 14, 2005

CAT NEVER STOPS

TSDK posted:

Is it actually chewing 100% of your CPU, or is it just being reported as using 100% of CPU by Task Manager.

Try doing a few other things whilst the app is running. If other apps run okay whilst yours is going, then the problem is just with the way Task Manager reports usage and not the app itself.

Our old PC engine used to do exactly that - it would 'expand' to claim all unused CPU in the Task Manager display, but it would back off whenever other stuff was going on, down to the actual usage level.

Your engine actually used 100% cpu, its just the premptive scheduler dividing the cpu up on all tasks when you start another one.
A task that uses 100% cpu AND is lagging the rest of the system has usually trouble with side effects like swapping to the hard drive or some driver issue.

edit: I just remembered: Mr. Dog are you running debug or release builds? debug can easily chew 90% more cpu than release. My little opengl project runs at around 100fps in debug and 1200fps in release which leads to 60% cpu ves 5% cpu when clamped to 60fps.

heeen fucked around with this message at 13:20 on Apr 14, 2008

heeen
May 14, 2005

CAT NEVER STOPS
What is the correct way to compute a depth buffer value from world position, because this gives my slightly wrong values:
code:
	vec4 transformedpos=gl_ModelViewProjectionMatrix*vec4(actualpos,1);
	gl_FragDepth=(transformedpos.z/transformedpos.w-gl_DepthRange.near)/gl_DepthRange.diff;

heeen
May 14, 2005

CAT NEVER STOPS
Ok, the calculation seems to be correct, yet it seems to be z-culled away, any ideas?
I'm raycasting triangles into triangles that lie in front of the former, if that makes sense.
Here is what it looked like with my (apparently wrong) depth calculation. You can see the pool bleed into the border.


edit:
code:
	vec4 transformedpos=gl_ModelViewMatrix*vec4(actualpos,1);
	float near=1.0;
	float far=2048.0;
	float depthcalc=(far / (far - near) + ((far * near / (near - far)) / transformedpos.z));
	gl_FragDepth =  depthcalc;

heeen
May 14, 2005

CAT NEVER STOPS

StickGuy posted:

Enjoy.
Thanks for your effort, but it doesn't work :shobon:

code:

	vec4 transformedpos=gl_ModelViewMatrix*vec4(actualpos,1);
	float devicez = transformedpos.z / transformedpos.w;
// #1	gl_FragDepth = ((gl_DepthRange.far - gl_DepthRange.near) / 2) * devicez + (gl_DepthRange.near + gl_DepthRange.far) / 2;
// #2	gl_FragDepth =  0.5 * devicez + 0.5;

neither of these work :(

edit
alright, I think I found the error in your quote, did you mean to write gl_ModelViewProjectionMatrix? because it seems to work :)


Edit: http://heeen.de/proj/refract.avi :c00l: http://www.youtube.com/watch?v=hqLobCH8PFo

heeen fucked around with this message at 23:48 on Apr 23, 2008

heeen
May 14, 2005

CAT NEVER STOPS
For my project I need a stencil buffer-only write pass, which is the most efficient way to disable writing to the color buffer, glColormask, glBlendfunc or glDrawbuffer?

heeen
May 14, 2005

CAT NEVER STOPS
I'm trying to use glClipPlane here, but no matter what values I send, it doesn't clip anything. If I try a positive and a negative halfspace surely some clipping should be noticable?

heeen
May 14, 2005

CAT NEVER STOPS

HB posted:

glEnable(GL_CLIP_PLANE0);

Also remember that clip planes use eye coordinates.

I have it enabled alright, to no effect. If I try 0,0,1,0 and 0,0,-1,0 or 0,1,0,0 and 0,-1,0,0 as parameters at least one of them should clip something, right?

heeen
May 14, 2005

CAT NEVER STOPS
edit: wrong quote
you have to use additive blending (gl_one, gl_one) if each light pass already contains the diffuse color of the tiles, or you can first render all lights and multiply it with the diffuse color of your scene afterwards.

heeen fucked around with this message at 10:34 on May 15, 2008

heeen
May 14, 2005

CAT NEVER STOPS

HB posted:

If you set <1,0,0,0> (or <-1,0,0,0>) you should see exactly half of your scene.

Are you doing anything weird with your projection matrix?

I found the solution, I have to use gl_ClipVertex in my vertex shader to use clipping planes. I didn't understand the problems with transformations yet, though. seems like I can just use ftransform when my clipping plane is specified in eye coordinates, but other than that, I don't know yet.

edit:

8) How does user clipping work?

DISCUSSION: The OpenGL Shading Language provides a gl_ClipVertex
built-in variable in the vertex shading language. This variable provides
a place for vertex shaders to specify a coordinate to be used by the
user clipping plane stage. The user must ensure that the clip vertex and
user clipping planes are defined in the same coordinate space. Note that
this is different than ARB_vertex_program, where user clipping is
ignored unless the position invariant option is enabled (where all
vertex transformation options are performed by the fixed functionality
pipeline). Here are some tips on how to use user clipping in a vertex
shader:

1) When using a traditional transform in a vertex shader, compute the
eye coordinates and store the result in gl_ClipVertex.

2) If clip planes are enabled with a vertex shader, gl_ClipVertex must
be written to, otherwise results will be undefined.

3) When doing object-space clipping, keep in mind that the clip planes
are automatically transformed to eye coordinates (see section 2.11
of the GL 1.4 spec). Use an identity modelView matrix to avoid this
transformation.

heeen fucked around with this message at 18:37 on May 16, 2008

heeen
May 14, 2005

CAT NEVER STOPS
Deos someone have some good texture resources? Preferably with normal/spec/bumpmap.

heeen
May 14, 2005

CAT NEVER STOPS
Here's a timer class I wrote once:
code:
#ifndef TIMER_H
#define TIMER_H
class Timer
{
public:
	Timer(){FrameTime=1;};
	

	virtual void Toggle()=0;
	double FrameTime;
};
#endif

#ifndef WIN32TIMER_H
#define WIN32TIMER_H

#include "timer.h"

/**
  *@author heeen
  */

class Win32Timer : public Timer  {
public: 
	Win32Timer();
	void Toggle();
private:
	double lastTime;
	double tfreq;

};

#endif



#include "win32timer.h"
#include <windows.h>


Win32Timer::Win32Timer()
{
	LARGE_INTEGER timerFrequency;
//	LARGE_INTEGER startCount;
	QueryPerformanceFrequency(&timerFrequency);
	tfreq = (double) timerFrequency.QuadPart;
	FrameTime=1;
	lastTime = 0; //(double)startCount.QuadPart /tfreq;
}

void Win32Timer::Toggle()
{
	double currentTime;
	LARGE_INTEGER startCount;
	QueryPerformanceCounter(&startCount);
	currentTime = (double)startCount.QuadPart /tfreq;
	FrameTime=(currentTime-lastTime);
	lastTime = currentTime;

}
used somehow like this:
code:

	timer.Toggle();
	timer.Toggle();
	while(doGameLoop)
	{
		time+=(float)timer.FrameTime;
		frameCounter++;
		renderer->render();

		context.SwapBuffer();
		context.HandleWin32Messages();
		doMovement();
		timer.Toggle();
	}
edit:
code:
if(keyboard.On('O'))
		renderer->cam.moveUp(movementspeed*timer.FrameTime);
etc.

heeen fucked around with this message at 13:54 on May 25, 2008

heeen
May 14, 2005

CAT NEVER STOPS
Well, no. I wrote that a few years ago and never thought about it. I had a different class for unix timers, so I didn't really need a virtual function, I just wanted a defined interface.

heeen
May 14, 2005

CAT NEVER STOPS

gibbed posted:

Havok announced a few months ago that they would be releasing the core library for Havok to the public, looks like they finally got around to it:
http://www.havok.com/tryhavok
Looks like they are being friendly to cheapo game developers too:
SDK download is ~230MB.

Excellent I have been waiting for this. Now I wonder wether I should try Havok or PhysX first. Can anyone compare the two?

heeen
May 14, 2005

CAT NEVER STOPS
I want to convert eye-coordinates into world-coordinates in my geometry shader, but soemthing is a bit off here:
code:
vec4 ws_points[3];
	for(int i=0; i<3; i++) //original triangle
	{
		ws_points[i]=gl_ModelViewMatrix*camtrafoinv*gl_PositionIn[i];
		//do something in worldspace
		gl_ClipVertex=camtrafo*ws_points[i];
		gl_Position=gl_ProjectionMatrix*camtrafo*ws_points[i];
		gl_FrontColor=vec4(1,0,0,1);
		EmitVertex();
		
	}
	EndPrimitive();
vertices that are already in worldspace work fine, but vertices with an additional transform get rotated strangely.
edit: nevermind, got it.

heeen fucked around with this message at 18:30 on Jun 17, 2008

heeen
May 14, 2005

CAT NEVER STOPS
Can someone share insights in developing an entity system?
As in what properties, how extendable, parent-child relationship, spawning, management etc.
Is duck-typing practicable? Or a mixture of static typing and dynamic properties?

heeen
May 14, 2005

CAT NEVER STOPS

OneEightHundred posted:

Are you networking this or making a single-player game?

What language are you writing your gamecode in?

I'm writing the engine in c++ and want to add scripting in js later. For now it is single player only. I think I'm going to use the hybrid method described above:
A few fixed entity classes for things like models, lights, physics, plus a script namespace for dynamic properties to avoid the bottleneck mentioned above.

heeen
May 14, 2005

CAT NEVER STOPS
What do you guys think of the Blender game engine?

heeen
May 14, 2005

CAT NEVER STOPS
Does Hammer support patches, like Gtkradiant?

heeen
May 14, 2005

CAT NEVER STOPS
Scene graphs - just say no

heeen
May 14, 2005

CAT NEVER STOPS
Would anyone be interested in sharing resources like textures and models? I just made a 4096 concrete texture and a 2048 metal floor texture.

heeen
May 14, 2005

CAT NEVER STOPS
QuakeC is compiled to bytecode or actual binaries you buffoons

heeen
May 14, 2005

CAT NEVER STOPS

Chris Awful posted:

Is it possible to set the origin in opengl to the topleft part of the screen, and keep it there when resizing the window?

You can use gluOrtho2D with the values for top end bottom swapped and you'll have the y-axis flipped.

Adbot
ADBOT LOVES YOU

heeen
May 14, 2005

CAT NEVER STOPS
Ceshire Cat: http://www.pseudoform.org/index.php?id=media went open source, looks like it fits your problem pretty well.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply