Guest User

Untitled

a guest
Apr 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. //----------------------------------------------------------------------------------------------------
  2. // Shader template for [w]tech.
  3. // Copyright (c) [w]tech team.
  4. //----------------------------------------------------------------------------------------------------
  5.  
  6. /** Define this when you want to make use of Tangents and Binormals (Needed for Normal-mapping)*/
  7. #define USE_TAN_BIN
  8.  
  9. /** Define this when you want to modify attributes of the VertexShader (See CustomPreVS()-function) */
  10. //#define USE_CUSTOM_PREVS
  11.  
  12. /** Define if you need access to the viewspace normals: Input.VS_Nrm */
  13. //#define USE_VIEWSPACE_NRM
  14.  
  15. /** Define if you need access to the viewspace vertexposition: Input.VS_Pos */
  16. #define USE_VIEWSPACE_POS
  17.  
  18. /** Un-Define if you know what you are doing and don't want the shader to use Instancing. The engine will most likly try to, though. */
  19. #define USE_INSTANCING
  20.  
  21. #include <ShaderObject.fxh>
  22.  
  23. class UserShaderObject : ShaderObject
  24. {
  25.         // ----------- PIXEL SHADER -----------
  26.         /** User defined scene-pixelshader (Outputs only one float4 for simplicity) */
  27.         float4 UserScenePixelShader()
  28.         {
  29.                 float3 Color = GetDiffuseLighting();            // get lighting
  30.  
  31.         /** bluring of lighting */
  32.  
  33.                 float3 l=0;
  34.        
  35.                 const int step = 16;
  36.                 const int ns=25*step/3;
  37.  
  38.         for(int y=-ns/2; y<ns/2; y+=step)
  39.                 {
  40.                         for(int x=-ns/2; x<ns/2; x+=step)
  41.                         {      
  42.                                 float2 Offset = (float2(x,y)/ViewportSize);
  43.                 Offset /= max(psInput.VS_Pos.z * 0.5, 0.1);
  44.                                 Offset *= saturate(0.2+(abs(Tex(Tex2).rg*2-1)));
  45.                 Offset *=  (1-Fresnel(vsNRM));
  46.                                 l+=LightBuffer.Sample(samLinear, SCREEN_UV+Offset).rgb;
  47.                         }
  48.                 }
  49.                
  50.                 l/= (ns/step)*(ns/step);
  51.        
  52.         /** use blured lighting */
  53.  
  54.        
  55.                 l = float3  (  
  56.                         0.9*l.b + 0.25*l.g, // convert blue and green light to red
  57.                         0.7*l.b +0.2*l.g,   // absorb green light
  58.                         0.8*l.b + 0.8*l.g   // absorb blue light
  59.                     );
  60.      
  61.         //l = GetDiffuseLighting();
  62.        
  63.         l.r += 0.1 * l.b; // Blau zu Rot
  64.         l.g += 0.2 * l.b; // Blau zu Grün
  65.         l.b -= 0.3 * l.b; // Blau abziehen
  66.         l.r +=0.1 * l.g;
  67.         l.b += 0.1 * l.g;
  68.         l.g -= 0.2 * l.g;
  69.  
  70.         Color = float3(0.75,0.9,1) * pow(abs(Tex(Tex1).rgb),1);     // some skin details
  71.         Color += 0.25*Fresnel(vsNRM);   // protect edges
  72.         Color *= l; // HIER KANNST DU SSS TESTEN
  73.                 Color += 0.15*GetSpecularLighting();            // add specular
  74.  
  75.                 return float4(Color, 1);                // return result
  76.        
  77.     }
  78.         /** User defined function for getting the Normals */
  79.         float3 GetNormals()
  80.         {
  81.                 float3 Normals = Tex(Tex2).rgb;                 // get normal map
  82.                 Normals= NrmMap(Normals);               // convert normal map
  83.         Normals += NrmMapD(TexUV(Tex3, UV*8).rgb,2);
  84.         Normals/=2;
  85.                 return Normals;                         // return normals
  86.         }
  87.  
  88.         /** User defined function for getting the specular power */
  89.         float GetSpecularPower()
  90.         {
  91.                 return 50;
  92.         }
  93.  
  94.         // ----------- VERTEX SHADER -----------
  95.         /** Runs before the VertexShader transforms the vertices */
  96.         VertexShaderInput PreVertexShader(VertexShaderInput vsInput)
  97.         {
  98.                 return vsInput;
  99.         }
  100.  
  101.         /** Runs after the VertexShader has transformed the vertices */
  102.         PixelShaderInput PostVertexShader(PixelShaderInput psInput)
  103.         {
  104.                 return psInput;
  105.         }
  106. };
  107.  
  108. #include <MainShader.fx>
Add Comment
Please, Sign In to add comment