mirror of https://github.com/aap/librw.git
fix opengl im2d. d3d still no fog
This commit is contained in:
parent
4c77fb5754
commit
fb859c0fa6
|
@ -11,7 +11,7 @@ float3 DoDirLight(Light L, float3 N)
|
|||
return l*L.color.xyz;
|
||||
}
|
||||
|
||||
float3 DoDirLightSpec(Light L, float3 N, float3 V, float power))
|
||||
float3 DoDirLightSpec(Light L, float3 N, float3 V, float power)
|
||||
{
|
||||
return pow(saturate(dot(N, normalize(V + -L.direction.xyz))), power)*L.color.xyz;
|
||||
}
|
||||
|
|
|
@ -130,8 +130,9 @@ struct Im2DVertex
|
|||
void setScreenX(float32 x) { this->x = x; }
|
||||
void setScreenY(float32 y) { this->y = y; }
|
||||
void setScreenZ(float32 z) { this->z = z; }
|
||||
void setCameraZ(float32 z) { this->w = z; }
|
||||
void setRecipCameraZ(float32 recipz) { }
|
||||
// This is a bit unefficient but we have to counteract GL's divide, so multiply
|
||||
void setCameraZ(float32 z) { }
|
||||
void setRecipCameraZ(float32 recipz) { this->w = 1.0f/recipz; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u, float recipz) { this->u = u; }
|
||||
|
|
|
@ -10,9 +10,8 @@ void
|
|||
main(void)
|
||||
{
|
||||
gl_Position = in_pos;
|
||||
gl_Position.w = 1.0;
|
||||
gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;
|
||||
v_fog = DoFog(gl_Position.z);
|
||||
v_fog = DoFog(gl_Position.w);
|
||||
gl_Position.xyz *= gl_Position.w;
|
||||
v_color = in_color;
|
||||
v_tex0 = in_tex0;
|
||||
|
|
|
@ -11,9 +11,8 @@ const char *im2d_vert_src =
|
|||
"main(void)\n"
|
||||
"{\n"
|
||||
" gl_Position = in_pos;\n"
|
||||
" gl_Position.w = 1.0;\n"
|
||||
" gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;\n"
|
||||
" v_fog = DoFog(gl_Position.z);\n"
|
||||
" v_fog = DoFog(gl_Position.w);\n"
|
||||
" gl_Position.xyz *= gl_Position.w;\n"
|
||||
" v_color = in_color;\n"
|
||||
" v_tex0 = in_tex0;\n"
|
||||
|
|
|
@ -369,6 +369,53 @@ im2dtest(void)
|
|||
&verts, 4, &indices, 4);
|
||||
}
|
||||
|
||||
void
|
||||
im2dtest2(void)
|
||||
{
|
||||
using namespace rw::RWDEVICE;
|
||||
int i;
|
||||
rw::Camera *cam = Scene.camera;
|
||||
float n = cam->nearPlane;
|
||||
float f = cam->farPlane;
|
||||
float mid = (n+f)/4.0f;
|
||||
struct
|
||||
{
|
||||
float x, y, z;
|
||||
rw::uint8 r, g, b, a;
|
||||
float u, v;
|
||||
} vs[4] = {
|
||||
{ 0.5f, 0.5f, n, 255, 255, 255, 255, 0.0f, 0.0f },
|
||||
{ 0.5f, 0.5f, mid, 255, 255, 255, 255, 1.0f, 0.0f },
|
||||
{ 0.5f, -0.5f, n, 255, 255, 255, 255, 0.0f, 1.0f },
|
||||
{ 0.5f, -0.5f, mid, 255, 255, 255, 255, 1.0f, 1.0f },
|
||||
};
|
||||
Im2DVertex verts[4];
|
||||
static short indices[] = {
|
||||
0, 1, 2, 3
|
||||
};
|
||||
|
||||
for(i = 0; i < 4; i++){
|
||||
float recipZ = 1.0f/vs[i].z;
|
||||
verts[i].setScreenX((vs[i].x*recipZ + 0.5f) * 640.0f);
|
||||
verts[i].setScreenY((vs[i].y*recipZ + 0.5f) * 448.0f);
|
||||
verts[i].setScreenZ(recipZ * cam->zScale + cam->zShift);
|
||||
// verts[i].setCameraZ(vs[i].z);
|
||||
verts[i].setRecipCameraZ(recipZ);
|
||||
verts[i].setColor(vs[i].r, vs[i].g, vs[i].b, vs[i].a);
|
||||
if(dosoftras)
|
||||
verts[i].setColor(255, 255, 255, 255);
|
||||
verts[i].setU(vs[i].u + 0.5f/640.0f, recipZ);
|
||||
verts[i].setV(vs[i].v + 0.5f/448.0f, recipZ);
|
||||
}
|
||||
|
||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster);
|
||||
rw::SetRenderState(rw::TEXTUREADDRESS, rw::Texture::WRAP);
|
||||
rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::NEAREST);
|
||||
rw::SetRenderState(rw::VERTEXALPHA, 1);
|
||||
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRISTRIP,
|
||||
&verts, 4, &indices, 4);
|
||||
}
|
||||
|
||||
void
|
||||
im3dtest(void)
|
||||
{
|
||||
|
@ -449,6 +496,10 @@ Draw(float timeDelta)
|
|||
{
|
||||
getFrontBuffer();
|
||||
|
||||
rw::SetRenderState(rw::FOGCOLOR, 0xFF0000FF);
|
||||
rw::SetRenderState(rw::FOGENABLE, 1);
|
||||
camera->m_rwcam->fogPlane = camera->m_rwcam->nearPlane;
|
||||
|
||||
static rw::RGBA clearcol = { 161, 161, 161, 0xFF };
|
||||
camera->m_rwcam->clear(&clearcol, rw::Camera::CLEARIMAGE|rw::Camera::CLEARZ);
|
||||
camera->update();
|
||||
|
@ -457,7 +508,7 @@ Draw(float timeDelta)
|
|||
extern void beginSoftras(void);
|
||||
beginSoftras();
|
||||
|
||||
gen::tlTest(Scene.clump);
|
||||
// gen::tlTest(Scene.clump);
|
||||
void drawtest(void);
|
||||
// drawtest();
|
||||
|
||||
|
@ -466,6 +517,7 @@ extern void endSoftras(void);
|
|||
endSoftras();
|
||||
}
|
||||
//im2dtest();
|
||||
im2dtest2();
|
||||
|
||||
// Scene.clump->render();
|
||||
// im3dtest();
|
||||
|
|
Loading…
Reference in New Issue