Сообщение от HolyDel
GAPI? Судя по контексту OpenGL (OpenAL а не DirectSound и FBO а не RTT да и Geometry Shaders наверное пока еще рано писать на DX, так как WinVista Win7 only)
сколько уже идет разработка? сколько разработчиков?
имхо слишком низко. да и семантика кривовата по моему мнению. отчистить движек можно от загруженных ресурсов. а тут отчистка экрана (окна, полотна, фреймбуффера) и т.д.
какой именно? все? активные?
почему не world->update(0.0f); (если в скобках твининг, то почему не 1.0?)
насчет ньютона. физдвиг без аппаратного ускорения, имхо, не нужен. пока вы напишите двиг, пока напишите игру, уже у 80% юзеров будут карточки, способные аппаратно ускорять физику (тряпки, мягкие тела, флюиды и прочие красивости).
а вообще, так держать!
очень удачен синтаксис, понятен с первого взгляда (на 95%).
буду следить за обновлениями, надеюсь все у вас получится.
|
Используется OpenGL,расширения версии 2.1.
В OpenGL есть расширение "ARB_geometry_shader".
engine->clear,для очистки текущего буффера.
engine->update\render World( deltaTime ),для очистки текущего мира,мир можно менять командой engine->setWorld.
для выгрузки всех ресурсов используется engine->exit();
Вобще есть уже первые нароботки по Deferred Renderer.
Использование DeferredRenderer:
void main(){
Engine* engine = new Engine();
// Инициализация
engine->init(800,600);
// Создаем мир
World* world = engine->createWorld();
engine->initDeferredRenderer();
Camera* camera = engine->createCamera();
camera->setLocalPosition(float3(0.0,0.0,-4));
PointLight* point0 = engine->createPointLight();
point0->setRange(200.0f);
point0->setLocalPosition(float3(0,50,-30));
Texture* colorMap = engine->loadTexture("color_map.dds");
Texture* normalMap = engine->loadTexture("normal_map.dds");
Material* material = new Material();
material->setTexture( 0 , colorMap );
material->setTexture( 1 , normalMap );
material->setShader( engine->loadShader("mesh_vertex.cg","deferred_mesh_textured_bump_pixel.cg",0) );
Mesh* cube = MeshUtil::getInstance().createCube();//createCube(material);
cube->paint(material);
cube->updateTangents();
cube->updateBounds();
//cube->scaleMesh( float3(1,0.1f,1) );
cube->setLocalPosition(float3(0,0,5));
cube->setLocalRotation(rotation(float3(0,0,0)*DEG2RAD));
// Создаем всё для пост фильтера
FrameBuffer* buffer = engine->createBuffer(800,600,FrameBuffer::COLOR0|FrameBuffer::COLOR1|FrameBuffer::DEPTH);
// OpenAL менеджер
OpenAL* al = engine->getAL();
// Грузим звук
Sound* sound = al->createSound("industrial2.mp3",Sound::STREAM||Sound::LOOP);
// Добавляем в список проигрываемых
sound->play();
while( !engine->keyHit(OIS::KC_ESCAPE) ){
if( engine->keyHit(OIS::KC_F5) )
engine->makeScreenshoot();
// устанавливаем рендер в буффер
engine->setFrameBuffer( buffer);
// очистка буффера цвета\глубины\стенцила
engine->clear(Engine::CLEAR_COLOR|Engine::CLEAR_DEPTH,float4(0,0.2f,0.3f,1.0f),1.0f,0);
cube->turn(float3(0,.5f,0));
// рисуем мир
engine->updateWorld(0.0f);
engine->renderWorld(0.0f);
// устанавливаем рендер в бек буффер
engine->setFrameBuffer(0);
engine->clear(Engine::CLEAR_COLOR|Engine::CLEAR_DEPTH,float4(0,0.2f,0.3f,1.0f),1.0f,0);
DeferredRenderer::getInstance().render(buffer,camera,0.0f);
// Вывод на экран
engine->flip();
}
// заверщение работы движка
engine->exit();
}
Point Light шейдер:
struct Input{
float2 texcoord : TEXCOORD0;
};
struct Output{
float4 color : COLOR0;
};
void main( in Input In , out Output Out , uniform sampler2D texture0 , uniform sampler2D texture1 , uniform sampler2D texture2 , uniform float4x4 invViewProj , uniform float3 lightPosition , uniform float lightRange , uniform float3 cameraPosition ){
float depth = tex2D(texture0,In.texcoord).x;
float4 albedo = tex2D(texture1,In.texcoord);
Out.color = albedo;
if( depth >= 1.0f )
return;
float3 normal = tex2D(texture2,In.texcoord).xyz;
// screen space coord
float4 position;
position.x = In.texcoord.x * 2.0f - 1.0f;
position.y = -(In.texcoord.y * 2.0f - 1.0f);
position.z = depth;
position.w = 1.0f;
position = mul( position , invViewProj );
position /= position.w;
// light vector
float3 light_vector = normalize( lightPosition - position.xyz );
// half vector
float3 half_vector = normalize((cameraPosition - position.xyz) + (lightPosition - position.xyz));
// light specular
float specular = 1.0f * pow(dot(half_vector,normal), 100);
// light attenuation
float attenuation = saturate(1.0f - distance(position.xyz, lightPosition) / lightRange);
// final color
Out.color = ( albedo * clamp(dot(normal,light_vector),0.0f,1.0f) ) + specular * attenuation;
}
Кст из потдерживаемых форматов текстур - tga,dds,png,jpg.