irrCg v0.8 (Initial) - CgFX (Texture States, MultiPass etc.)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Here is edited "depth.cg" to "handle" transparent nodes (fences, tree leaves...).
I have not tried it because i am not using Irrlicht long time now
(i choped it from my "game engine"), but i am still lurking thru this forums.

Sorry for my bad english.

Code: Select all

sampler2D samp; // your tex with alpha info
void main_v( 
              in float3  inPosition    : POSITION,
              in float2  inTexCoord0   : TEXCOORD0, 
              out float4 outPosition   : POSITION,
              out float  outTexCoord0  : TEXCOORD0, 
              out float  outDepthColor : TEXCOORD1, 
              uniform float4x4 WVP,
              uniform float4x4 WV)
{
	outPosition   =  mul(WVP, float4(inPosition, 1.0f));
	outTexCoord0  = inTexCoord0;
      outDepthColor = outPosition.z;
}
void main_f(  in  float2 inTexCoord0  : TEXCOORD0,
              in  float  inDepthColor : TEXCOORD1,
              out float4 outColor     : COLOR)
{
      float tAlpha   = tex2D(samp, inTexCoord0).a; // sample from alpha
      float alphaRef = 0.8f;                       // alphaRef value
      clip(tAlpha - alphaRef);                     // discard current pixel that is below alphaRef
	outColor       = inDepthColor;
}
Is there someone with solution for light "bleeding" problem?
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

hybrid wrote:The integration uses (used?) a different approach for the integration than for other HL shaders.
Hmmm... in my opinion this integration is very similar to current Irrlicht HL shaders implementation, only minor differences are visible in callback part. But I agree with Hybrid, IrrCg is avaiable as addon and it's easy to use, so we needn't currently merge them with Irrlicht core. Time need for merge it, Irrlicht dev team can intend for more important features, which have to be added to Irrlicht core.

@belfegor
Why You don't use code similar for it:

Code: Select all

if(AlphaValueFromTexture == 0.0) // only transparent, alpha bleending isn't supported
discard;
This is good solution for transparent objects, but for alpha blending we need A-Buffer or Depth Peeling.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

My assumption is probably based on an old version of irrCg and might be outdated. But I didn't have time to look this up, so we have to leave it as is for now. We might integrate it at some point with more free time on our side, though :)
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Why You don't use code similar for it:...
Because i only use DX9 in my engine (without Cg), and (i think) "discard" function isnt
part of HLSL functions.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Post by bmwop »

Hi all,

First of all, IrrCg is great!
But I found an interest thing in IrrCg (download svn version from the first post - 2009-05-17. Do we have more fresh version?).
I had problems with transparent materials. The HLSL/GLSL/built-in code works properly, but the Cg code not. I investigated a little bit, and compare IrrCg code to the original Irrlicht shading code, and I found a missing part from IrrCg.cpp:

Code: Select all

    //! Returns if the material is transparent. The scene managment needs to know this
    //! for being able to sort the materials by opaque and transparent.
    bool ICgMaterialRenderer::isTransparent() const
    {
        return BaseMaterial ? BaseMaterial->isTransparent() : false;
    }
(the comment is from Irrlicht CD3D9ShaderMaterialRenderer.cpp)

It solved my problem, the Cg shaders now work properly also with alpha channel textures.

Maybe someone also has this problem.

(Anyway, I think it is easy to modify the code of IrrCg to be able to compile on both Linux and Windows without modification.)

I also noticed some performance degradation with Cg compare to HLSL (D3D9): 5-10% (or more in some cases). But I can live with this.

Now it works fine.
Thanks!
Bye!
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Thanks for bug raport, now it's ok. In performance We can try improve it, by set optimal settings, I have to check result HLSL vs Cg on my Radeon 4850.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
noob2008
Posts: 5
Joined: Fri May 30, 2008 8:10 am

Linux compile issue

Post by noob2008 »

Hi

I'm attempting to get irrCg_svn running in Linux with OpenGL

I've commented out //#define IrrCgD3D9 and #define IrrCgWin32 and // #define IrrCgSharedLib then uncommented #define IrrCgLinux in the IrrGc.cpp file

I have gc toolkit 2.2 installed in /usr

I'm using Irrlicht 1.5

but am getting the following compile errors:
/Software/irrlicht/irrcg/source> make
g++ IrrCg.cpp -static -c -o ../lib/Linux/libIrrCg.a -I"../../Irrlicht/include" -I"../../Irrlicht/source/Irrlicht" -I"../include" -L"/usr/X11R6/lib" -L"../../lib/Linux"
In file included from IrrCg.cpp:47:
../../Irrlicht/include/IrrCgExtensionHandler.h: In constructor ‘IrrCg::IrrCgExtensionHandler::IrrCgExtensionHandler()’:
../../Irrlicht/include/IrrCgExtensionHandler.h:25: error: ‘wglGetProcAddress’ was not declared in this scope
In file included from IrrCg.cpp:48:
../../Irrlicht/include/IrrCgMaterial.h: At global scope:
../../Irrlicht/include/IrrCgMaterial.h:10: error: use of enum ‘IRR_CG_TYPE’ without previous declaration
../../Irrlicht/include/IrrCgMaterial.h:11: error: use of enum ‘IRR_CG_TRANSFORM’ without previous declaration
../../Irrlicht/include/IrrCgMaterial.h:417: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:433: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:441: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:457: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:465: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:481: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:489: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:505: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:513: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:529: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:537: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:553: error: ‘IRR_CG_TRANSFORM’ does not name a type
make: *** [all] Error 1

Is ‘wglGetProcAddress’ a windows only extension loader?

what have I missed?

apologies if this is obvious but its almost 2:00am and I'm getting a little tired :)
bmwop
Posts: 11
Joined: Tue Jul 07, 2009 4:04 pm

Re: Linux compile issue

Post by bmwop »

noob2008 wrote:Hi

I'm attempting to get irrCg_svn running in Linux with OpenGL

I've commented out //#define IrrCgD3D9 and #define IrrCgWin32 and // #define IrrCgSharedLib then uncommented #define IrrCgLinux in the IrrGc.cpp file

I have gc toolkit 2.2 installed in /usr

I'm using Irrlicht 1.5

but am getting the following compile errors:
/Software/irrlicht/irrcg/source> make
g++ IrrCg.cpp -static -c -o ../lib/Linux/libIrrCg.a -I"../../Irrlicht/include" -I"../../Irrlicht/source/Irrlicht" -I"../include" -L"/usr/X11R6/lib" -L"../../lib/Linux"
In file included from IrrCg.cpp:47:
../../Irrlicht/include/IrrCgExtensionHandler.h: In constructor ‘IrrCg::IrrCgExtensionHandler::IrrCgExtensionHandler()’:
../../Irrlicht/include/IrrCgExtensionHandler.h:25: error: ‘wglGetProcAddress’ was not declared in this scope
In file included from IrrCg.cpp:48:
../../Irrlicht/include/IrrCgMaterial.h: At global scope:
../../Irrlicht/include/IrrCgMaterial.h:10: error: use of enum ‘IRR_CG_TYPE’ without previous declaration
../../Irrlicht/include/IrrCgMaterial.h:11: error: use of enum ‘IRR_CG_TRANSFORM’ without previous declaration
../../Irrlicht/include/IrrCgMaterial.h:417: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:433: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:441: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:457: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:465: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:481: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:489: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:505: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:513: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:529: error: ‘IRR_CG_TRANSFORM’ does not name a type
../../Irrlicht/include/IrrCgMaterial.h:537: error: ‘IRR_CG_TRANSFORM’ has not been declared
../../Irrlicht/include/IrrCgMaterial.h:553: error: ‘IRR_CG_TRANSFORM’ does not name a type
make: *** [all] Error 1

Is ‘wglGetProcAddress’ a windows only extension loader?

what have I missed?

apologies if this is obvious but its almost 2:00am and I'm getting a little tired :)
I use this diff for both problems, now Cg works for me both Linux and Windows without modification:

Code: Select all

diff -ur orig/include/IrrCgExtensionHandler.h new/include/IrrCgExtensionHandler.h
--- orig/include/IrrCgExtensionHandler.h        2009-04-20 15:15:14.000000000 +0200
+++ new/include/IrrCgExtensionHandler.h 2009-07-06 23:24:06.000000000 +0200
@@ -11,7 +11,11 @@

 #ifdef IrrCgOGL

+#ifdef __linux__
+#include "GL/gl.h"
+#else
 #include "gl/gl.h"
+#endif
 #include "glext.h"

 namespace IrrCg
@@ -22,7 +26,11 @@
         IrrCgExtensionHandler()
         {
             #ifdef _IRR_OPENGL_USE_EXTPOINTER_
+#ifdef __linux__
+            pGlActiveTextureARB = 0;
+#else
             pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
+#endif
             #endif
         }

diff -ur orig/include/IrrCg.h new/include/IrrCg.h
--- orig/include/IrrCg.h        2009-04-26 15:45:48.000000000 +0200
+++ new/include/IrrCg.h 2009-07-07 13:55:02.000000000 +0200
@@ -30,10 +30,10 @@
 namespace IrrCg
 {
     //! ICgServices Type enumeration.
-    enum IRR_CG_TYPE { ICGT_EMPTY = 0, ICGT_OPENGL, ICGT_DIRECT3D9 };
+//    enum IRR_CG_TYPE { ICGT_EMPTY = 0, ICGT_OPENGL, ICGT_DIRECT3D9 };

     //! Matrix Type enumeration for Matrix operations.
-    enum IRR_CG_TRANSFORM { ICGT_MATRIX_IDENTITY = 0, ICGT_MATRIX_TRANSPOSE, ICGT_MATRIX_INVERSE, ICGT_MATRIX_INVERSE_TRANSPOSE };
+//    enum IRR_CG_TRANSFORM { ICGT_MATRIX_IDENTITY = 0, ICGT_MATRIX_TRANSPOSE, ICGT_MATRIX_INVERSE, ICGT_MATRIX_INVERSE_TRANSPOSE };

     //! IrrCg Extension Handler class.
     class IrrCgExtensionHandler;
@@ -358,6 +358,9 @@
         //! Like IMaterialRenderer::OnUnsetMaterial(), but for a Cg shaders.
         virtual void OnUnsetMaterial();

+        //! Returns if the material is transparent.
+        virtual bool isTransparent() const;
+
     protected:
         //! This store pointner to Type of standard Irrlicht Material Renderer eg. Solid.
         irr::video::IMaterialRenderer* BaseMaterial;
diff -ur orig/include/IrrCgMaterial.h new/include/IrrCgMaterial.h
--- orig/include/IrrCgMaterial.h        2009-04-20 15:15:14.000000000 +0200
+++ new/include/IrrCgMaterial.h 2009-07-06 21:43:35.000000000 +0200
@@ -7,8 +7,14 @@

 namespace IrrCg
 {
-    enum IRR_CG_TYPE;
-    enum IRR_CG_TRANSFORM;
+    //! ICgServices Type enumeration.
+    enum IRR_CG_TYPE { ICGT_EMPTY = 0, ICGT_OPENGL, ICGT_DIRECT3D9 };
+
+    //! Matrix Type enumeration for Matrix operations.
+    enum IRR_CG_TRANSFORM { ICGT_MATRIX_IDENTITY = 0, ICGT_MATRIX_TRANSPOSE, ICGT_MATRIX_INVERSE, ICGT_MATRIX_INVERSE_TRANSPOSE };
+
+//    enum IRR_CG_TYPE;
+//    enum IRR_CG_TRANSFORM;

     class ICgServices;
     class ICgMaterialConstantSetCallBack;
diff -ur orig/source/IrrCg.cpp new/source/IrrCg.cpp
--- orig/source/IrrCg.cpp       2009-04-26 15:45:48.000000000 +0200
+++ new/source/IrrCg.cpp        2009-07-07 13:55:02.000000000 +0200
@@ -1,18 +1,20 @@
 // Copyright (C) 2007-2008 Patryk Nadrowski
 // This file is part of the "IrrCg".
 // For conditions of distribution and use, see copyright notice in License.txt
+#ifndef DISABLE_CG_SHADERS

 // You have to define it, if You compile on Windows. Require Windows PlatformSDK.
+#ifndef __linux__
+#define _IRR_COMPILE_WITH_DIRECT3D_9_
 #define IrrCgWin32
-
+// You have to define it, if You need Cg support for Direct3D program. Require DirectX SDK.
+#define IrrCgD3D9
+#else
 // You have to define it, if You compile on Linux.
-//#define IrrCgLinux
-
+#define IrrCgLinux
 // You have to define it, if You use Irrlicht Linux Shared Library (*.so)
 // #define IrrCgSharedLib
-
-// You have to define it, if You need Cg support for Direct3D program. Require DirectX SDK.
-#define IrrCgD3D9
+#endif

 // You have to define it, if You need Cg support for OpenGL program.
 #define IrrCgOGL
@@ -64,11 +66,13 @@

 // Get OpenGL Texture Name. Like standard Irrlicht getOpenGLTextureName().
 #ifdef IrrCgOGL
+#ifndef __linux__
 GLuint irr::video::COpenGLTexture::getOpenGLTextureName() const
 {
        return TextureName;
 }
 #endif
+#endif

 // Get Direct3D Texture Name. Like standard Irrlicht getDX9Texture().
 #ifdef IrrCgD3D9
@@ -892,5 +896,14 @@
         if (BaseMaterial)
         BaseMaterial->OnUnsetMaterial();
     }
+
+    //! Returns if the material is transparent. The scene managment needs to know this
+    //! for being able to sort the materials by opaque and transparent.
+    bool ICgMaterialRenderer::isTransparent() const
+    {
+        return BaseMaterial ? BaseMaterial->isTransparent() : false;
+    }
+
     // End of class ICgMaterialRenderer
 }
+#endif /* DISABLE_CG_SHADERS */
diff -ur orig/source/IrrCgMaterial.cpp new/source/IrrCgMaterial.cpp
--- orig/source/IrrCgMaterial.cpp       2009-04-20 15:02:18.000000000 +0200
+++ new/source/IrrCgMaterial.cpp        2009-07-06 21:43:35.000000000 +0200
@@ -1,3 +1,6 @@
+
+#ifndef DISABLE_CG_SHADERS
+
 #include "irrlicht.h"

 #include <Cg/cg.h>
@@ -823,3 +826,4 @@
         return true;
     }
 }
+#endif /* DISABLE_CG_SHADERS */
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Hi, current SVN version of IrrCg aren't compatible with Linux, I can will improve it near 20 august, because now I have got many work with my game. Now You can try with bmwop patch (I don't test it).
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
noob2008
Posts: 5
Joined: Fri May 30, 2008 8:10 am

Post by noob2008 »

Thanks very much bmwop the patch worked like a charm.
Looking forward to your August 20 update Nadro, good luck with your game
mordentral
Posts: 1
Joined: Fri Aug 28, 2009 4:05 pm

Re:

Post by mordentral »

Just to let you know Nadro I downloaded directly from the SVN (I tend to do so to make sure I have the latest release of such things). Your SVN directory however is missing this file: source\IrrCgMaterial.cpp

I fixed it for myself by download the package you linked but wanted to warn you that it was missing.

Cheers and thanks for the extension
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Irrlicht 1.5 and irrCG

Post by asparagusx »

Hallo

Getting very confused here (done easily). I have downloaded an SVN version of irrCg V0.7 (which does not appear to be available any more) and I have compiled a version of irrCg with CG (April 2009) from NVidea downloads. I am compiling with Irrlicht 1.5.1. When I run any of the irrCG examples, the system starts but none of the meshes with CG materials on them will display. None of the callbacks (OnSetConstants) are called, so I am assuming something is not correct. Which is the correct version of irrCG to be used with irrlicht 1.5? CG does not appear to give any errors, but that be because it is not logged properly. Any advice/help will be appreciated.

It is notable that a valid material type is returned by

Code: Select all

CgLightingMaterialType = GPU->addCgShaderMaterialFromFiles(CG_SOURCE,"../../cg/LightingVert.cg","main_v","arbvp1","vs_2_0","../../cg/LightingVert.cg","main_f","arbfp1","ps_2_0",VLCB,EMT_SOLID);
Thanks

Asp
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Hi asparagusx,
Please use irrCg from SVN (rev 5). I uploaded it today. It's compatible with Irrlicht 1.5.1 and Irrlicht from SVN.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Nadro

Sorry for being thick - but where do I get the SVN version? I downloaded from the link on the first post, but it appears to be original V0.7. Interesting follow on - I changed the vertex/pixel shader type from "vs_2_0" and "ps_2_0" to "vs_1_1" and "ps_1_1" and the meshes were displayed, although not with the correct CG material renderer :

Code: Select all

CgLightingMaterialType = GPU->addCgShaderMaterialFromFiles(CG_SOURCE,"../../cg/LightingVert.cg","main_v","arbvp1","vs_2_0","../../cg/LightingVert.cg","main_f","arbfp1","ps_2_0",VLCB,EMT_SOLID);
Any ideas?

Thanks

Asp

PS Got SVN - it was on your google site - did not notice that!
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Nadro

Ok have rebuilt irrcg.lib with latest SVN source and the problems are still the same. There were some problems compiling and got some errors re abstract classes :

Code: Select all

virtual void OnSetConstants( ICgServices* services,CGprogram Vertex,CGprogram Fragment,const irr::video::SMaterial& Material ){}// = 0;
In the examples files, there are references to MATRIX_IDENTITY which should be ICGT_MATRIX_IDENTITY

Any ideas as to why I cannot see the meshes - the material types seems to be correct, but the problems are still the same as per my previous posts. I am trying to build the basic lighting example.

I am using March 2008 DirectX SDK, Cg April 2009 and Irrlicht 1.5.1-SVN.

Here is the console output when running the app

Image

and this is the output I see - as you can see Mr. Elephant is not there!

Image

I have managed to compile V07 before using basically the same environment, but it was a previous version of CG (May 2008 I think). There is also a problem when using #define IrrCgOGL when building irrcg.lib - I get a linker error in basic lighting

Code: Select all

1>irrcg.lib(IrrCg.obj) : error LNK2019: unresolved external symbol "public: bool __thiscall irr::video::COpenGLDriver::setTexture(unsigned int,class irr::video::ITexture const *)" (?setTexture@COpenGLDriver@video@irr@@QAE_NIPBVITexture@23@@Z) referenced in function "public: virtual void __thiscall IrrCg::ICgMaterialRenderer::OnSetMaterial(class irr::video::SMaterial const &,class irr::video::SMaterial const &,bool,class irr::video::IMaterialRendererServices *)" (?OnSetMaterial@ICgMaterialRenderer@IrrCg@@UAEXABVSMaterial@video@irr@@0_NPAVIMaterialRendererServices@45@@Z)
I am using latest SVN of 1.5.1 (checked it out about an hour ago). I am compiling irrcg.lib using Visual Studio 2005.

Thanks

Asp
Post Reply