Compiling Shaders

Grab your favourite IDE and tinker with the innards of game engines

Re: Compiling Shaders

Postby -=Biohazard=- on Thu May 13, 2010 10:03 pm

No you also need to use buildsdkshaders.bat and shadercompile.exe to actually generate the shaders - what this thread originally was about. But the includes are also generated if the shader compile fails, so you may build the project but the shaders still won't work. What errors can you read in the commandline when you ran the batch file?
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Mystfit on Fri May 14, 2010 2:46 am

Starting to get closer. My vertex shader actually compiled properly this time but for some reason, my pixel shader is being skipped. There are no errors while I run buildsdkshaders.bat and the vertex shader pops up in the list as it goes flying past, but the pixel shader is suspiciously absent.

I'm going to go over the pixel shader code again, just to make sure that there are no errors.
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby Armageddon on Fri May 14, 2010 5:06 am

Why are all these machinima dudes starting to come here?
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Re: Compiling Shaders

Postby Mystfit on Fri May 14, 2010 10:56 am

Armageddon wrote:Why are all these machinima dudes starting to come here?
I'm trying to write a DOF shader for a machinima project that I'm working on. I'm just a bit too impatient to wait for the Source Filmmaker I guess.

And Google led me here when I was researching my compiler woes.
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby -=Biohazard=- on Fri May 14, 2010 5:55 pm

Mystfit wrote:My vertex shader actually compiled properly this time but for some reason, my pixel shader is being skipped. There are no errors while I run buildsdkshaders.bat


That's weird, are you sure that you properly added the entry for the pixelshader in the text file? Also, which shadermodel are you using for the pixelshader?

Mystfit wrote:I'm trying to write a DOF shader for a machinima project that I'm working on.


Hm, you probably need a proper depthbuffer for that. The way I got mine is rendering a second pass to three textures with MRTs so I get worldspace normal, screenspace normal, a skybox mask and depth in alpha; but if you just need depthvalues rendering another time is probably overkill. You can override the fourth float component of pixelshaderconstant 29 to change valves' depthbuffer though - but either requires you to utilize a custom shader on every material in the scene. You can automatically replace all shaders when the map loads, but I figured that this requires a reload of all materials, so all methods I found are just compromises at some point.
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Mystfit on Sat May 15, 2010 6:07 am

I'm just planning on grabbing the built in depth buffer and using it to blend between a downsampled gaussian blurred version of the frame buffer and the unblurred version.

I've been using the paper at http://ati.amd.com/developer/gdc/Scheuermann_DepthOfField.pdf as a guide for planning out how to make the shader, but I have to get past the problem of getting at least one shader working first.

I've decided to take the SDK_Bloom shader and use that as a base to construct a new shader, since it's probably the most basic one out of the lot. However, I'm still getting "shader not found" errors ingame. The material is loading up onto a quad drawn over the screen, but just shows up as a wireframe. The material itself is just a vmt that loads up the shader and sends it the framebuffer. The shader is very basic and just performs a dot product against the framebuffer to get a greyscale version of the pixel.

Here's the new shader code.

post_sepia_ps20.fxc
Code: Select all
#include "common_ps_fxc.h"

sampler TexSampler   : register( s0 );

struct PS_INPUT
{
   HALF2 baseTexCoord            : TEXCOORD0;      // Base texture coordinate
};

float4 main( PS_INPUT i ) : COLOR
{
   float4 pixel = tex2D( TexSampler, i.baseTexCoord );
   float4 result = dot(float3(0.222, 0.707, 0.071), pixel);
   //result.a = 1.0f;
   return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
}



SDK_screenspaceeffect_vs20.fxc
Code: Select all
//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============//

// STATIC: "X360APPCHOOSER" "0..1" [= 0]

#include "common_vs_fxc.h"

struct VS_INPUT
{
   float3 vPos                  : POSITION;
   float2 vBaseTexCoord         : TEXCOORD0;

   #if X360APPCHOOSER
      float4 vColor            : COLOR0;
   #endif
};

struct VS_OUTPUT
{
    float4 projPos               : POSITION;   
   float2 baseTexCoord            : TEXCOORD0;
   float2 ZeroTexCoord            : TEXCOORD1;
   float2 bloomTexCoord            : TEXCOORD2;

   #if X360APPCHOOSER
      float4 vColor            : TEXCOORD3;
   #endif
};

float4 Texel_Sizes : register (SHADER_SPECIFIC_CONST_0);

VS_OUTPUT main( const VS_INPUT v )
{
   VS_OUTPUT o = ( VS_OUTPUT )0;

   o.projPos = float4( v.vPos, 1.0f );
   o.baseTexCoord = v.vBaseTexCoord;
   o.ZeroTexCoord=float2(0,0);
   o.bloomTexCoord.x=v.vBaseTexCoord.x+Texel_Sizes.z;
   o.bloomTexCoord.y=v.vBaseTexCoord.y+Texel_Sizes.w;

   #if X360APPCHOOSER
      o.vColor.rgba = v.vColor.rgba;
      o.projPos.xyzw = mul( float4( v.vPos.xyz, 1.0f ), cModelViewProj );
   #endif

   return o;
}


post_sepia.cpp
Code: Select all
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//

#include "BaseVSShader.h"

#include "SDK_screenspaceeffect_vs20.inc"
#include "post_sepia_ps20.inc"

BEGIN_VS_SHADER_FLAGS( post_sepia, "Help for Sepia", SHADER_NOT_EDITABLE )
   BEGIN_SHADER_PARAMS
      SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "" )
   END_SHADER_PARAMS

   SHADER_INIT
   {
      if( params[FBTEXTURE]->IsDefined() )
      {
         LoadTexture( FBTEXTURE );
      }
   }
   
   SHADER_FALLBACK
   {
      // Requires DX9 + above
      if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
      {
         Assert( 0 );
         return "Wireframe";
      }
      return 0;
   }

   SHADER_DRAW
   {
      SHADOW_STATE
      {
         pShaderShadow->EnableDepthWrites( false );

         pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
         int fmt = VERTEX_POSITION;
         pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );

         // Pre-cache shaders
         DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
         SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );

         if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
         {
            DECLARE_STATIC_PIXEL_SHADER( post_sepia_ps20 );
            SET_STATIC_PIXEL_SHADER( post_sepia_ps20 );
         }
      }

      DYNAMIC_STATE
      {
         BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
         DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
         SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );

         if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
         {
            DECLARE_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
            SET_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
         }
      }
      Draw();
   }
END_SHADER
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby -=Biohazard=- on Sat May 15, 2010 7:11 am

Mystfit wrote:I'm just planning on grabbing the built in depth buffer and using it to blend between a downsampled gaussian blurred version of the frame buffer and the unblurred version.


It only describes a range of about 200 units though.

Do you get an error during compile when you create a syntax error on purpose in post_sepia_ps20.fxc? If you don't you probably added it to the wrong text file, look at the last lines of buildsdkshaders.bat to see which files are actually compiled atm.
On the other hand it might be a copy issue, do you have a post_sepia_ps20.vcs in stdshaders/shaders/fxc?

And does the ingame error print post_sepia_ps20? Maybe for whatever reason g_pHardwareConfig->SupportsPixelShaders_2_b() doesn't return true.
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Mystfit on Sat May 15, 2010 9:18 am

-=Biohazard=- wrote:It only describes a range of about 200 units though.


Oh. Guess that's why r_showdepthoverlay has such a limited range.


I think I've tracked down the problem to "post_sepia.cpp". If I put any other code in there whatsoever, even if it's from another shader it will still say that it can't find the shader ingame. However, putting that code into another one of the SDK shader files WORKS. I'm currently staring at my working overlay ingame after I commented out everything in SDK_Bloom.cpp and replaced it with the code from post_sepia.cpp. I guess this means the stdshader_dx9 project isn't linking the cpp file into the dll or something? My apologies if I've mangled the terminology, I'm still fairly new to C++.

Only other glitch ingame is that it can't seem to load the framebuffer texture, so I'm staring at a greyscale version of the pink checkerboard. Console is saying 'Requesting texture value from var "$fbtexture" which is not a texture value (material: post/post_sepia)'.

This is my current vmt file.
Code: Select all
"SDK_Bloom"
{
   // Original shader: BaseTexture
   "$fbtexture" "_rt_FullFrameFB"
}
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby -=Biohazard=- on Sat May 15, 2010 10:35 am

Mystfit wrote:Oh. Guess that's why r_showdepthoverlay has such a limited range.


I think I've tracked down the problem to "post_sepia.cpp". If I put any other code in there whatsoever, even if it's from another shader it will still say that it can't find the shader ingame.


Hm, so the issue is not even with the actual compiled shader, I guess I missunderstood you then. Did you actually add your cpp to the project? Otherwise it won't be compiled. You can simply copy the content of your shader into sdk_bloom.cpp too though, and still use it as a completely seperate shader.

Mystfit wrote:Only other glitch ingame is that it can't seem to load the framebuffer texture, so I'm staring at a greyscale version of the pink checkerboard. Console is saying 'Requesting texture value from var "$fbtexture" which is not a texture value (material: post/post_sepia)'.

This is my current vmt file.
Code: Select all
"SDK_Bloom"
{
   // Original shader: BaseTexture
   "$fbtexture" "_rt_FullFrameFB"
}


You could also use BindStandardTexture() to bind the framebuffer, that's easier than using a vmt parameter; but I can't see anyhting wrong with what you're using atm...
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Mystfit on Sat May 15, 2010 10:42 am

I'm pretty sure the cpp has been added. I went 'Add Existing' and added the cpp file to the project, and it comes up in the list of items as they're compiling. Is there another place I have to add it as well?

Also, where do I use the BindStandardTexture() function, up in SHADER_INIT ?
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby -=Biohazard=- on Sat May 15, 2010 10:54 am

And you used "post_sepia" in the vmt earlier and that did not work? You would use BindStandardTexture instead of BindTexture in DYNAMIC_STATE.
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Mystfit on Sat May 15, 2010 11:51 am

Got it working at last! I think the problem was that I had my code in the wrong cpp file.

I attached my DoPostShaders function to the CViewRender class and moved everything into viewrender.cpp. Somehow this let it pick up on the framebuffer image (god knows how) and made a lovely little black and white image.

Going back to the DOF shader issue, can't I just make a new shader to grab vertex depth values,scale them to a range, then dump them in the alpha channel of an texture before doing my blurs? I have no idea how to change the existing zdepth shader valve uses and it has an annoying habit of ignoring translucent objects anyway.
User avatar
Mystfit
Member
Member
 
Joined: Thu Dec 06, 2007 10:03 am

Re: Compiling Shaders

Postby -=Biohazard=- on Sat May 15, 2010 11:59 am

Mystfit wrote:Got it working at last! I think the problem was that I had my code in the wrong cpp file.

I attached my DoPostShaders function to the CViewRender class and moved everything into viewrender.cpp. Somehow this let it pick up on the framebuffer image (god knows how) and made a lovely little black and white image.


Put everything into viewpostprocess.cpp "void DoEnginePostProcessing( int x, int y, int w, int h, bool bFlashlightIsOn, bool bPostVGui )" :P

Mystfit wrote:Going back to the DOF shader issue, can't I just make a new shader to grab vertex depth values,scale them to a range, then dump them in the alpha channel of an texture before doing my blurs? I have no idea how to change the existing zdepth shader valve uses and it has an annoying habit of ignoring translucent objects anyway.


Yes, you can do so. But if you want translucency and depth, the depth can't be stored in the alpha channel of course. If you do it that way you could put the depth in another channel then of your custom RT. Also, don't calc the final depth in the vertexshader. The interpolation on that level will cause a faulty output.
User avatar
-=Biohazard=-
Regular
Regular
 
Joined: Mon Apr 07, 2008 11:15 am

Re: Compiling Shaders

Postby Firegod522 on Wed Dec 08, 2010 2:00 am

Sorry for bumping an old thread, but I need some help getting shaders to compile, I've gotten to a point that I've edited my buildsdkshaders.bat, but I'm having this weird perl error, even though I have it installed.

Code: Select all
C:\Jacobsmod\src\materialsystem\stdshaders>buildsdkshaders
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
07:57 PM

07:57 PM
Can't locate String/CRC32.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/li
b .) at ..\..\devtools\bin\updateshaders.pl line 1.
BEGIN failed--compilation aborted at ..\..\devtools\bin\updateshaders.pl line 1.

Building inc files, asm vcs files, and VMPI worklist for stdshader_dx9_20b...
NMAKE :  U1052: file 'makefile.stdshader_dx9_20b' not found
Stop.
'xcopy' is not recognized as an internal or external command,
operable program or batch file.
07:57 PM


07:57 PM
Can't locate String/CRC32.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/li
b .) at ..\..\devtools\bin\updateshaders.pl line 1.
BEGIN failed--compilation aborted at ..\..\devtools\bin\updateshaders.pl line 1.

Building inc files, asm vcs files, and VMPI worklist for stdshader_dx9_30...
NMAKE :  U1052: file 'makefile.stdshader_dx9_30' not found
Stop.
'xcopy' is not recognized as an internal or external command,
operable program or batch file.
07:57 PM


07:57 PM
Can't locate String/CRC32.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/li
b .) at ..\..\devtools\bin\updateshaders.pl line 1.
BEGIN failed--compilation aborted at ..\..\devtools\bin\updateshaders.pl line 1.

Building inc files, asm vcs files, and VMPI worklist for modshaders...
NMAKE :  U1052: file 'makefile.modshaders' not found
Stop.
'xcopy' is not recognized as an internal or external command,
operable program or batch file.
07:57 PM

Press any key to continue . . .


Does anybody have any solutions?
Firegod522
Dumpling
Dumpling
 
Joined: Sun Nov 07, 2010 2:20 pm

Re: Compiling Shaders

Postby Sandern on Thu Dec 09, 2010 3:21 pm

Seems you do not have String/CRC32 installed. If you are using active perl you can install it using the package manager.
Sandern
Regular
Regular
 
Joined: Thu Jun 30, 2005 1:08 pm
Location: Netherlands
Previous

Return to Programming

Who is online

Users browsing this forum: No registered users