pouët.net

Go to bottom

Random line of code thread

category: code [glöplog]
I'll be glad the day you show us your glow code .. ;)
added on the 2009-02-18 17:38:57 by Aeko Aeko
Code: void PostProcess::init(bool clear) { g_system.bindTextureFBO("postprocess_1024"); if (clear) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } void PostProcess::glow(int steps, float xstep, float ystep, float bluralpha, float glowexp) { glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glDisable(GL_BLEND); glColor3f(1,1,1); blit("postprocess_1024", "postprocess_512"); blit("postprocess_512", "postprocess_256"); if (glowexp > 0.00001f) { Shader &exponential = g_system.getShader("postprocess_exp"); exponential.bind(); exponential.setUniform1f("expfactor", glowexp); exponential.setUniform1i("tex0", 0); blit("postprocess_256", "postprocess_128"); } else { blit("postprocess_256", "postprocess_128"); } //at this point, postprocess_128 contains a downsampled version of the full image //get shaders Shader& blurx = g_system.getShader("postprocess_blurx"); Shader& blury = g_system.getShader("postprocess_blury"); Shader& combine = g_system.getShader("postprocess_glowcombine"); //then do the blur for (int i = 0; i < steps; i++) { const float t = i / (float)steps; //draw to the other 128x128 texture with the horizontal blur shader blurx.bind(); blurx.setUniform1f("blurscale", xstep * t); blurx.setUniform1f("bluralpha", bluralpha); blurx.setUniform1i("tex", 0); blit("postprocess_128", "postprocess_128_2"); //and then back to the original one with the vertical blur blury.bind(); blury.setUniform1f("blurscale", ystep * t); blury.setUniform1f("bluralpha", bluralpha); blury.setUniform1i("tex", 0); blit("postprocess_128_2", "postprocess_128"); } //enable blend so that the alpha channel will work if necessary glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_ONE); glColor4f(1,1,1,1); //combine the two textures combine.bind(); combine.setUniform1i("tex0", 0); combine.setUniform1i("tex1", 1); g_system.bindTexture("postprocess_1024", GL_TEXTURE0_ARB); g_system.bindTexture("postprocess_128", GL_TEXTURE1_ARB); g_system.setOrthoMode(1, 1); glBegin(GL_QUADS); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex2f(0, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex2f(1, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex2f(1, 1); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex2f(0, 1); glEnd(); g_system.setPerspectiveMode(); g_system.unbindShader(); glDepthMask(GL_TRUE); g_system.clearTextureUnits(); glDisable(GL_BLEND); } void PostProcess::blit(string source, string dest) { g_system.bindTextureFBO(dest); glDisable(GL_BLEND); glColor3f(1,1,1); fullscreenQuad(source); g_system.unbindFBO(); }

Code: (postprocess_exp.vs) varying vec2 texcoord; void main(void) { texcoord = gl_MultiTexCoord0.st; gl_Position = ftransform(); } (postprocess_exp.fs) varying vec2 texcoord; uniform float expfactor; uniform sampler2D tex0; void main(void) { vec4 texel = texture2D(tex0, texcoord); //calculate luminosity float lum = texel.r * 0.3 + texel.g * 0.59 + texel.b * 0.11; float factor = pow(lum, expfactor); texel.rgb *= factor; gl_FragColor = texel; } (postprocess_blurx.vs) varying vec2 offs0; varying vec2 offs1; varying vec2 offs2; varying vec2 offs3; varying vec2 offs4; uniform float blurscale; void main(void) { //take 5 texels vec2 dx = vec2(blurscale, 0.0); vec2 dx2 = vec2(2.0 * blurscale, 0.0); offs0 = gl_MultiTexCoord0.st - dx2; offs1 = gl_MultiTexCoord0.st - dx; offs2 = gl_MultiTexCoord0.st; offs3 = gl_MultiTexCoord0.st + dx; offs4 = gl_MultiTexCoord0.st + dx2; gl_Position = ftransform(); } (postprocess_blurx.fs) uniform sampler2D tex; varying vec2 offs0; varying vec2 offs1; varying vec2 offs2; varying vec2 offs3; varying vec2 offs4; uniform float bluralpha; void main() { vec4 texel = vec4(0.0, 0.0, 0.0, 0.0); texel += texture2D(tex, offs0) * 0.1; texel += texture2D(tex, offs1) * 0.25; texel += texture2D(tex, offs2) * 0.5; texel += texture2D(tex, offs3) * 0.25; texel += texture2D(tex, offs4) * 0.1; gl_FragColor = texel * bluralpha; } (postprocess_glowcombine.vs) varying vec2 texturecoordinate; void main(void) { texturecoordinate = gl_MultiTexCoord0.st; gl_Position = ftransform(); } (postprocess_glowcombine.fs) uniform sampler2D tex0; uniform sampler2D tex1; varying vec2 texturecoordinate; void main(void) { vec4 normal_texel = texture2D(tex0, texturecoordinate); vec4 glow_texel = texture2D(tex1, texturecoordinate); gl_FragColor = normal_texel + glow_texel; }


The vertical blur is an exact copy of the horizonal blur. My values to start testing on are something like this:
void glow(int steps = 5, float xstep = 0.006f, float ystep = 0.006f, float bluralpha = 0.92f, float glowexp = 0.5f);
added on the 2009-02-18 17:50:48 by Preacher Preacher
ie.

Code: postprocess.init(); renderStuff(); postprocess.glow(5, 0.006f, 0.006f, 0.92f, 0.5f);


I need to make a stack or something for the rendertargets so that I can have multiple ones, but so far this has been sufficient.. (and I'm lazy :))
added on the 2009-02-18 17:52:23 by Preacher Preacher
Yeah !! More than sufficient !!

Thanks a lot. You are Great.
added on the 2009-02-18 17:57:50 by Aeko Aeko
Quote:

Yeah !! More than sufficient !!

Thanks a lot. You are Great.


terrible avatar
((SoSFString *)group->getField("materialType"))->getValue().getString()

puh.
added on the 2009-02-26 13:15:44 by raer raer
mfx();
added on the 2009-03-27 15:41:10 by Preacher Preacher
Code:int CVM::GetCallstack(char* output) { if(stepStack.Level() == 0) return 0; char* outstart = output; int frame = state.frame; void* scrUnwind = stepStack.Top(); for(int i = 0; ; i++) { VM::Context unwind; GetContext(scrUnwind, &unwind); output += sprintf(output, "%s::%s (%s@%d) %s\n", unwind.ns, unwind.function, unwind.script->path, unwind.scriptOffset, (i == 0) ? "<==" : ""); scrUnwind = (void*)state.stack.GetFrame(frame, -2); if(!scrUnwind) break; frame = state.stack.GetFrame(frame, -1); } return output - outstart; }
added on the 2009-03-27 15:56:31 by bartman bartman
- looking at preachers code, it seems I could possibly simplify my code a somewhat...
Code:cRTProxy bg_rt = cRenderTargetManager::get_instance()->getTmpRT( cRenderTargetManager::RTT_FULL );
added on the 2009-03-29 16:11:28 by hornet hornet
I like to do things manually and as simply as possible, though having proper managers etc. would obviously make a lot of difference and allow building more complex things easily. I am moving into a more "complicated" direction though.. less throwaway code and more properly built system code. My Breakpoint demo is kind of a horrible mixture of them both and since time is running out, I resorted into copypasting a lot of stuff :D

And to stay on the topic:

Shader& lighting = g_system.getShader("lighting_pointtexture");
added on the 2009-03-29 17:01:16 by Preacher Preacher
UIView *block = [[[UIView alloc] initwithFrame:CGRectMake(0,0,400,320)] setUserInteraction:FALSE] ;
added on the 2009-03-29 17:36:42 by rmeht rmeht
Code:lpt::BindShader( "billboard_expansion_shader" );

added on the 2009-03-29 17:52:37 by hornet hornet
Code: move.l #$02BDF0,$0C5A+2.w ;Falcon: fix planes fuckup (fucker bug!)
added on the 2009-03-29 20:43:09 by すすれ すすれ
I have NO idea how I managed that. 2nd try:

Code: move.l #$02BDF0,$0C5A+2.w ;Falcon:fix planes fuckup (fucker bug!)
added on the 2009-03-29 20:44:17 by すすれ すすれ
Nope, still wrong, let's lose the code tags then:

move.l #$02BDF0,$0C5A+2.w ;Falcon: fix planes fuckup (fucker bug!)

added on the 2009-03-29 20:45:07 by すすれ すすれ
Code: repeat working := GetState(); if not working then break; { One reason programming languages shouldn't resemble english too much... } until false;
added on the 2009-03-30 10:46:58 by xTr1m xTr1m
...not actually a line but I use this very often ATM :)
Code: move.l d0,d1 ; copy lsl.w #4,d0 ; multiply by 40 lsl.w #3,d1 add.w d0,d0 add.w d1,d0
added on the 2009-03-30 11:42:57 by d0DgE d0DgE
Code:unsigned char *videoram = (unsigned char *) 0xb8000;
added on the 2009-03-30 11:53:10 by wb wb
Code:res = mykml.loadKML(url, debug, savename="")
added on the 2009-03-30 15:07:34 by noname noname
Code: ////////////////////////////////////////////////////////////////////////// // Global environment. // Contain pointers to all global often needed interfaces. // This is a faster way to get interface pointer then calling ISystem interface to retrieve one. // Some pointers can be NULL, use with care. ////////////////////////////////////////////////////////////////////////// struct SSystemGlobalEnvironment { ISystem* pSystem; IGame* pGame; INetwork* pNetwork; IRenderer* pRenderer; IInput* pInput; ITimer* pTimer; IConsole* pConsole; IScriptSystem* pScriptSystem; I3DEngine* p3DEngine; ISoundSystem* pSoundSystem; IMusicSystem* pMusicSystem; IPhysicalWorld* pPhysicalWorld; IMovieSystem* pMovieSystem; IAISystem* pAISystem; IEntitySystem* pEntitySystem; ICryFont* pCryFont; ICryPak* pCryPak; ILog* pLog; ICharacterManager* pCharacterManager; IFrameProfileSystem* pFrameProfileSystem; INameTable* pNameTable; IFlowSystem* pFlowSystem; IAnimationGraphSystem* pAnimationGraphSystem; IDialogSystem* pDialogSystem; IHardwareMouse* pHardwareMouse; IMaterialEffects* pMaterialEffects; ////////////////////////////////////////////////////////////////////////// // Used to tell if this is a server/client/multiplayer instance bool bClient; bool bServer; bool bMultiplayer; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Used by frame profiler. bool bProfilerEnabled; FrameProfilerSectionCallback callbackStartSection; FrameProfilerSectionCallback callbackEndSection; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Indicate Editor status. ////////////////////////////////////////////////////////////////////////// bool bEditor; // Engine is running under editor. bool bEditorGameMode; // Engine is in editor game mode. ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Used by CRY_ASSERT bool bIgnoreAllAsserts; ////////////////////////////////////////////////////////////////////////// SPlatformInfo pi; }; extern SSystemGlobalEnvironment* gEnv;


This is FUUN Oo
added on the 2009-04-08 10:12:44 by vestige vestige
aizen: Hm, lots of virtual functions in cryENGINE? (IBla interfaces...) Isn't that a big performance problem on in-order cpus (360, ps3)?
added on the 2009-04-08 10:33:16 by arm1n arm1n
Yes it is, branch misprediction kills performance on consoles, and they used inheritance very liberally across their codebase. I'm just playing around with CryMOD SDK, so it is outdated code, but my guess is, they reduced number of virtual calls severly, for CryENGINE 3(which basically is CryENGINE 2 which runs on consoles).
added on the 2009-04-08 10:46:35 by vestige vestige
Quote:
Entirely written in modular C++, fully documented and commented, and divided into logical separate DLL's, you can use what you need as-is, and modify or replace only the components in our engine that you particularly require to customize for your individual project requirements.

An most of our code is dependand on this pointer: extern SSystemGlobalEnvironment* gEnv; ^^
added on the 2009-04-08 10:54:27 by vestige vestige
aizen: I guess this shows once again that the "big boys" are no different from anybody else.. Also of course there will be places in the code where it matters more than in other areas
added on the 2009-04-08 11:36:54 by arm1n arm1n
One of my most obscure looking codelines i've ever written while still having sensible meaning when put to a context:
Code:start_blocked ^= (dy<0)^(dx>0)^(tile_diag_2||tile_diag_4);
added on the 2009-04-08 12:25:56 by hhhhhhh hhhhhhh

login

Go to top