Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Level Editor Help Black&White screen effect possible?
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#11
RE: Black&White screen effect possible?

Big Grin LOL. Well, it's no wizardry, I just like to mess around with programming (mostly C#), so having experience with that helps.

I didn't get around testing to see if any of this can actually be applied to a custom story, or at least a full conversion, without messing up the main game - but I have my doubts about that. I think the shader's location is probably hard coded into Amnesia... I noticed that both the shader and color conversion map are loaded only once, when the game is started (you have to restart the game to see effects of any changes made). So, not looking too good so far...
01-02-2013, 01:13 AM
Find Reply
BonesTheRabbit Offline
Member

Posts: 68
Threads: 20
Joined: Feb 2012
Reputation: 2
#12
RE: Black&White screen effect possible?

(01-02-2013, 01:13 AM)TheGreatCthulhu Wrote: Big Grin LOL. Well, it's no wizardry, I just like to mess around with programming (mostly C#), so having experience with that helps.

I didn't get around testing to see if any of this can actually be applied to a custom story, or at least a full conversion, without messing up the main game - but I have my doubts about that. I think the shader's location is probably hard coded into Amnesia... I noticed that both the shader and color conversion map are loaded only once, when the game is started (you have to restart the game to see effects of any changes made). So, not looking too good so far...

Either way, that's some good stuff. I have absolutely no C# background; really just limited to what I've learned from fumbling around with the Amnesia library. As for the shader, I think it might applicable to a full conversion that runs a custom bat file. Not entirely sure. Either way, this is leaps and bounds ahead of where I was. Fingers crossed.
(This post was last modified: 01-02-2013, 01:15 AM by BonesTheRabbit.)
01-02-2013, 01:15 AM
Find Reply
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#13
RE: Black&White screen effect possible?

+rep anyways, good job!

01-02-2013, 04:07 AM
Find Reply
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#14
RE: Black&White screen effect possible?

OK, did some more exploration; we're in luck Big Grin - at least partially: it turn's out that you don't have to replace the colorconv_sepia.tga file - the game uses the first it finds, so if you have your own version, and the file has the same name, but it's in a different folder, it's enough to (don't do this though) add the path to that folder to the resources.cfg file before everytheng else (more specifically, before the "/textures" folder).

Now, since full conversions can be configured to use their own resources.cfg file, a full conversion can use a different color replacement map. I was hoping that something similar can be done with the shader itself, but I don't think so, since it's in the "core" folder.

Although you can't get a grayscale image using the color replacement map alone, you can nevertheless get some pretty interesting effects; check these out:

[Image: 8336640972_145a71fa1b_b.jpg] (large)
(This post was last modified: 01-02-2013, 04:40 AM by TheGreatCthulhu.)
01-02-2013, 04:40 AM
Find Reply
BonesTheRabbit Offline
Member

Posts: 68
Threads: 20
Joined: Feb 2012
Reputation: 2
#15
RE: Black&White screen effect possible?

+Rep again for the alternate screen effects.

Maybe there's a way to script it to run an entirely new shader? Or is that just a no-go? I'm not very familiar with C# or Amnesia scripting (Like I said, just the very basics).
01-02-2013, 05:36 AM
Find Reply
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#16
RE: Black&White screen effect possible?

OK, I figured it out - for full conversions at least.

What I did is this: I modified the GLSL fragment program and the colorconv_sepia.tga file in such a way so that the original sepia effect for the main game can remain unchanged, while allowing for a different effect to be created for a full conversion, just by providing an alternate colorconv_sepia.tga file (withouth overwriting the one in textures\effects\ folder; and without messing whit the GLSL shader any further).

This is the trick - I exploited the fact that the shader uses a 1D color conversion map. So I've doubled the length of the map from 256 to 512, and have split it into two logical regions (still one image file, just different purpose to the left and right side of the image). The left half of the image remains what it was - it's the input color map for the shader. The entire right side should be a single color - any gray shade. The shade of the right side decides if you want to use the original algorithm that came with amnesia (which is based on color conversion) [pure black], or the new one I made (which is based on color replacement, allowing for greyscale and true-sepia images) [pure white], or if you want to mix the two [the shade of gray determines the amount].

This allows for a range of effects, but, of course, once you find the one you like, you can only use that single one for your full conversion, in place of the original sepia effect (without affecting the main game).

IMPORTANT: Make sure to backup any file before replacing it!

Here's the updated shader (just the main() function, download below). Notice that I've improved the code by using GLSL built in functions like dot() and mix():
PHP Code: (Select All)
void main()
{
    
vec3 vDiffuseColor texture2DRect(diffuseMapgl_TexCoord[0].xy).xyz;
    
    
// This is the original sepia shader used for amnesia - color conversion shader
    
vec3 vOutput =  vec3(texture1D(convMapvDiffuseColor.0.5).x,
                   
texture1D(convMapvDiffuseColor.0.5).y,
                 
texture1D(convMapvDiffuseColor.0.5).z);
    
    
float third 1.0 3.0;
    
float gray dot(vDiffuseColorvec3(thirdthirdthird)); // Grayscale value 

    // This is the color-replacement shader
    
vec3 vReplacementColor texture1D(convMapgray 0.5).xyz;
  
    
// the right part of the gradient determines the blend amount between the two shader algorithms; black = 0% , white = 100%
    
float blendAmmount texture1D(convMap0.9).x;  
    

    
vOutput =  mix(vOutputvReplacementColorblendAmmount);
    
    
    @
ifdef UseFadeAlpha
        gl_FragColor
.xyz vOutput*afFadeAlpha vDiffuseColor*(1-afFadeAlpha);
    @else
        
gl_FragColor.xyz vOutput;    
    @endif    


I've also attached several gradient maps for the effects you can see in the image below. To help you find your way around, I used a naming convention for the tga files:
colorconv_sepia.shaderName.conversion.tga
colorconv_sepia.shaderName.replacement.tga

If it ends with "conversion", the game will use the original shader, if it ends with "replacement", the game will use my shader ("conversion" stands for original color-conversion filter, "replacement" for my color-replacement filter.).

Here's what the effects look like (expand to see - it's a somewhat large image):
Spoiler below!
[Image: 8339184378_2273bad6ef_k.jpg]
(large image)

The gradient files are attached below (effect.zip). For the image above, "conversion" filters are on the left, and "replacement" filters are on the right. The files used are, row by row:
gray
gray1
invert
invert1
predator
sepia



Here's how to create the gradient images:
[Image: 8338191203_10b5cee87b_z.jpg]


Installation:

(I'll be refering to "redist" folder - this is for the retail edition; for Steam edition, the appropriate folder is "amnesia the dark descent")

IMPORTANT: Make sure to backup any file before replacing it!

The archive modified_posteffect_color_conv_tex_frag.zip contains the modified shader program. Go to redist\core\shaders, and create a backup of posteffect_color_conv_tex_frag.glsl, then extract the corresponding file from the archive to the same folder, replacing the original.

Now go to redist\textures\effects, and backup the colorconv_sepia.tga file. Download modified_colorconv_sepia.zip, and extract the image file to replace the original one.

That's it.

The effects.zip archive contains colorconv tga-s I used to create the screenshots above. Create some separate folder and extract them. To use one as an effect, you must rename it to colorconv_sepia.tga, and make sure that your full conversion loads it before anything else (by specifying its path as the first entry in the FC's resources.cfg).


------

To temporarily test the shader without creating a full conversion, create some folder inside the redist dir, for example "shader_test"; extract a file of your choice from effects.zip to that folder, and rename it to colorconv_sepia.tga.

Then, from redist folder open resources.cfg in Notepad++ (or just Notepad), and add this line at the top, just under the <Resources> tag (create a backup first):
<Directory Path="/shader_test" AddSubDirs="true" />

Then run the main game or a custom story and invoke the sepia effect (say by calling the FadeSepiaColorTo() script function), to see the new effect.

When done, simply delete colorconv_sepia.tga from shader_test folder (you can also restore resources.cfg). Don't forget to do this, or the main game will stay affected.

NOTE: For the main game not to be affected, it is important that the custom colorconv_sepia.tga file from your full conversion is located in a folder specifically used by the full conversion, so that the main resources file (of the main game) does not reference it! So if you didn't restore resources.cfg, don't put the FC's color conversion gradient into the shader_test folder. Create a different, special-purpose folder for your FC.

------

Using With Full Conversions
When you full conversion is finished and ready, people who download it must also have their shader and gradient map files replaced. This is OK, since their main Amnesia gameplay experience will not be affected, but I recommend for the installation procedure of the full conversion to create a backup for each of the files. This can be done with a BAT file (batch script).

How To Specify a Separate Resource File for a Full Conversion?
You should read the tutorials others made about full conversions, but here's how to do this specific task:
  • Assuming your FC config files are stored in redist/fc_config, and that the FC game is launched by Launcher.exe fc_config/main_init.cfg,
  • Open main_init.cfg;
  • Under <ConfigFiles
  • find the Resources attribute, and set the appropriate path, like this:
  • Resources = "fc_config/resources.cfg".
  • Finally, in FC's resources.cfg add the path to the custom gradient file (colorconv_sepia.tga), as explained above.

Once again:
IMPORTANT: Make sure to backup any file before replacing it!


Attached Files
.zip   modified_posteffect_color_conv_tex_frag.zip (Size: 790 bytes / Downloads: 37)
.zip   effects.zip (Size: 8.52 KB / Downloads: 47)
.zip   modified_colorconv_sepia.zip (Size: 663 bytes / Downloads: 39)
(This post was last modified: 01-03-2013, 01:46 PM by TheGreatCthulhu.)
01-02-2013, 08:33 PM
Find Reply
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#17
RE: Black&White screen effect possible?

Most impressive! This would definately be worth making into a Development Article
01-03-2013, 11:23 AM
Find Reply
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#18
RE: Black&White screen effect possible?

Yea, TheGreatChtulhu is a great dude.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
01-03-2013, 12:01 PM
Find Reply
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#19
RE: Black&White screen effect possible?

(01-03-2013, 11:23 AM)Adrianis Wrote: This would definately be worth making into a Development Article

I would like to wait for a few people to try it out first, just to make sure there aren't any surprises, performance impacts or overlooked bugs, etc...
01-03-2013, 01:42 PM
Find Reply
NaxEla Offline
Senior Member

Posts: 415
Threads: 5
Joined: Dec 2012
Reputation: 28
#20
RE: Black&White screen effect possible?

(01-03-2013, 01:42 PM)TheGreatCthulhu Wrote:
(01-03-2013, 11:23 AM)Adrianis Wrote: This would definately be worth making into a Development Article

I would like to wait for a few people to try it out first, just to make sure there aren't any surprises, performance impacts or overlooked bugs, etc...

u r amazin

In Ruins [WIP]
01-03-2013, 05:30 PM
Find Reply




Users browsing this thread: 1 Guest(s)