From cfb9827b2c1fbc9be2d884cb1dd3a110d5eaea22 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 19 Jun 2013 20:47:23 +0200 Subject: [PATCH] Test texture with postprocessing material, seems to work with opengl --- code/nel/include/nel/3d/driver.h | 14 +++--- code/snowballs2/bin/pp_test.cg | 13 +++++ code/snowballs2/client/src/commands.cpp | 65 ++++++++++++++++++++----- 3 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 code/snowballs2/bin/pp_test.cg diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 9e77e31d6..58db119c0 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -144,7 +144,7 @@ public: enum TPixelProgramProfile { - // direct3d + // direct3d - 0xD3D0,major,minor ps_1_1 = 0xD3D00101, ps_1_2 = 0xD3D00102, ps_1_3 = 0xD3D00103, @@ -153,11 +153,13 @@ public: ps_2_x = 0xD3D00201, // not sure... ps_3_0 = 0xD3D00300, - // opengl - arbfp1 = 0x061A0100, // made up values - fp20 = 0x06100200, - fp30 = 0x06100300, - fp40 = 0x06100400, + // opengl - 0x0610,bitfield + arbfp1 = 0x06100001, // ARB_fragment_program + // fp20 = 0x061B0002, + fp30 = 0x06100004, // NV_fragment_program + fp40 = 0x06100008, // NV_fragment_program2 + gp4fp = 0x06100010, // NV_gpu_program4 + gp5fp = 0x06100020, // NV_gpu_program5 }; protected: diff --git a/code/snowballs2/bin/pp_test.cg b/code/snowballs2/bin/pp_test.cg new file mode 100644 index 000000000..f44c2d424 --- /dev/null +++ b/code/snowballs2/bin/pp_test.cg @@ -0,0 +1,13 @@ +void pp_test( + // Per fragment parameters + float2 texCoord : TEXCOORD0, + + // Fragment program constants + uniform sampler2D cTex0 : TEX0, + + // Output color + out float4 oCol : COLOR) +{ + oCol.rba = float3(1.0, 0.0, 1.0); + oCol.g = tex2D(cTex0, texCoord).g; +} \ No newline at end of file diff --git a/code/snowballs2/client/src/commands.cpp b/code/snowballs2/client/src/commands.cpp index a92f296c8..09f7b354c 100644 --- a/code/snowballs2/client/src/commands.cpp +++ b/code/snowballs2/client/src/commands.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #endif // @@ -247,6 +248,7 @@ void cbUpdateCommands (CConfigFile::CVar &var) #if SBCLIENT_DEV_PIXEL_PROGRAM namespace { CPixelProgram *a_DevPixelProgram = NULL; +UTextureFile *a_NelLogo; } #endif @@ -294,20 +296,44 @@ void initCommands() #if SBCLIENT_DEV_PIXEL_PROGRAM CommandsMaterial.getObjectPtr()->setShader(NL3D::CMaterial::PostProcessing); - static const char *program_arbfp1 = + /*static const char *program_arbfp1 = "!!ARBfp1.0\n" - "PARAM red = {1.0, 0.0, 0.0, 1.0};\n" - "MOV result.color, red;\n" + "PARAM c[1] = { { 0, 1 } };\n" + "MOV result.color, c[0].xyxy;\n" "END\n"; - static const char *program_ps_1_1 = + static const char *program_ps_2_0 = "ps.1.1\n" "def c0, 1.0, 0.0, 0.0, 1.0\n" - "mov r0, c0\n"; + "mov r0, c0\n";*/ + a_NelLogo = Driver->createTextureFile("nel128.tga"); + CommandsMaterial.setTexture(dynamic_cast(a_NelLogo)); + /*CommandsMaterial.setBlend (false); + CommandsMaterial.setAlphaTest (false); + CommandsMaterial.setBlendFunc (UMaterial::one, UMaterial::zero); + CommandsMaterial.setZWrite(false); + CommandsMaterial.setZFunc(UMaterial::always); + CommandsMaterial.setDoubleSided(true);*/ + //CommandsMaterial.set + static const char *program_arbfp1 = + "!!ARBfp1.0\n" + "PARAM c[1] = { { 1, 0 } };\n" + "MOV result.color.xzw, c[0].xyyx;\n" + "TEX result.color.y, fragment.texcoord[0], texture[0], 2D;\n" + "END\n"; + static const char *program_ps_2_0 = + "ps_2_0\n" + "dcl_2d s0\n" + "def c0, 1.00000000, 0.00000000, 0, 0\n" + "dcl t0.xy\n" + "texld r0, t0, s0\n" + "mov r0.z, c0.y\n" + "mov r0.xw, c0.x\n" + "mov oC0, r0\n"; NL3D::IDriver *d = dynamic_cast(Driver)->getDriver(); if (d->isPixelProgramSupported(IDriver::arbfp1)) a_DevPixelProgram = new CPixelProgram(program_arbfp1); - if (d->isPixelProgramSupported(IDriver::ps_1_1)) - a_DevPixelProgram = new CPixelProgram(program_ps_1_1); + if (d->isPixelProgramSupported(IDriver::ps_2_0)) + a_DevPixelProgram = new CPixelProgram(program_ps_2_0); #endif } @@ -327,7 +353,11 @@ void updateCommands() // Display the background Driver->setMatrixMode2D11 (); +#if SBCLIENT_DEV_PIXEL_PROGRAM + CommandsMaterial.setColor(CRGBA::Blue); // Test to check which shader is displaying. +#else CommandsMaterial.setColor(CommandsBackColor); +#endif float x0 = CommandsBoxX - CommandsBoxBorderX; float y0 = CommandsBoxY - CommandsBoxBorderY; float x1 = CommandsBoxX + CommandsBoxWidth + CommandsBoxBorderX; @@ -338,13 +368,26 @@ void updateCommands() d->activePixelProgram(a_DevPixelProgram); bool fogEnabled = d->fogEnabled(); d->enableFog(false); -#endif + + // Driver->drawQuad(CQuad(CVector(x0, y0, 0), CVector(x1, y0, 0), CVector(x1, y1, 0), CVector(x0, y1, 0)), CommandsMaterial); + CQuadUV quadUV; + quadUV.V0 = CVector(x0, y0, 0); + quadUV.V1 = CVector(x1, y0, 0); + quadUV.V2 = CVector(x1, y1, 0); + quadUV.V3 = CVector(x0, y1, 0); + quadUV.Uv0 = CUV(0, 1); + quadUV.Uv1 = CUV(1, 1); + quadUV.Uv2 = CUV(1, 0); + quadUV.Uv3 = CUV(0, 0); + Driver->drawQuad(quadUV, CommandsMaterial); + //Driver->drawBitmap(x0, y0, x1 - x0, y1 - y0, *a_NelLogo); + + d->enableFog(fogEnabled); + d->activePixelProgram(NULL); +#else Driver->drawQuad(CQuad(CVector(x0, y0, 0), CVector(x1, y0, 0), CVector(x1, y1, 0), CVector(x0, y1, 0)), CommandsMaterial); -#if SBCLIENT_DEV_PIXEL_PROGRAM - d->enableFog(fogEnabled); - d->activePixelProgram(NULL); #endif // Set the text context