Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 16 May 2007
Offline Last Active Jun 02 2014 04:35 PM

Topics I've Started

RegisterGlobalFunction returning script class

17 July 2013 - 10:23 AM

Sorry for creating so many threads recently. I've got some kind of chicken and egg problem.


There's a class "EffectC" implemented in C++ and also an angelscript class "Effect" which is loaded in a "base" module. When EffectC is created, it creates an instance of "Effect" which has a constructor, taking EffectC as parameter:

shared class Effect : DynamicBase, Object
	private EffectC@ self;
	Effect(EffectC@ obj) { @self = obj; }

Now here's the problem: In Angelscript I'd like to create a new effect, calling a globalFunction "Effect@ createEffect()". This should actually be a registered C++ function, that creates "EffectC", which in turn creates an instance of "Effect" and returns it.

r = engine->RegisterGlobalFunction("Effect@ createEffect(uint res)", asFUNCTION(asCreateEffect), asCALL_CDECL);

This doesn't work, obviously, because the engine doesn't know about "Effect" (identifier "Effect" is not a data type).

Is it even possible to use a C++ function and return an asIScriptObject?

Proper way of creating as class in C++

16 July 2013 - 06:22 AM

I've googled but couldn't come up with a proper solution. I'd like to create an instance of an angelscript class from C++. My current approach:

asIObjectType* type = modBase->GetObjectTypeByName("Test");
asIScriptObject* obj = static_cast<asIScriptObject*>(engine->CreateScriptObject(type->GetTypeId()));

While this works I wondered, why CreateScriptObject returned a void pointer instead of a script object. Investigating as_scriptengine.cpp, I noticed, that the method was marked as deprecated and creation should be done via a factory. How does it work? The class is guaranteed to have a default constructor.


Also, what's wrong with the way it's currently done?

Dynamically compile classes

09 July 2013 - 07:52 AM

Hello there. Once again, thank you for this great scripting language.

As I understand adding script sections to a module is more or less the same as concatenating several code snippets (except for error messages). When building my code everything inside the module is discarded and replaced by the script sections I added. Is this correct?


Functions as well as global variables can be dynamically compiled into a module. What I need is adding class declarations on the fly, so I can add new classes while the game progresses and create instances of them. Is this is possible and if not, how difficult would it be to add such a feature?

Rendering refraction and transparent objects

16 November 2012 - 11:09 AM

Hello there, I'd like to implement refractive objects (water, glass etc) and two problems arise:

1) In order to use refraction I need to render everything else to a texture. Is that correct or is there another way?

2) Since glass is transparent I need to order it back to front. If 1) applies I'd have to render the multiple times. In case of three transparent objects where the second one is refractive:

a) render solid geometry to texture
b) render 1st transparent object to texture
c) render refractive object using the texture from a) and b)
d) render 2nd transparent object

Now this seems like a performance killer and I suspect there're better ways to do this. I don't know how though and my search didn't come up with anything informative. Maybe you have a solution to my problem?

Blending RGBA8

31 October 2012 - 02:23 AM

Hello there. I'm currently working on my light prepass render pipeline, that is, writing normal and depth buffer (1), then creating light accumulation buffer (2) and finally render geometry again (3) using the information from the light accumulation buffer.

Now I'm working on adding decals to the system. Since decals are placed on top of solid geometry I disable depth writing and then render the decals using alpha blending. Here is where the problem starts:

During (3) I can smoothly alpha blend my decals on top of the solid geometry using ogl's blend function (ONE_MINUS_SRC_ALPHA, SRC_ALPHA). Decals blend in very well, BUT it uses the normals of the underlying surface. While this may be desired in some cases like graffiti on walls, it should sometimes use its own normals for lighting calculation. A simple example would be foot step marks on the ground.

What I'd like to do is to use alpha blending during (1), i.e. alpha blend solid geometry normals with my decal normals. The normal buffer layout is
ARGB8 with normal xyz in RGB and object's specular roughness in A. That means I need to blend all 4 channels. Since the alpha blend function uses the alpha channel for blending I can't blend normals and roughness at the same time. Actually I need some additional fragment value on which I can base the alpha blending.

Here's the code
#extension GL_ARB_draw_buffers : enable
varying vec3 normal;
varying vec4 position;
uniform sampler2D texAlpha;
void main()\n \
{\n \
// normal\n \
gl_FragData[0].rgb = normal * 0.5 + 0.5;
gl_FragData[0].a = gl_FrontMaterial.shininess/128.;
// the blend factor that I actually need for blending
	    float blendFactor = texture2D(texAlpha, gl_TexCoord[0].st);
gl_FragDepth = position.z/position.w;

So basicall I'd like to use the blending function with the blend factor I defined in the code. Like ONE_MINUS_BLENDFACTOR_ALPHA. I know this doesn't exist but you get the idea. Is there any way to make this possible or workaround the problem?

Thanks for your help