fix opengl im2d. d3d still no fog

This commit is contained in:
aap 2021-02-12 13:58:11 +01:00
parent 4c77fb5754
commit fb859c0fa6
5 changed files with 60 additions and 9 deletions

View File

@ -11,7 +11,7 @@ float3 DoDirLight(Light L, float3 N)
return l*L.color.xyz; 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; return pow(saturate(dot(N, normalize(V + -L.direction.xyz))), power)*L.color.xyz;
} }

View File

@ -130,8 +130,9 @@ struct Im2DVertex
void setScreenX(float32 x) { this->x = x; } void setScreenX(float32 x) { this->x = x; }
void setScreenY(float32 y) { this->y = y; } void setScreenY(float32 y) { this->y = y; }
void setScreenZ(float32 z) { this->z = z; } void setScreenZ(float32 z) { this->z = z; }
void setCameraZ(float32 z) { this->w = z; } // This is a bit unefficient but we have to counteract GL's divide, so multiply
void setRecipCameraZ(float32 recipz) { } void setCameraZ(float32 z) { }
void setRecipCameraZ(float32 recipz) { this->w = 1.0f/recipz; }
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
this->r = r; this->g = g; this->b = b; this->a = a; } this->r = r; this->g = g; this->b = b; this->a = a; }
void setU(float32 u, float recipz) { this->u = u; } void setU(float32 u, float recipz) { this->u = u; }

View File

@ -10,9 +10,8 @@ void
main(void) main(void)
{ {
gl_Position = in_pos; gl_Position = in_pos;
gl_Position.w = 1.0;
gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw; 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; gl_Position.xyz *= gl_Position.w;
v_color = in_color; v_color = in_color;
v_tex0 = in_tex0; v_tex0 = in_tex0;

View File

@ -11,9 +11,8 @@ const char *im2d_vert_src =
"main(void)\n" "main(void)\n"
"{\n" "{\n"
" gl_Position = in_pos;\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" " 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" " gl_Position.xyz *= gl_Position.w;\n"
" v_color = in_color;\n" " v_color = in_color;\n"
" v_tex0 = in_tex0;\n" " v_tex0 = in_tex0;\n"

View File

@ -369,6 +369,53 @@ im2dtest(void)
&verts, 4, &indices, 4); &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 void
im3dtest(void) im3dtest(void)
{ {
@ -449,6 +496,10 @@ Draw(float timeDelta)
{ {
getFrontBuffer(); 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 }; static rw::RGBA clearcol = { 161, 161, 161, 0xFF };
camera->m_rwcam->clear(&clearcol, rw::Camera::CLEARIMAGE|rw::Camera::CLEARZ); camera->m_rwcam->clear(&clearcol, rw::Camera::CLEARIMAGE|rw::Camera::CLEARZ);
camera->update(); camera->update();
@ -457,7 +508,7 @@ Draw(float timeDelta)
extern void beginSoftras(void); extern void beginSoftras(void);
beginSoftras(); beginSoftras();
gen::tlTest(Scene.clump); // gen::tlTest(Scene.clump);
void drawtest(void); void drawtest(void);
// drawtest(); // drawtest();
@ -466,6 +517,7 @@ extern void endSoftras(void);
endSoftras(); endSoftras();
} }
//im2dtest(); //im2dtest();
im2dtest2();
// Scene.clump->render(); // Scene.clump->render();
// im3dtest(); // im3dtest();