Quantcast

Jump to content

» «
Photo

[SA]Basic guide to the ENBSeries effect.txt shader

12 replies to this topic
Marty McFly
  • Marty McFly

    such fancy, very shaders, so enb, wow

  • Feroci
  • Joined: 07 Nov 2010
  • None

#1

Posted 25 July 2013 - 01:33 PM Edited by Marty McFly, 30 July 2013 - 05:12 PM.

Ok, so I guess I'll start straight away. I'll try to be as precise as possible. It's my personal understanding, hopefully they are all correct or at least not misleading. Also I'm a bad explanator, excuse this, I'm no native english speaker also, I'll try to make as less mistakes as possible.


What I'll explain here is the structure of the code, develop an own short exposure shader (with basic explanation of the language HLSL). Also I'll upload the finished file AND a basic file where main structure is there but the pixel shader does nothing by default, good to get started.

Introduction
effect.txt is a shader plugin which is loaded by ENBSeries. Nothing special has to be done to make ENB loading it, placing the file into same folder like d3d9.dll and enbseries.ini etc will do the job. This little (or big file) is really powerful. Think of it as a customizeable slot that Boris Vorontsov left for us to develop a plugin. It is the almost last stage where post processing happens, after all normal ENB effects like shadows, water, bumpmapping etc. The file is written in HLSL, that's the shader language of DirectX, very similiar to C.

There has been a mess about multipass/singlepass, I'll explain later what that is.


Structure
First of all, there has to be input given. How? Through so called "textures", effect.txt for SA has access to those:

CODE
texture2D texColor; (=color input)
texture2D texDepth;(=depth texture, used to get distance from camera n such for effects like DOF or SSAO)
texture2D texNoise; (=some kind of random texture for image grain used)



These have to be sampled with so called "samplers", like here:

CODE
sampler2D InputSampler = sampler_state
{
   Texture = (texColor); (here you see the texture)
   MinFilter = POINT;
   MagFilter = POINT;
   MipFilter = POINT;
   AddressU   = Clamp;
AddressV   = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};


For now on, when referring to color, the "InputSampler" is used. You can name it whatever you want, "Iamasampler123" would also work. But better let it be like it is.


Now comes the struct, keep your fingers away from it, it has to be like this:

CODE
struct VS_OUTPUT_POST {
float4 vpos  : POSITION;
float2 txcoord : TEXCOORD0;
};

struct VS_INPUT_POST {
float3 pos  : POSITION;
float2 txcoord : TEXCOORD0;
};



A following important thing is the Vertex Shader. It can manipulate image with some geometry info, rather than treat the image as a flat paint. I am not good at vertex shader, besides it's rarely used in this stage of post processing. I'll just skip it.



CODE
VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
VS_OUTPUT_POST OUT;

float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

OUT.vpos=pos;
OUT.txcoord.xy=IN.txcoord.xy;

return OUT;
}



Then comes the pixel shader, important! Here is everything where 99% of the magic happens and what I modify to create new effects. Later more, so here no explanation code.


At the very end, the shader(s) are wrapped in a technique, it is called "technique" or "compiler" but it's no actual one, it links vertex with pixel shader and some interpretations the ENB binary (the d3d9.dll) needs.

CODE
technique PostProcess
{
   pass P0
   {
VertexShader = compile vs_3_0 VS_PostProcess(); (=vertex shader title, here "VS_PP")
PixelShader  = compile ps_3_0 main(); (pixel shader title, here "main")


ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}



The code itself, basic explanations
To create own shaders, I'll explain some data types, operations, syntax n stuff. I can't cover everything, that'd be too much.

DATA TYPES
  • float
    This is the data type which is used most. Its can be every rational number, also with commas such as 3.0, 255.43453, -1000.4 or such.
  • int
    Mostly used for stuff like passes, it can only be full numbers like 2, 4, 100, -34464 or 99999 or such. Used for counts, if something does the same thing all over again and again, you can tell the shader "do this X times". Half times or 1/3 or whatever won't work.
  • bool
    Also often used, can only be 1 or 0, true or false. You already know this thing! EnableShadows or EnableWater, AlternativeDepth or UseMRTRendering from enbseries.ini are booleans. Can only be enabled or true (1) or disabled/false (0).
HLSL has some specific stuff like float2, float3 and float4. It basically means that a variable which is a float2 has not one number but 2. To get X and Y coordinates I can create 2 new variables, one for X and one for Y coordinate OR I can create only one variable from type float2 whose one component is X coordinate and second is Y coordinate. In effect.txt, for example the stuff around COLOR is a float4 whose 4 components represent Red, Green and Blue channels and the fourth is alpha channel which means transparency. To access the first value of a float4 named asdf, we use this: asdf.x, for the others y z and w.

To set up a new variable, there are several ways. I'll create a variable named "gtaforums" from data type float.
CODE

float gtaforums = 5.0;


as you can see, the line ends with ";". Most shader lines end with that, it determines that a new line begins. What this above does is creating the new variable, say it is a float and give the value, here 5.0. I can also write:

CODE
float gtaforums; (which firstly doesn't give it any value)
gtaforums = 5.0; (which now uses the given variable and sets it to 5)


What doesn't work is:

CODE

gtaforums = 5.0;
float gtaforums;  (wrong order since shaders are read from top to bottom)

or

float gtaforums;
float gtaforums = 5.0; (gtaforums is already set as variable, doing this again isn't valid.


Now we modify that value! Let's multiplicate it with 2.5:


CODE
gtaforums = gtaforums *2.5; (now gtaforums doesn't have the value 5 but 12.5)

or

gtaforums *= 2.5; (combining = and math operator works for +-/*)

OR we insert a new variable:

float multiplicator = 2.5; (since we have 2.5, bool or int don't work)

gtaforums *= multiplicator;



ADD COMMENTS


To exclude a line, just write "//" in front of it. Anything after taht will be ignored by the shader. To exclude a block,, use "/*" and "*/" like here:

CODE
enabledenabled//disableddisableddisabled

and

/*
disableddisabled
disableddisabled
disableddisabled
disableddisabled
disableddisabled
disableddisabled
*/



-----------------------

I think this will do, the rest does google wink.gif


Pixel Shader
Sooo finally, we begin with actual shader writing. Go grab this code:

http://pastebin.com/aVzWqRcJ

It's a raw effect.txt with every struct, vertex shader, technique n all and a pixel shader but this pixel shader doesn't modify anything by default.
Look after "START HERE WITH YOUR OWN MAGIC" there you can begin.


As you can see, I gave you a variable named color, since we want to modify the color of the screen. It's linked the sampled texColor (InputSampler) and the pixel coordinates (IN.txcoord) so it represents in RGBA the color of every pixel. Let's multiply it:

CODE
float4 color = tex2D(InputSampler, IN.txcoord);

color *= 2;

color.w=1; //sets transparency to off
return color; //returns the values to the screen. if you return 0 for example, you have blackscreen.


Result is 2 times brighter screen! What you or we did is a simple exposure control shader. Let's add a control value, we call it "Exposure":


CODE
float4 color = tex2D(InputSampler, IN.txcoord);

float Exposure = 2.0;
color *= Exposure;

color.w=1;
return color;


Now we don't want to make ALL channels brighter, only RED! Muahaha. Red is represented by the first value of the float4:


CODE
float4 color = tex2D(InputSampler, IN.txcoord);

float Exposure = 1.0;
float RedExposure = 2.0; //control for red

color *= Exposure;
color.x *= RedExposure; //multiplies x value of color, here red.

color.w=1;
return color;


Results in red tinted screen. We want to create a full control for all channels:

CODE
float4 color = tex2D(InputSampler, IN.txcoord);

float Exposure = 1.0;
float RedExposure = 2.0; //control for red
float GreenExposure = 2.0; //control for green
float BlueExposure = 2.0;//control for blue

color *= Exposure;
color.x *= RedExposure; //multiplies x value of color, here red.
color.y *= RedExposure; //multiplies y value of color, here green.
color.z *= RedExposure; //multiplies z value of color, here blue.

color.w=1;
return color;


Now we have a shader that controls general exposure/brightness and for every channel. With own control values! So we can create a blue tint or a violet tint or whatever!




This is the basic for a short shader. With this knowledge, next time I'll take a finished shader, tear it apart and explain what each thing does.
  • FMHn and Concavax like this

Marty McFly
  • Marty McFly

    such fancy, very shaders, so enb, wow

  • Feroci
  • Joined: 07 Nov 2010
  • None

#2

Posted 27 July 2013 - 06:18 PM

Preserved

alayanrole
  • alayanrole

    El Danza Kuduro!

  • Members
  • Joined: 20 May 2011
  • None

#3

Posted 27 July 2013 - 10:26 PM

whoo.. good TUT. going to learn 'bout this

PacketOVerload_x64Bit
  • PacketOVerload_x64Bit

    Window Licker 4 Blondes

  • Members
  • Joined: 13 Mar 2010
  • Canada

#4

Posted 29 July 2013 - 10:56 PM

Cool Marty, will give it a good read when I get home from work. Also, I heard if you decompile the d3d9 the ENB d3d9.dll can actually read another enbseries.ini file. Do you know how to decompile it? Mr LaGlace used that process to analyze the min and max of the d3d9.dll.

icon14.gif cookie.gif
-P

Marty McFly
  • Marty McFly

    such fancy, very shaders, so enb, wow

  • Feroci
  • Joined: 07 Nov 2010
  • None

#5

Posted 30 July 2013 - 09:27 AM

QUOTE (PacketOVerload_x64Bit @ Monday, Jul 29 2013, 22:56)
Cool Marty, will give it a good read when I get home from work. Also, I heard if you decompile the d3d9 the ENB d3d9.dll can actually read another enbseries.ini file. Do you know how to decompile it? Mr LaGlace used that process to analyze the min and max of the d3d9.dll.

icon14.gif cookie.gif
-P

Nah, this was something different, we used this structure because we had no multicast on old enb versions:

D3d9.dll loads enbseries.ini, effect.txt and via proxy d3d2.dll

D3d2 was same enb dll hex edited to load other file names so:

D3d2.dll loads enbseriesA.ini, effect2.txt and via proxy d3d3.dll
D3d3.dll loads enbseriesB.ini, effect3.txt and via proxy d3d4.dll

Result was multiple times loaded enb's (always 0.075) so we could iron out the lack of multipass support with multi effect.txts with one pass each.

Since 0.076 is out, we don't need this any more because all shaders can be combined.

Also, the newer enb versions are encrypted so hex editing doesn't work anymore. I was able to find the strings for the file names with IDA Pro but I saw no sense modifying them. But I think icelaglace used the same program to find the min max values, although his dlls aren't hex edited to load iceconfig instead of enbseries.ini because also the enbseries logo is missing at startup of gta iv which can't be achieved with hex editing.

Michael_Xiong
  • Michael_Xiong

    Player Hater

  • Members
  • Joined: 30 Jul 2013

#6

Posted 30 July 2013 - 03:52 PM

icon14.gif I had translated your post into Chinese.So,can I post it on www.gtabbs.com? dozingoff.gif
For sure I will mention your name and indicate “Copyright : Marty McFly” tounge2.gif

Michael_Xiong
  • Michael_Xiong

    Player Hater

  • Members
  • Joined: 30 Jul 2013

#7

Posted 30 July 2013 - 04:23 PM

Oh...I have a question.
"*" means "Multiply",but in this line,you said it means "plus"?

CODE
gtaforums = gtaforums *2.5; (now gtaforums doesn't have the value 5 but 7.5)


5*2.5=7.5
Is it a mistake?

Marty McFly
  • Marty McFly

    such fancy, very shaders, so enb, wow

  • Feroci
  • Joined: 07 Nov 2010
  • None

#8

Posted 30 July 2013 - 05:10 PM Edited by Marty McFly, 30 July 2013 - 06:02 PM.

QUOTE (Michael_Xiong @ Tuesday, Jul 30 2013, 16:23)
Oh...I have a question.
"*" means "Multiply",but in this line,you said it means "plus"?

CODE
gtaforums = gtaforums *2.5; (now gtaforums doesn't have the value 5 but 7.5)


5*2.5=7.5
Is it a mistake?

Yes, this is a mistake xD, fixed now. And sure, you can post it, I'd like to see the finished post since I visit gtabbs frequently.

Michael_Xiong
  • Michael_Xiong

    Player Hater

  • Members
  • Joined: 30 Jul 2013

#9

Posted 31 July 2013 - 10:28 AM

QUOTE (Marty McFly @ Tuesday, Jul 30 2013, 17:10)
QUOTE (Michael_Xiong @ Tuesday, Jul 30 2013, 16:23)
Oh...I have a question.
"*" means "Multiply",but in this line,you said it means "plus"?

CODE
gtaforums = gtaforums *2.5; (now gtaforums doesn't have the value 5 but 7.5)


5*2.5=7.5
Is it a mistake?

Yes, this is a mistake xD, fixed now. And sure, you can post it, I'd like to see the finished post since I visit gtabbs frequently.

Thanks! inlove.gif
http://www.gtabbs.co...id-2903189.html
↑↑↑link of my post.

Michael_Xiong
  • Michael_Xiong

    Player Hater

  • Members
  • Joined: 30 Jul 2013

#10

Posted 31 July 2013 - 12:01 PM

And when will you release the next part of this tutorial? dozingoff.gif
I can not wait tounge2.gif

Marty McFly
  • Marty McFly

    such fancy, very shaders, so enb, wow

  • Feroci
  • Joined: 07 Nov 2010
  • None

#11

Posted 31 July 2013 - 04:58 PM

QUOTE (Michael_Xiong @ Wednesday, Jul 31 2013, 12:01)
And when will you release the next part of this tutorial? dozingoff.gif
I can not wait tounge2.gif

I'm working on it, I'm learning new stuff atm and relearn old stuff to be as precise as possible.

FMHn
  • FMHn

    kinurrrrrr

  • Members
  • Joined: 31 Aug 2013

#12

Posted 06 January 2014 - 02:28 AM

Hello marty! Sorry for a Out Off Topic reply, but possibly to create shader (i mean HLSL) on rendermonkey?
but, how to import that shader to GTA sa? I don't know how that shader work, especialy SSAO shader,
realy interesting to learn how create shader! :D

i realy like if you update this thread and more significant, btw thanks for guide! :)

realy goodwork man keep it up!
(sorry didn't reply your message now, back to collage)

jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#13

Posted 28 April 2014 - 06:29 AM

nice! looking for a simple tutorial of hlsl shaders finally I found this one :D
could you be kind enough to explain, how to create shaders for this plugin;
 
and I'm wondering, it is possible create shader for water in this way?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users