Please use english language
It is currently 18 Dec 2017, 06:57

All times are UTC


Forum rules


new topics are not allowed in this subsection, only replies.




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Depth visualisation
PostPosted: 05 Nov 2013, 09:27 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 11600
Location: St.Petersburg
Shader use enbeffectprepass.fx shader to output depth data. Temporal variable F1 used for manual scaling inside the game.

Code:
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ENBSeries effect file
// visit http://enbdev.com for updates
// Copyright (c) 2007-2013 Boris Vorontsov
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



//+++++++++++++++++++++++++++++
//internal parameters, can be modified
//+++++++++++++++++++++++++++++
float   EBlurSamplingRange=4.0;
float   EApertureScale=4.0;



//+++++++++++++++++++++++++++++
//external parameters, do not modify
//+++++++++++++++++++++++++++++
//keyboard controlled temporary variables (in some versions exists in the config file). Press and hold key 1,2,3...8 together with PageUp or PageDown to modify. By default all set to 1.0
float4   tempF1; //0,1,2,3
float4   tempF2; //5,6,7,8
float4   tempF3; //9,0
//x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
float4   ScreenSize;
//x=generic timer in range 0..1, period of 16777216 ms (4.6 hours), w=frame time elapsed (in seconds)
float4   Timer;
//changes in range 0..1, 0 means that night time, 1 - day time
float   ENightDayFactor;
//changes 0 or 1. 0 means that exterior, 1 - interior
float   EInteriorFactor;
//adaptation delta time for focusing
float   FadeFactor;
//fov in degrees
float   FieldOfView;



//textures
texture2D texColor;
texture2D texDepth;
texture2D texNoise;
texture2D texPalette;
texture2D texFocus; //computed focusing depth
texture2D texCurr; //4*4 texture for focusing
texture2D texPrev; //4*4 texture for focusing

sampler2D SamplerColor = sampler_state
{
   Texture   = <texColor>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = NONE;//NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

sampler2D SamplerDepth = sampler_state
{
   Texture   = <texDepth>;
   MinFilter = POINT;
   MagFilter = POINT;
   MipFilter = NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

sampler2D SamplerNoise = sampler_state
{
   Texture   = <texNoise>;
   MinFilter = POINT;
   MagFilter = POINT;
   MipFilter = NONE;//NONE;
   AddressU  = Wrap;
   AddressV  = Wrap;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

sampler2D SamplerPalette = sampler_state
{
   Texture   = <texPalette>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = NONE;//NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

//for focus computation
sampler2D SamplerCurr = sampler_state
{
   Texture   = <texCurr>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = LINEAR;//NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

//for focus computation
sampler2D SamplerPrev = sampler_state
{
   Texture   = <texPrev>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};
//for dof only in PostProcess techniques
sampler2D SamplerFocus = sampler_state
{
   Texture   = <texFocus>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = NONE;
   AddressU  = Clamp;
   AddressV  = Clamp;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};

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

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



////////////////////////////////////////////////////////////////////
//begin focusing code
////////////////////////////////////////////////////////////////////
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VS_OUTPUT_POST VS_Focus(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;
}



//SRCpass1X=ScreenWidth;
//SRCpass1Y=ScreenHeight;
//DESTpass2X=4;
//DESTpass2Y=4;
float4 PS_ReadFocus(VS_OUTPUT_POST IN) : COLOR
{
   float2 uvsrc=IN.txcoord.xy;

   const float2 offset[4]=
   {
      float2(0.0, 0.3),
      float2(0.0, -0.3),
      float2(0.3, 0.0),
      float2(-0.3, 0.0)
   };

   float res=tex2D(SamplerDepth, uvsrc).x;
   for (int i=0; i<4; i++)
   {
      uvsrc.xy=offset[i];
      uvsrc.xy+=IN.txcoord;
      res+=tex2D(SamplerDepth, uvsrc).x;
   }
   res*=0.2;

   return res;
}



//SRCpass1X=4;
//SRCpass1Y=4;
//DESTpass2X=4;
//DESTpass2Y=4;
float4 PS_WriteFocus(VS_OUTPUT_POST IN) : COLOR
{
   float2 uvsrc=0.0;//IN.txcoord0.xy;

   //const float pixsizex=4.0;
//   uvsrc.xy-=(0.5+0.0625)/4.0;
//   const float step=0.125/4.0;
   float   pos=0.0001;
   float   res=0.0;
   float   curr=0.0;
   float   prev=0.0;
   float   currmax=0.0;
   float   prevmax=0.0;
   for (int ix=0; ix<16; ix++)
   {
      float   tcurr=tex2D(SamplerCurr, (uvsrc.xy*0.25+0.125)).x;//the same for all 4 pixels
      float   tprev=tex2D(SamplerPrev, (uvsrc.xy*0.25+0.125)).x;//the same for all 4 pixels
      currmax=max(currmax, tcurr);
      prevmax=max(prevmax, tprev);
      curr+=tcurr;
      prev+=tprev;
      uvsrc.x+=1.0;
      if (uvsrc.x>4.0)
      {
         uvsrc.x=0.0;
         uvsrc.y+=1.0;
      }
   }
   curr*=0.0625;
   prev*=0.0625;

   res=lerp(prev, curr, saturate(FadeFactor));//time elapsed factor
   res=max(res, 0.0);

   return res;
}



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique ReadFocus
{
   pass P0
   {
      VertexShader = compile vs_3_0 VS_Focus();
      PixelShader  = compile ps_3_0 PS_ReadFocus();

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



technique WriteFocus
{
   pass P0
   {
      VertexShader = compile vs_3_0 VS_Focus();
      PixelShader  = compile ps_3_0 PS_WriteFocus();

      ZEnable=FALSE;
      CullMode=NONE;
      ALPHATESTENABLE=FALSE;
      SEPARATEALPHABLENDENABLE=FALSE;
      AlphaBlendEnable=FALSE;
      FogEnable=FALSE;
      SRGBWRITEENABLE=FALSE;
   }
}
////////////////////////////////////////////////////////////////////
//end focusing 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;
}



float4 PS_ProcessPass1(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
   float4 res;
   float2 coord=IN.txcoord.xy;

   float   Scaling=0.005 * pow(tempF1.x, 4.0);//TODO edit this, pow 4 used for faster changes

   float   scenedepth=tex2D(SamplerDepth, IN.txcoord.xy).x;
   //to linear
   res=Scaling/(max(1.0-scenedepth, 0.00000000001));
   res=1-res.x;//invert, could be 1/res.x, but it's non linear
   if (scenedepth>0.99999) res=1.0;//white for infinite distance
   res=min(res, 1.0);//max is white
   res=max(res, 0.0);//min is black

   res.w=1.0;
   return res;
}



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique PostProcess
{
   pass P0
   {

      VertexShader = compile vs_3_0 VS_PostProcess();
      PixelShader  = compile ps_3_0 PS_ProcessPass1();

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

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
Tomoko
 Post subject: Re: Depth visualisation
PostPosted: 05 Nov 2013, 11:09 
Offline

Joined: 01 Nov 2013, 12:12
Posts: 10
Amazing, thanks alot! The only minor problem is that the sky is shown as white, but it's pretty easy to work around in post i believe.

Edit: But if there is a way to make the sky black, that would of course be helpfull and it would save some time and struggle in post.


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 05 Nov 2013, 21:10 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 11600
Location: St.Petersburg
You've asked result with white background on screenshot, i did it. If you don't need it, simply delete the line
Code:
if (scenedepth>0.99999) res=1.0;//white for infinite distance

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 05 Nov 2013, 23:10 
Offline

Joined: 01 Nov 2013, 12:12
Posts: 10
ENBSeries wrote:
You've asked result with white background on screenshot, i did it. If you don't need it, simply delete the line
Code:
if (scenedepth>0.99999) res=1.0;//white for infinite distance

Yeah that image was a bad example, sorry about that. Good thing i just learned how to use that command though, sometimes it's good to use a slight gray color for sky to blend well with the horizon.
Just tried 1/res.x instead of the linear 1-res.x and the gradient is alot better, you can tell individual grass apart over long distances with this.

Do you have code for visualisation of other effects such as AO only and detailed shadows only?


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 06 Nov 2013, 07:46 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 11600
Location: St.Petersburg
It's the mod, not debugging something and will never be.

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 06 Nov 2013, 09:21 
Offline

Joined: 01 Nov 2013, 12:12
Posts: 10
ENBSeries wrote:
It's the mod, not debugging something and will never be.

I think you misunderstood something I wrote, there's no need for any debugging. The depth visualisation code works perfectly.


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 19 Nov 2013, 01:05 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 11600
Location: St.Petersburg
Dummy post

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 15 Dec 2013, 10:38 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 31 Mar 2012, 15:06
Posts: 1439
Location: France
Ohhhh, I missed this..... Shall have a look....
Thanx for this, Boris !

_________________
Obsidian 900D, AX1500i, i7 6850K@4.425 Ghz, MSI X99 Raider, SLI 2x1080Ti 11G VRAM, 32G RAM@3371, 950 Pro M2, 11 Tb HDDs, W10 Pro 64, Full Watercooling
Image
K ENB Pure Light SE
K ENB Pure Light
Kountervibe ENB
Kinematic ENB


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 02 Sep 2016, 05:11 
Offline

Joined: 20 May 2012, 13:34
Posts: 66
how to use this code with enb fallout 4 ?


Top
 Profile  
 
 Post subject: Re: Depth visualisation
PostPosted: 02 Sep 2016, 09:29 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 11600
Location: St.Petersburg
This code is for reading depth in the enbeffect.fx of Fallout 4
Code:
color=TextureDepth.Sample(Sampler0, IN.txcoord0.xy);

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group