add game&rawdata

This commit is contained in:
Vasily Petrov 2026-06-17 23:06:51 +03:00
parent 0133cd976c
commit 49b34b5546
45731 changed files with 709831 additions and 0 deletions

38
gamedata/shaders/r2/.lua Normal file
View file

@ -0,0 +1,38 @@
function printf(fmt, ...)
log(string.format(fmt, unpack(arg)))
end
--[[
t_point_att = "internal\\internal_light_attpoint"
function r1_lspot (shader, t_base, vs, aref)
shader:begin (vs,"add_spot")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture ("internal\\internal_light_att")
: clamp ()
: f_linear ()
: project (true)
shader:sampler ("s_att") :texture ("internal\\internal_light_attclip")
: clamp ()
: f_linear ()
end
function r1_lpoint (shader, t_base, vs, aref)
shader:begin (vs,"add_point")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture (t_point_att)
: clamp ()
: f_linear ()
shader:sampler ("s_att") :texture (t_point_att)
: clamp ()
: f_linear ()
end
]] --

38
gamedata/shaders/r2/.s Normal file
View file

@ -0,0 +1,38 @@
function printf(fmt,...)
log(string.format(fmt,unpack(arg)))
end
--[[
t_point_att = "internal\\internal_light_attpoint"
function r1_lspot (shader, t_base, vs, aref)
shader:begin (vs,"add_spot")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture ("internal\\internal_light_att")
: clamp ()
: f_linear ()
: project (true)
shader:sampler ("s_att") :texture ("internal\\internal_light_attclip")
: clamp ()
: f_linear ()
end
function r1_lpoint (shader, t_base, vs, aref)
shader:begin (vs,"add_point")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture (t_point_att)
: clamp ()
: f_linear ()
shader:sampler ("s_att") :texture (t_point_att)
: clamp ()
: f_linear ()
end
]]--

View file

@ -0,0 +1,50 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
//////////////////////////////////////////////////////////////////////////////////////////
// This is the basic primitive used by convex, volumetric lights
// for example spot-lights, one face of the omni lights, etc.
//////////////////////////////////////////////////////////////////////////////////////////
// following options are available to configure compilation:
// USE_LMAP
// USE_LMAPXFORM
// USE_SHADOW
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 m_lmap [2] ;
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc);
half4 _N = tex2Dproj (s_normal, tc);
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
// ----- light-model
half rsqr;
half4 light = plight_local (m, _P, _N, Ldynamic_pos, Ldynamic_pos.w, rsqr);
// ----- shadow
half4 P4 = half4 (_P.x,_P.y,_P.z,1);
float4 PS = mul (m_shadow, P4);
half s = 1.h;
#ifdef USE_SHADOW
#ifdef USE_SJITTER
s = shadowtest (PS,tcJ);
#else
s = shadow (PS);
#endif
#endif
// ----- lightmap
half4 lightmap= 1.h;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot (P4, m_lmap[0]);
PS.y = dot (P4, m_lmap[1]);
#endif
lightmap= tex2Dproj (s_lmap, PS); //
#endif
return blendp (Ldynamic_color * light * s * lightmap, tc);
}

View file

@ -0,0 +1,51 @@
#include "common.hlsli"
#include "lmodel.hlsli"
#include "shadow.hlsli"
//////////////////////////////////////////////////////////////////////////////////////////
// This is the basic primitive used by convex, volumetric lights
// for example spot-lights, one face of the omni lights, etc.
//////////////////////////////////////////////////////////////////////////////////////////
// following options are available to configure compilation:
// USE_LMAP
// USE_LMAPXFORM
// USE_SHADOW
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 m_lmap[2];
float4 main(float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1) : COLOR
{
float4 _P = tex2Dproj(s_position, tc);
float4 _N = tex2Dproj(s_normal, tc);
_P.xyz += normalize(_N.xyz) * 0.025f;
float m = xmaterial;
#ifndef USE_R2_STATIC_SUN
m = _P.w;
#endif
// ----- light-model
float rsqr;
float4 light = plight_local(m, _P, _N, Ldynamic_pos, Ldynamic_pos.w, rsqr);
// ----- shadow
float4 P4 = float4(_P.x, _P.y, _P.z, 1.0f);
float4 PS = mul(m_shadow, P4);
float s = 1.0f;
#ifdef USE_SHADOW
s = shadow(PS);
#endif
// ----- lightmap
float4 lightmap = 1.0f;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot(P4, m_lmap[0]);
PS.y = dot(P4, m_lmap[1]);
#endif
lightmap = tex2Dlod(s_lmap, float4(PS.xy / PS.w, 0.0f, 0.0f)); //
#endif
return blendp(Ldynamic_color * light * s * lightmap, tc);
}

View file

@ -0,0 +1,6 @@
#include "common.h"
half4 main ( p_flat I ) : COLOR
{
return half4 (1,1,1,1)*16.0h;
}

View file

@ -0,0 +1,6 @@
#include "common.hlsli"
float4 main(p_flat I) : COLOR
{
return float4(1.0f, 1.0f, 1.0f, 1.0f) * 16.0f;
}

View file

@ -0,0 +1,6 @@
#include "common.h"
half4 main ( p_flat I ) : COLOR
{
return half4 (1,1,1,0)*1.0h;
}

View file

@ -0,0 +1,6 @@
#include "common.hlsli"
float4 main(p_flat I) : COLOR
{
return float4(1.0f, 1.0f, 1.0f, 0.0f) * 1.0f;
}

View file

@ -0,0 +1,22 @@
#include "common.h"
#include "lmodel.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
// Note: this is a half-sphere
uniform half3 direction;
half4 main ( float4 tc:TEXCOORD0 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc);
half4 _N = tex2Dproj (s_normal, tc);
half3 L2P = _P.xyz - Ldynamic_pos.xyz; // light2point
half3 L2P_N = normalize (L2P); // light2point
half rsqr = dot (L2P,L2P); // distance 2 light (squared)
half att = saturate (1 - rsqr*Ldynamic_pos.w); // q-linear attenuate
half light = saturate (dot(-L2P_N,_N.xyz));
half hemi = saturate (dot(L2P_N, direction));
// Final color
return blendp (half4(Ldynamic_color.xyz * att * light * hemi, 0), tc);
}

View file

@ -0,0 +1,22 @@
#include "common.hlsli"
#include "lmodel.hlsli"
// Pixel
// Note: this is a float-sphere
uniform float3 direction;
float4 main(float4 tc : TEXCOORD0) : COLOR
{
float4 _P = tex2Dproj(s_position, tc);
float4 _N = tex2Dproj(s_normal, tc);
float3 L2P = _P.xyz - Ldynamic_pos.xyz; // light2point
float3 L2P_N = normalize(L2P); // light2point
float rsqr = dot(L2P, L2P); // distance 2 light (squared)
float att = saturate(1.0f - rsqr * Ldynamic_pos.w); // q-linear attenuate
float light = saturate(dot(-L2P_N, _N.xyz));
float hemi = saturate(dot(L2P_N, direction));
// Final color
return blendp(float4(Ldynamic_color.xyz * att * light * hemi, 0.0f), tc);
}

View file

@ -0,0 +1,7 @@
#include "common.h"
float4 main ( float4 P: POSITION ) : POSITION
{
return mul (m_WVP, P );
}
FXVS;

View file

@ -0,0 +1,7 @@
#include "common.hlsli"
float4 main(float4 P : POSITION) : POSITION
{
return mul(m_WVP, P);
}
FXVS;

View file

@ -0,0 +1,2 @@
#define USE_SHADOW
#include "accum_base.ps"

View file

@ -0,0 +1,4 @@
#define USE_SHADOW
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1,20 @@
#include "common.h"
#include "lmodel.h"
half4 main ( float4 tc:TEXCOORD0 ) : COLOR
{
const half bias_mul = 0.999f;
// Sample the fat framebuffer:
half4 _P = tex2Dproj (s_position, tc);
half4 _N = tex2Dproj (s_normal, tc);
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half rsqr;
half4 light = plight_local (m, _P, _N, Ldynamic_pos, Ldynamic_pos.w, rsqr);
return blendp (Ldynamic_color * light, tc);
}

View file

@ -0,0 +1,4 @@
#define USE_SHADOW
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1,5 @@
#define USE_LMAP
#define USE_LMAPXFORM
#define USE_SHADOW
#include "accum_base.ps"

View file

@ -0,0 +1,3 @@
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1,36 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
struct _input
{
float2 tc : TEXCOORD0;
float4 tcJ : TEXCOORD1;
float2 LT : TEXCOORD2;
float2 RT : TEXCOORD3;
float2 LB : TEXCOORD4;
float2 RB : TEXCOORD5;
};
float4 main ( _input I ) : COLOR
{
float4 _P = tex2D (s_position, I.tc);
half4 _N = tex2D (s_normal, I.tc);
// ----- light-model
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half4 light = plight_infinity (m,_P,_N,Ldynamic_dir);
// ----- shadow
half4 s_sum;
s_sum.x = tex2D (s_smap,I.LT).x;
s_sum.y = tex2D (s_smap,I.RT).y;
s_sum.z = tex2D (s_smap,I.LB).z;
s_sum.w = tex2D (s_smap,I.RB).w;
half s = dot (s_sum, 1.h/4.h);
return Ldynamic_color * light * s;
}

View file

@ -0,0 +1,44 @@
#include "common.hlsli"
#include "lmodel.hlsli"
#include "shadow.hlsli"
float4 main(float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1) : COLOR
{
float4 _P = tex2Dproj(s_position, tc);
float4 _N = tex2Dproj(s_normal, tc);
_P.xyz += normalize(_N.xyz) * 0.015f;
// ----- light-model
float m = xmaterial;
#ifndef USE_R2_STATIC_SUN
m = _P.w;
#endif
float4 light = plight_infinity(m, _P, _N, Ldynamic_dir);
// ----- shadow
float4 P4 = float4(_P.x, _P.y, _P.z, 1.0f);
float4 PS = mul(m_shadow, P4);
float s = 1.0f;
#if SUN_QUALITY == 2
#ifndef USE_FAR_ATTENTION
s *= shadow_high(PS);
#else
s *= shadowtest_sun(PS, float4(0, 0, 0, 0));
#endif
#else
s *= shadow(PS);
#endif
#ifdef USE_FAR_ATTENTION
// Far edge fading code
float3 tc_f = abs(PS.xyz / PS.w - float3(0.5f, 0.5f, 0.5f));
float3 border = 0.4f;
float3 fac = 1.0f - saturate((tc_f - border) / (0.5f - border));
s = lerp(s, 1.0f, 1.0f - fac.x * fac.y * fac.z);
#endif
s *= sunmask(P4);
return blend(Ldynamic_color * light * s, tc);
}

View file

@ -0,0 +1,39 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#ifdef USE_SUNFILTER
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc);
half4 _N = tex2Dproj (s_normal, tc);
// ----- light-model
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half4 light = plight_infinity (m,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f);
float4 PS = mul (m_shadow, P4);
half s = sunmask (P4);
#if defined (USE_SJITTER) || SUN_QUALITY==2
s *= shadow_high (PS);//shadowtest_sun (PS,float4(0,0,0,0));
#else
s *= shadow (PS);
#endif
return blend (Ldynamic_color * light * s/*float4( 1.f, 0.2f, 0.2f, 1.f)*/,tc);
}
#endif

View file

@ -0,0 +1,53 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
uniform float3 view_shadow_proj;
#ifdef USE_SUNFILTER
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2Dproj (s_position, tc);
half4 _N = tex2Dproj (s_normal, tc);
// ----- light-model
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half4 light = plight_infinity (m,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f);
float4 PS = mul (m_shadow, P4);
half s = sunmask (P4);
#if defined (USE_SJITTER) || SUN_QUALITY==2
s *= shadowtest_sun (PS,float4(0,0,0,0));
#else
s *= shadow (PS);
#endif
// Fading code
float2 tc_f = (PS.xy/PS.w)-float2(0.5f,0.5f);
// Fade only fron edges
tc_f *= step( -dot( tc_f, view_shadow_proj.xy ), 0 );
tc_f = abs( tc_f );
float border = 0.4f;
float fac_x = 1.f-saturate( ( tc_f.x - border )/(0.5f-border));
float fac_y = 1.f-saturate( ( tc_f.y - border )/(0.5f-border));
s += ((1-s)*(1-fac_x*fac_y));
//\ // Fading code
return blend (Ldynamic_color * light * s/*float4( 1.f, 0.2f, 0.2f, 1.f)*/,tc);
}
#endif

View file

@ -0,0 +1,79 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#define SUN_FARPLANE 100.f
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P);
#ifndef SUN_QUALITY
#ifdef USE_HWSMAP
#ifdef USE_FETCH4
half s = sunmask(_P)*sample_hw_f4 (PS, float4(0,0,0,0) );
#else
half s = sunmask(_P)*sample_hw_pcf (PS, float4(0,0,0,0) );
#endif
#else
half s = sunmask(_P)*sample_sw (PS.xy / PS.w, float2(0,0), PS.z);
#endif
#else // SUN_QUALITY
half s = sunmask(_P);
#if SUN_QUALITY==1
s *= shadow (PS);
#elif SUN_QUALITY==2
s *= shadowtest_sun (PS,tcJ);
#endif
#endif // SUN_QUALITY
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
half4 _N = tex2D (s_normal, tc);
// ----- light-model
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half4 light = plight_infinity (m,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1);
float4 PS = mul (m_shadow, P4);
#ifndef SUN_QUALITY
#ifdef USE_HWSMAP
#ifdef USE_FETCH4
half s = sunmask(P4)*sample_hw_f4 (PS, float4(0,0,0,0) );
#else
half s = sunmask(P4)*sample_hw_pcf (PS, float4(0,0,0,0) );
#endif
#else
half s = sunmask(P4)*sample_sw (PS.xy / PS.w, float2(0,0), PS.z);
#endif
#else // SUN_QUALITY
half s = sunmask(P4);
#if SUN_QUALITY==1
s *= shadow (PS);
#elif SUN_QUALITY==2
s *= shadowtest_sun (PS,tcJ);
#endif
#endif // SUN_QUALITY
#ifdef SUN_FARPLANE
float f = saturate (_P.z/SUN_FARPLANE);
s = lerp (s, 0.333h, f*f);
#endif
return blend (Ldynamic_color * light * s, tc);
}
#endif

View file

@ -0,0 +1,10 @@
#include "common.h"
#define EPS (0.9f/255.f)
half4 main ( p_screen I ) : COLOR
{
// Sample the fat framebuffer:
half4 NH = tex2D (s_normal, I.tc0);
half L = NH.w * dot (Ldynamic_dir, (half3)NH) + EPS; // Use hemisphere as approximation of max light
return half4 (L,L,L,L);
}

View file

@ -0,0 +1,11 @@
#include "common.hlsli"
#define EPS (0.9f / 255.f)
float4 main(p_screen I) : COLOR
{
// Sample the fat framebuffer:
float4 NH = tex2D(s_normal, I.tc0);
float L = dot(Ldynamic_dir, (float3)NH) + EPS; // Use hemisphere as approximation of max light
return float4(L, L, L, L);
}

View file

@ -0,0 +1,40 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
half4 _N = tex2D (s_normal, tc);
// ----- light-model
half m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
half4 light = plight_infinity (m,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f);
float4 PS = mul (m_shadow, P4);
half s = sunmask (P4);
#ifdef USE_SJITTER
s *= shadowtest_sun (PS,tcJ);
#else
s *= shadow (PS);
#endif
return blend (Ldynamic_color * light * s,tc);
}
#endif

View file

@ -0,0 +1,67 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#define XKERNEL .6f
half4 xlight_infinity (half m, half3 point, half3 normal, half3 light_direction) {
half3 N = normal; // normal
half3 V = -normalize (point); // vector2eye
half3 L = -light_direction; // vector2light
half3 H = normalize (L+V); // half-angle-vector
return tex3Dlod (s_material, half4( dot(L,N), dot(H,N), m, 0 ) ); // sample material
}
half xsample_hw (float4 tc,float4 shift){
static const float ts = XKERNEL / float(SMAP_size);
return tex2Dlod (s_smap,tc + shift*ts).x;
}
half xshadow (float4 tc, half old) {
float4 tcp = tc.xyzw/tc.w;
half s0 = xsample_hw (tcp,float4(-1,-1,0,0));
half s1 = xsample_hw (tcp,float4(+1,-1,0,0));
half s2 = xsample_hw (tcp,float4(-1,+1,0,0));
half s3 = xsample_hw (tcp,float4(+1,+1,0,0));
return (s0+s1+s2+s3)/4.h ;
}
half xsunmask (float4 P) { //
float2 tc = mul (m_sunmask, P); //
return tex2Dlod(s_lmap,tc.xyyy).w; // A8
}
//////////////////////////////////////////////////////////////////////////////////////////
// hardware
//////////////////////////////////////////////////////////////////////////////////////////
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
half4 _N = tex2D (s_normal, tc);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f) ;
float4 PS = mul (m_shadow, P4) ;
half s = tex2Dproj (s_smap,PS).x ;
half4 light = 0; //half4 (1,0,0,0);
if (s>0.0001) {
s = xshadow (PS,s) * xsunmask(P4); // s*xsunmask(P4); //
light = Ldynamic_color * s * xlight_infinity (_P.w,_P,_N,Ldynamic_dir);
}
/*
#ifdef USE_SJITTER
s *= shadowtest_sun (PS,tcJ);
#else
s *= shadow (PS);
#endif
*/
return blend ( light, tc );
}
#endif

View file

@ -0,0 +1,35 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
half4 _N = tex2D (s_normal, tc);
// ----- light-model
half4 light = plight_infinity (_P.w,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f);
float4 PS = mul (m_shadow, P4);
half s = sunmask (P4);
#ifdef USE_SJITTER
s *= shadowtest_sun (PS,tcJ);
#else
s *= shadow (PS);
#endif
return blend (Ldynamic_color * light * s,tc);
}
#endif

View file

@ -0,0 +1,35 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
half4 _N = tex2D (s_normal, tc);
// ----- light-model
half4 light = plight_infinity (_P.w,_P,_N,Ldynamic_dir);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f);
float4 PS = mul (m_shadow, P4);
half s = sunmask (P4);
#ifdef USE_SJITTER
s *= shadowtest_sun (PS,tcJ);
#else
s *= shadow (PS);
#endif
return blend (Ldynamic_color * light * s,tc);
}
#endif

View file

@ -0,0 +1,59 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#define XKERNEL .6f
half4 xlight_infinity (half m, half3 point, half3 normal, half3 light_direction) {
half3 N = normal; // normal
half3 V = -normalize (point); // vector2eye
half3 L = -light_direction; // vector2light
half3 H = normalize (L+V); // half-angle-vector
return tex3Dlod (s_material, half4( dot(L,N), dot(H,N), m, 0 ) ); // sample material
}
half xsample_hw (float4 tc,float4 shift){
static const float ts = XKERNEL / float(SMAP_size);
return tex2Dlod (s_smap,tc + shift*ts).x;
}
half xshadow (float4 tc, half old) {
float4 tcp = tc.xyzw/tc.w;
half s0 = xsample_hw (tcp,float4(-1,-1,0,0));
half s1 = xsample_hw (tcp,float4(+1,-1,0,0));
half s2 = xsample_hw (tcp,float4(-1,+1,0,0));
half s3 = xsample_hw (tcp,float4(+1,+1,0,0));
return (s0+s1+s2+s3)/4.h ;
}
half xsunmask (float4 P) { //
float2 tc = mul (m_sunmask, P); //
return tex2Dlod(s_lmap,tc.xyyy).w; // A8
}
//////////////////////////////////////////////////////////////////////////////////////////
// hardware
//////////////////////////////////////////////////////////////////////////////////////////
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f) ;
float4 PS = mul (m_shadow, P4) ;
half s = tex2Dproj (s_smap,PS).x ;
half4 light = 0; //half4 (1,0,0,0);
if (s>0.0001) {
half4 _N= tex2D (s_normal, tc);
s = xshadow (PS,s) * xsunmask(P4); // s*xsunmask(P4); //
light = Ldynamic_color * s * xlight_infinity (_P.w,_P,_N,Ldynamic_dir);
}
return blend ( light, tc );
}
#endif

View file

@ -0,0 +1,80 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#define XKERNEL .6f
half4 xlight_infinity (half m, half3 point, half3 normal, half3 light_direction) {
half3 N = normal; // normal
half3 V = -normalize (point); // vector2eye
half3 L = -light_direction; // vector2light
half3 H = normalize (L+V); // half-angle-vector
return tex3Dlod (s_material, half4( dot(L,N), dot(H,N), m, 0 ) ); // sample material
}
half xsample_hw (float4 tc,float4 shift){
static const float ts = XKERNEL / float(SMAP_size);
return tex2Dlod (s_smap,tc + shift*ts).x;
}
half xshadow (float4 tc, half old) {
float4 tcp = tc.xyzw/tc.w;
half s0 = xsample_hw (tcp,float4(-1,-1,0,0));
half s1 = xsample_hw (tcp,float4(+1,-1,0,0));
half s2 = xsample_hw (tcp,float4(-1,+1,0,0));
half s3 = xsample_hw (tcp,float4(+1,+1,0,0));
return (s0+s1+s2+s3)/4.h ;
}
half xsunmask (float4 P) { //
float2 tc = mul (m_sunmask, P); //
return tex2Dlod(s_lmap,tc.xyyy).w; // A8
}
half xsample_h (float4 tc,float4 shift){
return tex2Dproj (s_smap,tc + tc.w*shift).x;
}
uniform float4 o0,o1,o2,o3;
half xshadow_2 (float4 tc) {
static const float ts = KERNEL / float(SMAP_size);
half4 s ;
s.x = xsample_h (tc,o0); //float4(-1,-1,0,0)*ts);
s.y = xsample_h (tc,o1); //float4(+1,-1,0,0)*ts);
s.z = xsample_h (tc,o2); //float4(-1,+1,0,0)*ts);
s.w = xsample_h (tc,o3); //float4(+1,+1,0,0)*ts);
return (s.x+s.y+s.z+s.w)*0.25h; //dot(s,1.h/4.h) ;
}
half xshadow_3 (float4 tc) {
static const float ts = KERNEL / float(SMAP_size);
half4 s ;
s.x = xsample_h (tc,float4(-1,-1,0,0)*ts);
s.y = xsample_h (tc,float4(+1,-1,0,0)*ts);
s.z = xsample_h (tc,float4(-1,+1,0,0)*ts);
s.w = xsample_h (tc,float4(+1,+1,0,0)*ts);
return (s.x+s.y+s.z+s.w)*0.25h; //dot(s,1.h/4.h) ;
}
//////////////////////////////////////////////////////////////////////////////////////////
// hardware
//////////////////////////////////////////////////////////////////////////////////////////
#ifdef USE_SUNFILTER
float4 main ( float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc) ;
_P.w = 1.f ;
float4 PS = mul (m_shadow, _P) ;
half s = shadowtest_sun(PS,tcJ)*sunmask(_P) ;
return s ;
}
#else
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
float4 _P = tex2D (s_position, tc);
// ----- shadow
float4 P4 = float4 (_P.x,_P.y,_P.z,1.f) ;
float4 PS = mul (m_shadow, P4) ;
half s = xshadow_2 (PS);
half4 light = 0; //half4 (1,0,0,0) ;
if (s>0.0001) {
half4 _N= tex2D (s_normal, tc );
light = Ldynamic_color * s * xsunmask (P4) * xlight_infinity (_P.w,_P,_N,Ldynamic_dir);
}
return blend ( light, tc );
}
#endif

View file

@ -0,0 +1,8 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
float4 main ( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
return Ldynamic_color;
}

View file

@ -0,0 +1,28 @@
#include "common.h"
struct v2p
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float4 tc: TEXCOORD0;
#ifdef USE_SJITTER
float4 tcJ: TEXCOORD1;
#endif
};
//////////////////////////////////////////////////////////////////////////////////////////
//uniform float4x4 m_texgen;
uniform float4x4 m_texgen_J;
//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
v2p main ( float4 P: POSITION )
{
v2p O;
O.hpos = mul (m_WVP, P );
O.tc = mul (m_texgen, P );
#ifdef USE_SJITTER
O.tcJ = mul (m_texgen_J, P );
#endif
return O;
}
FXVS;

View file

@ -0,0 +1,20 @@
#include "common.hlsli"
struct v2p
{
float4 hpos : POSITION; // Clip-space position (for rasterization)
float4 tc : TEXCOORD0;
};
// uniform float4x4 m_texgen;
uniform float4x4 m_texgen_J;
// Vertex
v2p main(float4 P : POSITION)
{
v2p O;
O.hpos = mul(m_WVP, P);
O.tc = mul(m_texgen, P);
return O;
}
FXVS;

View file

@ -0,0 +1,12 @@
function normal(shader, t_base, t_second, t_detail)
shader:begin("accum_volumetric", "accum_volumetric")
:fog(false)
:zb(true, false)
:blend(true, blend.one, blend.one)
-- : aref (true,0)
:sorting(2, false)
shader:sampler("s_lmap"):texture(t_base):clamp()
shader:sampler("s_smap"):texture("null")
-- shader:sampler ("s_noise") :texture("fx\\fx_noise2") : f_linear ()
shader:sampler("s_noise"):texture("fx\\fx_noise"):f_linear()
end

View file

@ -0,0 +1,81 @@
#include "common.h"
#include "shadow.h"
struct v2p
{
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
half fDensity : TEXCOORD2; // plane density alon Z axis
// half2 tNoise : TEXCOORD3; // projective noise
};
uniform float4 m_lmap [2];
uniform sampler2D s_noise;
#define USE_LMAP
#define USE_LMAPXFORM
#define USE_SHADOW
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
// ----- shadow
float4 P4 = half4(I.vPos, 1);
float4 PS = mul( m_shadow, P4);
half s = 1.h;
#ifdef USE_SHADOW
// #ifdef USE_SJITTER
// s = shadowtest (PS,tcJ);
// #else
s = shadow(PS);
// #endif
#endif
// ----- lightmap
half4 lightmap = 1.h;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot( P4, m_lmap[0]);
PS.y = dot( P4, m_lmap[1]);
#endif
lightmap = tex2Dproj(s_lmap, PS); //
#endif
// ----- attenuate
half rsqr = dot( I.lightToPos, I.lightToPos); // distance 2 light (squared)
half att = saturate( 1 - rsqr * Ldynamic_pos.w ); // q-linear attenuate
//half att = saturate( 1 - (rsqr * Ldynamic_pos.w)*(rsqr * Ldynamic_pos.w) ); // q-linear attenuate
//half att = 10*(1/(1+0.1*rsqr));
//half att = 1.0h/rsqr;
//half att = 1.0h/rsqr-Ldynamic_pos.w;
//half att = 5*(sqrt(1.0h/rsqr)-sqrt(Ldynamic_pos.w));
// ----- noise
PS.xy /= PS.w;
half time = timers.z*0.1;
PS.xy /= 3;
PS.x += time;
half4 t_noise = tex2D(s_noise,PS);
PS.x -= time;
PS.y -= time*0.70091;
t_noise *= tex2D(s_noise,PS);
//t_noise *= 4;
t_noise = t_noise*0.5+0.5;
// out
//half maxIntens = 1.0h/100.0h;
//half maxIntens = 1.0h/40.0h;
//half maxIntens = 1.0h/10.0h;
half maxIntens = I.fDensity;
half3 result = maxIntens * s * att;
result *= lightmap;
result *= Ldynamic_color * t_noise;
// result = maxIntens;
// result *= lightmap;
// result = 0.1h;
// result = 0.0h;
return half4( result, 0);
}

View file

@ -0,0 +1,76 @@
#include "common.hlsli"
#include "shadow.hlsli"
struct v2p
{
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
float fDensity : TEXCOORD2; // plane density alon Z axis
// float2 tNoise : TEXCOORD3; // projective noise
};
uniform float4 m_lmap[2];
uniform sampler2D s_noise;
#define USE_LMAP
#define USE_LMAPXFORM
#define USE_SHADOW
// Pixel
float4 main(v2p I) : COLOR
{
// ----- shadow
float4 P4 = float4(I.vPos, 1.0f);
float4 PS = mul(m_shadow, P4);
float s = 1.0f;
#ifdef USE_SHADOW
s = shadow(PS);
#endif
// ----- lightmap
float4 lightmap = 1.0f;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot(P4, m_lmap[0]);
PS.y = dot(P4, m_lmap[1]);
#endif
lightmap = tex2Dproj(s_lmap, PS); //
#endif
// ----- attenuate
float rsqr = dot(I.lightToPos, I.lightToPos); // distance 2 light (squared)
float att = saturate(1 - rsqr * Ldynamic_pos.w); // q-linear attenuate
// float att = saturate( 1 - (rsqr * Ldynamic_pos.w)*(rsqr * Ldynamic_pos.w) ); // q-linear attenuate
// float att = 10*(1/(1+0.1*rsqr));
// float att = 1.0h/rsqr;
// float att = 1.0h/rsqr-Ldynamic_pos.w;
// float att = 5*(sqrt(1.0h/rsqr)-sqrt(Ldynamic_pos.w));
// ----- noise
PS.xy /= PS.w;
float time = timers.z * 0.1f;
PS.xy /= 3;
PS.x += time;
float4 t_noise = tex2D(s_noise, PS);
PS.x -= time;
PS.y -= time * 0.70091f;
t_noise *= tex2D(s_noise, PS);
// t_noise *= 4;
t_noise = t_noise * 0.5f + 0.5f;
// out
// float maxIntens = 1.0h/100.0h;
// float maxIntens = 1.0h/40.0h;
// float maxIntens = 1.0h/10.0h;
float maxIntens = I.fDensity;
float3 result = maxIntens * s * att;
result *= lightmap;
result *= Ldynamic_color * t_noise;
// result = maxIntens;
// result *= lightmap;
// result = 0.1h;
// result = 0.0h;
return float4(result, 0.0f);
}

View file

@ -0,0 +1,12 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_volumetric", "accum_volumetric")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
-- : aref (true,0)
: sorting (2, false)
shader:sampler ("s_lmap") :texture (t_base): clamp()
shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_noise") :texture("fx\\fx_noise2") : f_linear ()
shader:sampler ("s_noise") :texture("fx\\fx_noise") : f_linear ()
end

View file

@ -0,0 +1,32 @@
#include "common.h"
float3 vMinBounds;
float3 vMaxBounds;
struct vf
{
float4 hpos : POSITION;
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
half fDensity : TEXCOORD2; // plane density alon Z axis
// half2 tNoise : TEXCOORD3; // projective noise
};
vf main (v_static v)
{
vf o;
float4 vPos;
vPos.xyz = lerp( vMinBounds, vMaxBounds, v.P); // Position in camera space
vPos.w = 1;
o.hpos = mul (m_P, vPos); // xform, input in camera coordinates
o.lightToPos = vPos.xyz - Ldynamic_pos.xyz;
o.vPos = vPos;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h*2;
o.fDensity = 1.0h/40.0h;
// o.fDensity = 1.0h/20.0h;
return o;
}

View file

@ -0,0 +1,32 @@
#include "common.hlsli"
float3 vMinBounds;
float3 vMaxBounds;
struct vf
{
float4 hpos : POSITION;
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
float fDensity : TEXCOORD2; // plane density alon Z axis
// float2 tNoise : TEXCOORD3; // projective noise
};
vf main(v_static v)
{
vf o;
float4 vPos;
vPos.xyz = lerp(vMinBounds, vMaxBounds, v.P); // Position in camera space
vPos.w = 1;
o.hpos = mul(m_P, vPos); // xform, input in camera coordinates
o.lightToPos = vPos.xyz - Ldynamic_pos.xyz;
o.vPos = vPos;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h*2;
o.fDensity = 1.0h / 40.0h;
// o.fDensity = 1.0h/20.0h;
return o;
}

View file

@ -0,0 +1,100 @@
// Allow dynamic branching usage for HW PCF support
#ifdef USE_HWSMAP_PCF
#define SUNSHAFTS_DYNAMIC
#endif // USE_HWSMAP_PCF
#include "common.h"
#include "shadow.h"
#define RAY_PATH 2.0h
//#define JITTER_SUN_SHAFTS
#ifdef SUN_SHAFTS_QUALITY
#if SUN_SHAFTS_QUALITY==1
#define FILTER_LOW
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY==2
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY==3
#define RAY_SAMPLES 40
#endif
#endif
half4 volume_range; // x - near plane, y - far plane
half4 sun_shafts_intensity;
//#ifdef USE_BRANCHING
// "If" in loop
float4 main (float2 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
#ifndef SUN_SHAFTS_QUALITY
return half4(0,0,0,0);
#else // SUN_SHAFTS_QUALITY
half3 P = tex2D(s_position, tc).xyz;
#ifndef JITTER_SUN_SHAFTS
// Fixed ray length, fixed step dencity
// half3 direction = (RAY_PATH/RAY_SAMPLES)*normalize(P);
// Variable ray length, variable step dencity
half3 direction = P/RAY_SAMPLES;
#else // JITTER_SUN_SHAFTS
// Variable ray length, variable step dencity, use jittering
half4 J0 = tex2D (jitter0,tcJ);
half coeff = (RAY_SAMPLES - 2*J0.x)/(RAY_SAMPLES*RAY_SAMPLES);
half3 direction = P*coeff;
// half3 direction = P/(RAY_SAMPLES+(J0.x*4-2));
#endif // JITTER_SUN_SHAFTS
half depth = P.z;
half deltaDepth = direction.z;
half4 current = mul (m_shadow,float4(P,1));
half4 delta = mul (m_shadow, float4(direction,0));
half res = 0;
half max_density = sun_shafts_intensity;
half density = max_density/RAY_SAMPLES;
if (depth<0.0001)
res = max_density;
#ifndef SUNSHAFTS_DYNAMIC
for ( int i=0; i<RAY_SAMPLES; ++i )
{
if (depth>0.3)
#ifndef FILTER_LOW
res += density*shadow(current);
#else // FILTER_LOW
res += density*sample_hw_pcf(current, float4(0,0,0,0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#else
int n = (int)((P.z - 0.3) / deltaDepth);
for ( int i=0; i<n; ++i )
{
#ifndef FILTER_LOW
res += density*shadow(current);
#else // FILTER_LOW
res += density*sample_hw_pcf(current, float4(0,0,0,0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#endif
// float fSturation = -dot(Ldynamic_dir, half3(0,0,1));
float fSturation = -Ldynamic_dir.z;
// Normalize dot product to
fSturation = 0.5*fSturation+0.5;
// Map saturation to 0.2..1
fSturation = 0.80*fSturation+0.20;
res *= fSturation;
return res*Ldynamic_color;
#endif // SUN_SHAFTS_QUALITY
}

View file

@ -0,0 +1,12 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_volume", "accum_volumetric_sun")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
shader:sampler ("s_smap") :texture ("null")
shader:sampler ("s_position") :texture ("$user$position") : f_none ()
shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
-- shader:sampler ("s_noise") :texture("fx\\fx_noise") : f_linear ()
-- shader:sampler ("s_lmap") :texture (t_base): clamp()
end

View file

@ -0,0 +1,10 @@
function normal(shader, t_base, t_second, t_detail)
shader:begin("accum_volume", "accum_volumetric_sun_cascade")
:fog(false)
:zb(false, false)
:blend(true, blend.one, blend.one)
:sorting(2, false)
shader:sampler("s_smap"):texture("null")
shader:sampler("s_position"):texture("$user$position"):f_none()
shader:sampler("jitter0"):texture("$user$jitter_0"):f_none()
end

View file

@ -0,0 +1,103 @@
// Allow dynamic branching usage for HW PCF support
#ifdef USE_HWSMAP_PCF
#define SUNSHAFTS_DYNAMIC
#endif // USE_HWSMAP_PCF
#include "common.h"
#include "shadow.h"
#define RAY_PATH 2.0h
#define JITTER_TEXTURE_SIZE 64.0f
#define JITTER_SUN_SHAFTS
#ifdef SUN_SHAFTS_QUALITY
#if SUN_SHAFTS_QUALITY==1
#define FILTER_LOW
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY==2
#define FILTER_LOW
#define RAY_SAMPLES 30
#elif SUN_SHAFTS_QUALITY==3
#define FILTER_LOW
#define RAY_SAMPLES 40
#endif
#endif
half4 volume_range; // x - near plane, y - far plane
half4 sun_shafts_intensity;
uniform float4 screen_res;
//#ifdef USE_BRANCHING
// "If" in loop
float4 main (float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : COLOR
{
#ifndef SUN_SHAFTS_QUALITY
return half4(0,0,0,0);
#else // SUN_SHAFTS_QUALITY
half3 P = tex2Dproj(s_position, tc).xyz;
#ifndef JITTER_SUN_SHAFTS
// Fixed ray length, fixed step dencity
// half3 direction = (RAY_PATH/RAY_SAMPLES)*normalize(P);
// Variable ray length, variable step dencity
half3 direction = P/RAY_SAMPLES;
#else // JITTER_SUN_SHAFTS
// Variable ray length, variable step dencity, use jittering
half4 J0 = tex2D (jitter0,float4(screen_res.x/JITTER_TEXTURE_SIZE*tc.xy/tc.w,0,0));//tcJ);
half coeff = (RAY_SAMPLES - 1*J0.x)/(RAY_SAMPLES*RAY_SAMPLES);
half3 direction = P*coeff;
// half3 direction = P/(RAY_SAMPLES+(J0.x*4-2));
#endif // JITTER_SUN_SHAFTS
half depth = P.z;
half deltaDepth = direction.z;
half4 current = mul (m_shadow,float4(P,1));
half4 delta = mul (m_shadow, float4(direction,0));
half res = 0;
half max_density = sun_shafts_intensity;
half density = max_density/RAY_SAMPLES;
if (depth<0.0001)
res = max_density;
#ifndef SUNSHAFTS_DYNAMIC
for ( int i=0; i<RAY_SAMPLES; ++i )
{
if (depth>0.3)
#ifndef FILTER_LOW
res += density*shadow_volumetric(current);
#else // FILTER_LOW
res += density*sample_hw_pcf(current, float4(0,0,0,0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#else
int n = (int)((P.z - 0.3) / deltaDepth);
for ( int i=0; i<n; ++i )
{
#ifndef FILTER_LOW
res += density*shadow_volumetric(current);
#else // FILTER_LOW
res += density*sample_hw_pcf(current, float4(0,0,0,0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#endif
// float fSturation = -dot(Ldynamic_dir, half3(0,0,1));
float fSturation = -Ldynamic_dir.z;
// Normalize dot product to
fSturation = 0.5*fSturation+0.5;
// Map saturation to 0.2..1
fSturation = 0.80*fSturation+0.20;
res *= fSturation;
return res*Ldynamic_color*1.0;
#endif // SUN_SHAFTS_QUALITY
}

View file

@ -0,0 +1,108 @@
// Allow dynamic branching usage for HW PCF support
#ifdef USE_HWSMAP_PCF
#define SUNSHAFTS_DYNAMIC
#endif // USE_HWSMAP_PCF
#include "common.hlsli"
#include "shadow.hlsli"
#define RAY_PATH 2.0h
#define JITTER_TEXTURE_SIZE 64.0f
#define JITTER_SUN_SHAFTS
#ifdef SUN_SHAFTS_QUALITY
#if SUN_SHAFTS_QUALITY == 1
#define FILTER_LOW
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY == 2
#define FILTER_LOW
#define RAY_SAMPLES 30
#elif SUN_SHAFTS_QUALITY == 3
#define FILTER_LOW
#define RAY_SAMPLES 40
#endif
#endif
float4 volume_range; // x - near plane, y - far plane
float4 sun_shafts_intensity;
uniform float4 screen_res;
// #ifdef USE_BRANCHING
// "If" in loop
float4 main(float2 tc : TEXCOORD0) : COLOR
{
#ifndef SUN_SHAFTS_QUALITY
return float4(0.0f, 0.0f, 0.0f, 0.0f);
#else // SUN_SHAFTS_QUALITY
float3 P = tex2D(s_position, tc).xyz;
#ifndef JITTER_SUN_SHAFTS
// Fixed ray length, fixed step dencity
// float3 direction = (RAY_PATH/RAY_SAMPLES)*normalize(P);
// Variable ray length, variable step dencity
float3 direction = P / RAY_SAMPLES;
#else // JITTER_SUN_SHAFTS
// Variable ray length, variable step dencity, use jittering
float4 J0 = tex2D(jitter0, float4(screen_res.x / JITTER_TEXTURE_SIZE * tc, 0.0f, 0.0f)); // tcJ);
float coeff = (RAY_SAMPLES - 1.0f * J0.x) / (RAY_SAMPLES * RAY_SAMPLES);
float3 direction = P * coeff;
#endif // JITTER_SUN_SHAFTS
float depth = P.z;
float deltaDepth = direction.z;
float4 current = mul(m_shadow, float4(P, 1.0f));
float4 delta = mul(m_shadow, float4(direction, 0.0f));
float res = 0.0f;
float max_density = sun_shafts_intensity;
float density = max_density / RAY_SAMPLES;
if (depth < 0.0001)
{
res = max_density;
}
#ifndef SUNSHAFTS_DYNAMIC
for (int i = 0; i < RAY_SAMPLES; ++i)
{
if (depth > 0.3)
#ifndef FILTER_LOW
res += density * shadow_volumetric(current);
#else // FILTER_LOW
res += density * sample_hw_pcf(current, float4(0, 0, 0, 0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#else
int n = (int)((P.z - 0.3) / deltaDepth);
for (int i = 0; i < n; ++i)
{
#ifndef FILTER_LOW
res += density * shadow_volumetric(current);
#else // FILTER_LOW
res += density * sample_hw_pcf(current, float4(0, 0, 0, 0));
#endif // FILTER_LOW
depth -= deltaDepth;
current -= delta;
}
#endif
// float fSturation = -dot(Ldynamic_dir, float3(0,0,1));
float fSturation = -Ldynamic_dir.z;
// Normalize dot product to
fSturation = 0.5 * fSturation + 0.5;
// Map saturation to 0.2..1
fSturation = 0.80 * fSturation + 0.20;
float fog = saturate(length(P.xyz) * fog_params.w + fog_params.x);
res = lerp(res, max_density, fog);
res *= fSturation;
return res * Ldynamic_color * 1.0;
#endif // SUN_SHAFTS_QUALITY
}

View file

@ -0,0 +1,12 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_volume", "accum_volumetric_sun_cascade")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
shader:sampler ("s_smap") :texture ("null")
shader:sampler ("s_position") :texture ("$user$position") : f_none ()
shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
-- shader:sampler ("s_noise") :texture("fx\\fx_noise") : f_linear ()
-- shader:sampler ("s_lmap") :texture (t_base): clamp() : f_none ()
end

View file

@ -0,0 +1,27 @@
#include "common.h"
struct v2p
{
half2 tc0: TEXCOORD0; // base
half2 tc1: TEXCOORD1; // base
half2 tc2: TEXCOORD2; // base
half2 tc3: TEXCOORD3; // base
};
uniform sampler2D s_base0;
uniform sampler2D s_base1;
uniform sampler2D s_base2;
uniform sampler2D s_base3;
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main_ps_1_1 ( v2p I ) : COLOR
{
half4 t_0 = tex2D (s_base0,I.tc0);
half4 t_1 = tex2D (s_base1,I.tc1);
half4 t_2 = tex2D (s_base2,I.tc2);
half4 t_3 = tex2D (s_base3,I.tc3);
// out
return ((t_0+t_1)*.5 + (t_2+t_3)*.5)*.5;
}

View file

@ -0,0 +1,26 @@
#include "common.hlsli"
struct v2p
{
float2 tc0 : TEXCOORD0; // base
float2 tc1 : TEXCOORD1; // base
float2 tc2 : TEXCOORD2; // base
float2 tc3 : TEXCOORD3; // base
};
uniform sampler2D s_base0;
uniform sampler2D s_base1;
uniform sampler2D s_base2;
uniform sampler2D s_base3;
// Pixel
float4 main(v2p I) : COLOR
{
float4 t_0 = tex2D(s_base0, I.tc0);
float4 t_1 = tex2D(s_base1, I.tc1);
float4 t_2 = tex2D(s_base2, I.tc2);
float4 t_3 = tex2D(s_base3, I.tc3);
// out
return ((t_0 + t_1) * 0.5f + (t_2 + t_3) * 0.5f) * 0.5f;
}

View file

@ -0,0 +1,18 @@
#include "common.h"
struct v2p
{
half2 tc0: TEXCOORD0; // base
half2 tc1: TEXCOORD1; // lmap
half4 c0: COLOR0; // sun
};
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
half4 t_base = tex2D (s_base,I.tc0);
// out
return half4 (t_base.r,t_base.g,t_base.b,t_base.a * I.c0.a);
}

View file

@ -0,0 +1,17 @@
#include "common.hlsli"
struct v2p
{
float2 tc0 : TEXCOORD0; // base
float2 tc1 : TEXCOORD1; // lmap
float4 c0 : COLOR0; // sun
};
// Pixel
float4 main(v2p I) : COLOR
{
float4 t_base = tex2D(s_base, I.tc0);
// out
return float4(t_base.r, t_base.g, t_base.b, t_base.a * I.c0.a);
}

View file

@ -0,0 +1,24 @@
#include "common.h"
struct vf
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // base
float4 c0 : COLOR0; // color
};
vf main (v_static v)
{
vf o;
o.hpos = mul (m_WVP, v.P); // xform, input in world coords
o.tc0 = unpack_tc_base (v.tc,v.T.w,v.B.w); // copy tc
// calculate fade
float3 dir_v = normalize (mul(m_WV,v.P));
float3 norm_v = normalize (mul(m_WV,unpack_normal(v.Nh)));
float fade = abs (dot(dir_v,norm_v));
o.c0 = fade;
return o;
}

View file

@ -0,0 +1,24 @@
#include "common.hlsli"
struct vf
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // base
float4 c0 : COLOR0; // color
};
vf main(v_static v)
{
vf o;
o.hpos = mul(m_WVP, v.P); // xform, input in world coords
o.tc0 = unpack_tc_base(v.tc, v.T.w, v.B.w); // copy tc
// calculate fade
float3 dir_v = normalize(mul(m_WV, v.P));
float3 norm_v = normalize(mul(m_WV, unpack_normal(v.Nh)));
float fade = abs(dot(dir_v, norm_v));
o.c0 = fade;
return o;
}

View file

@ -0,0 +1,33 @@
#include "common.hlsli"
struct v2p
{
float2 tc0: TEXCOORD0; // base
float2 tc1: TEXCOORD1; // lmap
float4 c0: COLOR0; // sun
};
uniform float4 m_hud_params; //
inline bool isCollimatorActive()
{
return (m_hud_params.w == 1.f);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main ( v2p I ) : COLOR
{
float4 t_base = tex2D (s_base,I.tc0);
// out
if(isCollimatorActive())
{
return float4 (t_base.r,t_base.g,t_base.b,t_base.a * I.c0.a);
}
else
{
return float4 (t_base.r,t_base.g,t_base.b,t_base.a * 0.0f);
}
}

View file

@ -0,0 +1,28 @@
#include "common.h"
struct v2p
{
float2 tc0: TEXCOORD0; // Texture coordinates (for sampling maps)
float2 tc1: TEXCOORD1; // Texture coordinates (for sampling maps)
float2 tc2: TEXCOORD2; // Texture coordinates (for sampling maps)
float2 tc3: TEXCOORD3; // Texture coordinates (for sampling maps)
};
uniform half4 b_params;
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
// hi-rgb.base-lum
half3 s0 = tex2D (s_image, I.tc0);
half3 s1 = tex2D (s_image, I.tc1);
half3 s2 = tex2D (s_image, I.tc2);
half3 s3 = tex2D (s_image, I.tc3);
half3 avg = (s0+s1+s2+s3)/2;
half hi = dot(avg,1.h)-b_params.x ; // assume def_hdr equal to 3.0
return half4(avg,hi);
}

View file

@ -0,0 +1,26 @@
#include "common.hlsli"
struct v2p
{
float2 tc0 : TEXCOORD0; // Texture coordinates (for sampling maps)
float2 tc1 : TEXCOORD1; // Texture coordinates (for sampling maps)
float2 tc2 : TEXCOORD2; // Texture coordinates (for sampling maps)
float2 tc3 : TEXCOORD3; // Texture coordinates (for sampling maps)
};
uniform float4 b_params;
// Pixel
float4 main(v2p I) : COLOR
{
// hi-rgb.base-lum
float3 s0 = tex2D(s_image, I.tc0);
float3 s1 = tex2D(s_image, I.tc1);
float3 s2 = tex2D(s_image, I.tc2);
float3 s3 = tex2D(s_image, I.tc3);
float3 avg = (s0 + s1 + s2 + s3) / (2.0f * def_hdr);
float hi = dot(avg, 1.0f) - b_params.x; // assume def_hdr equal to 3.0
return float4(avg, hi);
}

View file

@ -0,0 +1,53 @@
#include "common.h"
struct v2p
{
float2 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform half4 weight[2];
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
// Separable gauss filter: 2*7 + 1 + 7*2 = 29 samples
// Samples: 0-central, -1, -2,..., -7, 1, 2,... 7
// Approximated i-count: 15t + 15a + 7a(d) + 1(out) = 38, HLSL compiled to 38 :)
half4 main ( v2p I ) : COLOR
{
// central
half4 accum = weight[1].w * tex2D (s_bloom, I.tc0);
// left (7)
// right (7) - no swizles on 'texld', so this is dep-read infact
accum += weight[0].x * tex2D (s_bloom, I.tc1.xy);
accum += weight[0].x * tex2D (s_bloom, I.tc1.wz);
accum += weight[0].y * tex2D (s_bloom, I.tc2.xy);
accum += weight[0].y * tex2D (s_bloom, I.tc2.wz);
accum += weight[0].z * tex2D (s_bloom, I.tc3.xy);
accum += weight[0].z * tex2D (s_bloom, I.tc3.wz);
accum += weight[0].w * tex2D (s_bloom, I.tc4.xy);
accum += weight[0].w * tex2D (s_bloom, I.tc4.wz);
accum += weight[1].x * tex2D (s_bloom, I.tc5.xy);
accum += weight[1].x * tex2D (s_bloom, I.tc5.wz);
accum += weight[1].y * tex2D (s_bloom, I.tc6.xy);
accum += weight[1].y * tex2D (s_bloom, I.tc6.wz);
accum += weight[1].z * tex2D (s_bloom, I.tc7.xy);
accum += weight[1].z * tex2D (s_bloom, I.tc7.wz);
// OK
return accum;
}

View file

@ -0,0 +1,51 @@
#include "common.hlsli"
struct v2p
{
float2 tc0 : TEXCOORD0; // Central
float4 tc1 : TEXCOORD1; // -1,+1
float4 tc2 : TEXCOORD2; // -2,+2
float4 tc3 : TEXCOORD3; // -3,+3
float4 tc4 : TEXCOORD4; // -4,+4
float4 tc5 : TEXCOORD5; // -5,+5
float4 tc6 : TEXCOORD6; // -6,+6
float4 tc7 : TEXCOORD7; // -7,+7
};
uniform float4 weight[2];
// Pixel
// Separable gauss filter: 2*7 + 1 + 7*2 = 29 samples
// Samples: 0-central, -1, -2,..., -7, 1, 2,... 7
// Approximated i-count: 15t + 15a + 7a(d) + 1(out) = 38, HLSL compiled to 38 :)
float4 main(v2p I) : COLOR
{
// central
float4 accum = weight[1].w * tex2D(s_bloom, I.tc0);
// left (7)
// right (7) - no swizles on 'texld', so this is dep-read infact
accum += weight[0].x * tex2D(s_bloom, I.tc1.xy);
accum += weight[0].x * tex2D(s_bloom, I.tc1.wz);
accum += weight[0].y * tex2D(s_bloom, I.tc2.xy);
accum += weight[0].y * tex2D(s_bloom, I.tc2.wz);
accum += weight[0].z * tex2D(s_bloom, I.tc3.xy);
accum += weight[0].z * tex2D(s_bloom, I.tc3.wz);
accum += weight[0].w * tex2D(s_bloom, I.tc4.xy);
accum += weight[0].w * tex2D(s_bloom, I.tc4.wz);
accum += weight[1].x * tex2D(s_bloom, I.tc5.xy);
accum += weight[1].x * tex2D(s_bloom, I.tc5.wz);
accum += weight[1].y * tex2D(s_bloom, I.tc6.xy);
accum += weight[1].y * tex2D(s_bloom, I.tc6.wz);
accum += weight[1].z * tex2D(s_bloom, I.tc7.xy);
accum += weight[1].z * tex2D(s_bloom, I.tc7.wz);
// OK
return accum;
}

View file

@ -0,0 +1,22 @@
#include "common.h"
struct v2p
{
float2 tc0: TEXCOORD0; // base
float2 tc1: TEXCOORD1; // base
float2 tc2: TEXCOORD2; // base
float2 tc3: TEXCOORD3; // base
};
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
half4 t_0 = tex2D (s_bloom,I.tc0);
half4 t_1 = tex2D (s_bloom,I.tc1);
half4 t_2 = tex2D (s_bloom,I.tc2);
half4 t_3 = tex2D (s_bloom,I.tc3);
// out
return (t_0+t_1+t_2+t_3)/2;
}

View file

@ -0,0 +1,21 @@
#include "common.hlsli"
struct v2p
{
float2 tc0 : TEXCOORD0; // base
float2 tc1 : TEXCOORD1; // base
float2 tc2 : TEXCOORD2; // base
float2 tc3 : TEXCOORD3; // base
};
// Pixel
float4 main(v2p I) : COLOR
{
float4 t_0 = tex2D(s_bloom, I.tc0);
float4 t_1 = tex2D(s_bloom, I.tc1);
float4 t_2 = tex2D(s_bloom, I.tc2);
float4 t_3 = tex2D(s_bloom, I.tc3);
// out
return (t_0 + t_1 + t_2 + t_3) / 2;
}

View file

@ -0,0 +1,39 @@
#include "common.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
//////////////////////////////////////////////////////////////////////////////////////////
#define LUMINANCE_BASE 0.0001h
half luminance (float2 tc) {
half3 source = tex2D(s_image,tc);
return dot (source, LUMINANCE_VECTOR*def_hdr );
}
//////////////////////////////////////////////////////////////////////////////////////////
// perform 2x2=4s convolution, working on 4x4=16p area
// that means 256x256 source will be scaled to (256/4)x(256/4) = 64x64p
// a): 256x256 => 64x64p with log
// b): 64x64p => 8x8p
// c): 8x8p => 1x1p with exp
half4 main ( v2p I ) : COLOR
{
// first 8 bilinear samples (8x4 = 32 pixels)
half4 final;
final.x = luminance(I.tc0);
final.y = luminance(I.tc1);
final.z = luminance(I.tc2);
final.w = luminance(I.tc3);
// OK
return final ;
}

View file

@ -0,0 +1,39 @@
#include "common.hlsli"
struct v2p
{
float4 tc0 : TEXCOORD0; // Central
float4 tc1 : TEXCOORD1; // -1,+1
float4 tc2 : TEXCOORD2; // -2,+2
float4 tc3 : TEXCOORD3; // -3,+3
float4 tc4 : TEXCOORD4; // -4,+4
float4 tc5 : TEXCOORD5; // -5,+5
float4 tc6 : TEXCOORD6; // -6,+6
float4 tc7 : TEXCOORD7; // -7,+7
};
#define LUMINANCE_BASE 0.0001f
float luminance(float2 tc)
{
float3 source = tex2D(s_image, tc);
return dot(source, LUMINANCE_VECTOR * def_hdr);
}
// perform 2x2=4s convolution, working on 4x4=16p area
// that means 256x256 source will be scaled to (256/4)x(256/4) = 64x64p
// a): 256x256 => 64x64p with log
// b): 64x64p => 8x8p
// c): 8x8p => 1x1p with exp
float4 main(v2p I) : COLOR
{
// first 8 bilinear samples (8x4 = 32 pixels)
float4 final;
final.x = luminance(I.tc0);
final.y = luminance(I.tc1);
final.z = luminance(I.tc2);
final.w = luminance(I.tc3);
// OK
return final;
}

View file

@ -0,0 +1,69 @@
#include "common.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
//////////////////////////////////////////////////////////////////////////////////////////
// perform 4x4 bilinear, 8x8p, the step (B)
// b): 64x64p => 8x8p
#ifdef FP16_FILTER
// native bilinear
half sample (half2 tc) {
return dot (tex2D(s_image,tc), 1/4.h); // sum components
}
#else
// emulate bilinear
half sample (half2 tc) {
half phalf = .5h/64.h;
half4 res;
res.x = dot (tex2D(s_image,tc+half2(-phalf,-phalf)), 1/4.h); // sum components
res.y = dot (tex2D(s_image,tc+half2(+phalf,-phalf)), 1/4.h); // sum components
res.z = dot (tex2D(s_image,tc+half2(-phalf,+phalf)), 1/4.h); // sum components
res.w = dot (tex2D(s_image,tc+half2(+phalf,+phalf)), 1/4.h); // sum components
return dot (res, 1/4.h); // sum components
}
#endif
half4 main ( v2p I ) : COLOR
{
// sample
half4 accum0;
accum0.x = sample(I.tc0);
accum0.y = sample(I.tc1);
accum0.z = sample(I.tc2);
accum0.w = sample(I.tc3);
half4 accum1;
accum1.x = sample(I.tc4);
accum1.y = sample(I.tc5);
accum1.z = sample(I.tc6);
accum1.w = sample(I.tc7);
half4 accum2;
accum2.x = sample(I.tc0.wz);
accum2.y = sample(I.tc1.wz);
accum2.z = sample(I.tc2.wz);
accum2.w = sample(I.tc3.wz);
half4 accum3;
accum3.x = sample(I.tc4.wz);
accum3.y = sample(I.tc5.wz);
accum3.z = sample(I.tc6.wz);
accum3.w = sample(I.tc7.wz);
// perform accumulation
half4 final;
final.x = dot(accum0,1/4.h);
final.y = dot(accum1,1/4.h);
final.z = dot(accum2,1/4.h);
final.w = dot(accum3,1/4.h);
// OK
return final;
}

View file

@ -0,0 +1,73 @@
#include "common.hlsli"
struct v2p
{
float4 tc0 : TEXCOORD0; // Central
float4 tc1 : TEXCOORD1; // -1,+1
float4 tc2 : TEXCOORD2; // -2,+2
float4 tc3 : TEXCOORD3; // -3,+3
float4 tc4 : TEXCOORD4; // -4,+4
float4 tc5 : TEXCOORD5; // -5,+5
float4 tc6 : TEXCOORD6; // -6,+6
float4 tc7 : TEXCOORD7; // -7,+7
};
// perform 4x4 bilinear, 8x8p, the step (B)
// b): 64x64p => 8x8p
#ifdef FP16_FILTER
// native bilinear
float sample(float2 tc)
{
return dot(tex2D(s_image, tc), 1.0f / 4.0f); // sum components
}
#else
// emulate bilinear
float sample(float2 tc)
{
float pfloat = 0.5f / 64.0f;
float4 res;
res.x = dot(tex2D(s_image, tc + float2(-pfloat, -pfloat)), 1.0f / 4.0f); // sum components
res.y = dot(tex2D(s_image, tc + float2(+pfloat, -pfloat)), 1.0f / 4.0f); // sum components
res.z = dot(tex2D(s_image, tc + float2(-pfloat, +pfloat)), 1.0f / 4.0f); // sum components
res.w = dot(tex2D(s_image, tc + float2(+pfloat, +pfloat)), 1.0f / 4.0f); // sum components
return dot(res, 1.0f / 4.0f); // sum components
}
#endif
float4 main(v2p I) : COLOR
{
// sample
float4 accum0;
accum0.x = sample(I.tc0);
accum0.y = sample(I.tc1);
accum0.z = sample(I.tc2);
accum0.w = sample(I.tc3);
float4 accum1;
accum1.x = sample(I.tc4);
accum1.y = sample(I.tc5);
accum1.z = sample(I.tc6);
accum1.w = sample(I.tc7);
float4 accum2;
accum2.x = sample(I.tc0.wz);
accum2.y = sample(I.tc1.wz);
accum2.z = sample(I.tc2.wz);
accum2.w = sample(I.tc3.wz);
float4 accum3;
accum3.x = sample(I.tc4.wz);
accum3.y = sample(I.tc5.wz);
accum3.z = sample(I.tc6.wz);
accum3.w = sample(I.tc7.wz);
// perform accumulation
float4 final;
final.x = dot(accum0, 1 / 4.h);
final.y = dot(accum1, 1 / 4.h);
final.z = dot(accum2, 1 / 4.h);
final.w = dot(accum3, 1 / 4.h);
// OK
return final;
}

View file

@ -0,0 +1,81 @@
#include "common.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform half4 MiddleGray;
//////////////////////////////////////////////////////////////////////////////////////////
// perform 4x4 bilinear, 8x8p, the step (C)
// c): 8x8p => 1x1p with exp
#ifdef FP16_FILTER
// native bilinear
half sample (half2 tc) {
return dot (tex2D(s_image,tc), 1/4.h); // sum components
}
#else
// emulate bilinear
half sample (half2 tc) {
half phalf = .5h/8.h;
half4 res;
res.x = dot (tex2D(s_image,tc+half2(-phalf,-phalf)), 1/4.h); // sum components
res.y = dot (tex2D(s_image,tc+half2(+phalf,-phalf)), 1/4.h); // sum components
res.z = dot (tex2D(s_image,tc+half2(-phalf,+phalf)), 1/4.h); // sum components
res.w = dot (tex2D(s_image,tc+half2(+phalf,+phalf)), 1/4.h); // sum components
return dot (res, 1/4.h); // sum components
}
#endif
half4 main ( v2p I ) : COLOR
{
// sample
half4 accum0;
accum0.x = sample(I.tc0);
accum0.y = sample(I.tc1);
accum0.z = sample(I.tc2);
accum0.w = sample(I.tc3);
half4 accum1;
accum1.x = sample(I.tc4);
accum1.y = sample(I.tc5);
accum1.z = sample(I.tc6);
accum1.w = sample(I.tc7);
half4 accum2;
accum2.x = sample(I.tc0.wz);
accum2.y = sample(I.tc1.wz);
accum2.z = sample(I.tc2.wz);
accum2.w = sample(I.tc3.wz);
half4 accum3;
accum3.x = sample(I.tc4.wz);
accum3.y = sample(I.tc5.wz);
accum3.z = sample(I.tc6.wz);
accum3.w = sample(I.tc7.wz);
// perform accumulation
half4 final;
final.x = dot(accum0,1/4.h);
final.y = dot(accum1,1/4.h);
final.z = dot(accum2,1/4.h);
final.w = dot(accum3,1/4.h);
half result = dot(final, 1/4.h);
// OK
float scale = MiddleGray.x / (result*MiddleGray.y + MiddleGray.z); // final
float scale_prev = tex2D (s_tonemap,I.tc0).x;
float rvalue = lerp (scale_prev,scale,MiddleGray.w);
// clamp (rvalue, 1.f/8.f, 2.0f);
clamp (rvalue, 1.f/128.f, 20.0f);
return rvalue ;
}

View file

@ -0,0 +1,84 @@
#include "common.hlsli"
struct v2p
{
float4 tc0 : TEXCOORD0; // Central
float4 tc1 : TEXCOORD1; // -1,+1
float4 tc2 : TEXCOORD2; // -2,+2
float4 tc3 : TEXCOORD3; // -3,+3
float4 tc4 : TEXCOORD4; // -4,+4
float4 tc5 : TEXCOORD5; // -5,+5
float4 tc6 : TEXCOORD6; // -6,+6
float4 tc7 : TEXCOORD7; // -7,+7
};
uniform float4 MiddleGray;
// perform 4x4 bilinear, 8x8p, the step (C)
// c): 8x8p => 1x1p with exp
#ifdef FP16_FILTER
// native bilinear
float sample(float2 tc)
{
return dot(tex2D(s_image, tc), 1.0f / 4.0f); // sum components
}
#else
// emulate bilinear
float sample(float2 tc)
{
float pfloat = 0.5f / 8.0f;
float4 res;
res.x = dot(tex2D(s_image, tc + float2(-pfloat, -pfloat)), 1.0f / 4.0f); // sum components
res.y = dot(tex2D(s_image, tc + float2(+pfloat, -pfloat)), 1.0f / 4.0f); // sum components
res.z = dot(tex2D(s_image, tc + float2(-pfloat, +pfloat)), 1.0f / 4.0f); // sum components
res.w = dot(tex2D(s_image, tc + float2(+pfloat, +pfloat)), 1.0f / 4.0f); // sum components
return dot(res, 1.0f / 4.0f); // sum components
}
#endif
float4 main(v2p I) : COLOR
{
// sample
float4 accum0;
accum0.x = sample(I.tc0);
accum0.y = sample(I.tc1);
accum0.z = sample(I.tc2);
accum0.w = sample(I.tc3);
float4 accum1;
accum1.x = sample(I.tc4);
accum1.y = sample(I.tc5);
accum1.z = sample(I.tc6);
accum1.w = sample(I.tc7);
float4 accum2;
accum2.x = sample(I.tc0.wz);
accum2.y = sample(I.tc1.wz);
accum2.z = sample(I.tc2.wz);
accum2.w = sample(I.tc3.wz);
float4 accum3;
accum3.x = sample(I.tc4.wz);
accum3.y = sample(I.tc5.wz);
accum3.z = sample(I.tc6.wz);
accum3.w = sample(I.tc7.wz);
// perform accumulation
float4 final;
final.x = dot(accum0, 1 / 4.h);
final.y = dot(accum1, 1 / 4.h);
final.z = dot(accum2, 1 / 4.h);
final.w = dot(accum3, 1 / 4.h);
float result = dot(final, 1 / 4.h);
// OK
float scale = MiddleGray.x / (result * MiddleGray.y + MiddleGray.z); // final
float scale_prev = tex2D(s_tonemap, I.tc0).x;
float rvalue = lerp(scale_prev, scale, MiddleGray.w);
// clamp (rvalue, 1.f/8.f, 2.0f);
clamp(rvalue, 1.f / 128.f, 20.0f);
return rvalue;
}

View file

@ -0,0 +1,5 @@
@echo off
del test\*.ps
del test\*.vs
FOR %%a IN (*.ps) DO call p %%a
FOR %%b IN (*.vs) DO call v %%b

View file

@ -0,0 +1,15 @@
#include "common.hlsli"
uniform float4 screen_res;
float4 main(p_shadow I) : COLOR
{
float3 col;
float factor = saturate(distance(I.tc0, float2(0.5f, 0.5f)));
col.r = tex2D(s_image, I.tc0 + float2(screen_res.z * factor, 0.0f)).r;
col.g = tex2D(s_image, I.tc0 + float2(-0.866f, -0.5f) * screen_res.zw * factor).g;
col.b = tex2D(s_image, I.tc0 + float2(0.866f, -0.5f) * screen_res.zw * factor).b;
return float4(col, 1.0f);
}

View file

@ -0,0 +1,9 @@
function normal(shader, t_base, t_second, t_detail)
shader:begin("clouds", "clouds")
:fog(false)
:zb(false, false)
:sorting(3, true)
:blend(true, blend.srcalpha, blend.invsrcalpha)
shader:sampler("s_clouds0"):texture("null"):wrap():f_anisotropic()
shader:sampler("s_clouds1"):texture("null"):wrap():f_anisotropic()
end

View file

@ -0,0 +1,30 @@
#include "common.h"
struct v2p
{
half4 color : COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
half2 tc0 : TEXCOORD0;
half2 tc1 : TEXCOORD1;
};
uniform sampler2D s_clouds0 : register(s0);
uniform sampler2D s_clouds1 : register(s1);
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
half4 s0 = tex2D (s_clouds0,I.tc0);
half4 s1 = tex2D (s_clouds1,I.tc1);
half4 mix = I.color * (s0 + s1) ;
#ifdef USE_VTF
half4 rgb = mix ;
#else
half scale = tex2D (s_tonemap,half2(.5h,.5h)).x;
half4 rgb , hi;
tonemap (rgb, hi, mix, scale );
#endif
return half4 (rgb.rgb, rgb.a);
}

View file

@ -0,0 +1,20 @@
#include "common.hlsli"
struct v2p
{
float4 color : COLOR0;
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
};
uniform sampler2D s_clouds0 : register(s0);
uniform sampler2D s_clouds1 : register(s1);
float4 main(v2p I) : COLOR
{
float4 s0 = tex2D(s_clouds0, I.tc0);
float4 s1 = tex2D(s_clouds1, I.tc1);
float4 mix = I.color * (s0 + s1);
return mix;
}

View file

@ -0,0 +1,12 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("clouds","clouds")
: fog (false)
-- : zb (true,false)
-- Igor: avoid siluets.
: zb (false,false)
: sorting (3, true)
: blend (true, blend.srcalpha,blend.invsrcalpha)
shader:sampler ("s_clouds0") :texture ("null") : wrap() : f_anisotropic()
shader:sampler ("s_clouds1") :texture ("null") : wrap() : f_anisotropic()
shader:sampler ("s_tonemap") :texture ("$user$tonemap")
end

View file

@ -0,0 +1,43 @@
#include "common.h"
#include "shared\cloudconfig.h"
struct vi
{
float4 p : POSITION ;
float4 dir : COLOR0 ; // dir0,dir1(w<->z)
float4 color : COLOR1 ; // rgb. intensity
};
struct vf
{
float4 hpos : POSITION ;
float4 color : COLOR0 ; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
float2 tc0 : TEXCOORD0 ;
float2 tc1 : TEXCOORD1 ;
};
vf main (vi v)
{
vf o;
o.hpos = mul (m_WVP, v.p); // xform, input in world coords
// if (length(float3(v.p.x,0,v.p.z))>CLOUD_FADE) o.color.w = 0 ;
// generate tcs
float2 d0 = v.dir.xy*2-1;
float2 d1 = v.dir.wz*2-1;
float2 _0 = v.p.xz * CLOUD_TILE0 + d0*timers.z*CLOUD_SPEED0;
float2 _1 = v.p.xz * CLOUD_TILE1 + d1*timers.z*CLOUD_SPEED1;
o.tc0 = _0; // copy tc
o.tc1 = _1; // copy tc
o.color = v.color ; // copy color, low precision, cannot prescale even by 2
o.color.w *= pow (v.p.y,25);
#ifdef USE_VTF
float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
o.color.rgb *= scale ; // high precision
#endif
return o;
}

View file

@ -0,0 +1,31 @@
#include "common.hlsli"
#include "shared\cloudconfig.hlsli"
struct vi
{
float4 p : POSITION;
float4 dir : COLOR0; // dir0,dir1(w<->z)
float4 color : COLOR1; // rgb. intensity
};
struct vf
{
float4 hpos : POSITION;
float4 color : COLOR0;
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
};
void main(in vi v, out vf o)
{
o.hpos = mul(m_WVP, v.p);
float2 d0 = v.dir.xy * 2.0f - 1.0f;
float2 d1 = v.dir.wz * 2.0f - 1.0f;
o.tc0 = v.p.xz * CLOUD_TILE0 + d0 * timers.z * CLOUD_SPEED0;
o.tc1 = v.p.xz * CLOUD_TILE1 + d1 * timers.z * CLOUD_SPEED1;
o.color = v.color;
o.color.w *= pow(v.p.y, 25);
}

View file

@ -0,0 +1,164 @@
#include "common.h"
//#define USE_SUPER_SPECULAR
//#define USE_ORIGINAL_SSAO
//#define HBAO_WORLD_JITTER
uniform sampler2D s_half_depth;
#include "lmodel.h"
#include "hmodel.h"
#include "ssao_blur.ps"
#include "ssao.ps"
#include "ssao_hbao.ps"
struct _input {
float4 hpos : POSITION ;
#ifdef USE_VTF
float4 tc0 : TEXCOORD0 ; // tc.xy, tc.w = tonemap scale
#else
float2 tc0 : TEXCOORD0 ; // tc.xy
#endif
float2 tcJ : TEXCOORD1; // jitter coords
};
struct _out {
half4 low : COLOR0 ;
half4 high : COLOR1 ;
};
uniform sampler1D fog_table ;
_out main ( _input I )
{
// Sample the buffers:
float4 P = tex2D (s_position, I.tc0); // position.(mtl or sun)
half4 N = tex2D (s_normal, I.tc0); // normal.hemi
half4 D = tex2D (s_diffuse, I.tc0); // rgb.gloss
half4 L = tex2D (s_accumulator, I.tc0); // diffuse.specular
// D.rgb *= (D.rgb+0.1); // rasie texures contrast
#ifdef USE_SUPER_SPECULAR
{
half ds = dot (D.rgb,1.h/3.h) ;
D.w = max (D.w, ds*ds/8.h) ;
}
#endif
#ifdef FORCE_GLOSS
D.w = FORCE_GLOSS ;
#endif
#ifdef USE_GAMMA_22
D.rgb = (D.rgb*D.rgb) ; // pow(2.2)
#endif
// static sun
half mtl = P.w;
#ifdef USE_R2_STATIC_SUN
half sun_occ = P.w*2 ;
mtl = xmaterial;
L += Ldynamic_color * sun_occ * plight_infinity (mtl, P.xyz, N.xyz, Ldynamic_dir);
#endif
// hemisphere
half3 hdiffuse,hspecular;
// Calculate SSAO
//#ifdef USE_SSAO_BLUR
// half occ = ssao_blur_ps(I.tc0);
#ifdef USE_HBAO
float occ = calc_hbao(P.z, N, I.tc0);
#else
half occ = calc_ssao(P, N, I.tc0, I.tcJ);
#endif
hmodel (hdiffuse, hspecular, mtl, N.w, D.w, P.xyz, N.xyz);
// hmodel (hdiffuse, hspecular, mtl, 1, D.w, P.xyz, N.xyz);
// hdiffuse*=hdiffuse; //. high contrast hemi
// hdiffuse*=(D.rgb*0.8 + 0.2h); // rise texture contrast for diffuse lighting
// hdiffuse = 0.8;
// hdiffuse *= (occ*(D.rgb + .1h));
hdiffuse *= occ;
hspecular *= occ;
half4 light = half4 (L.rgb + hdiffuse, L.w) ;
half4 C = D*light ; // rgb.gloss * light(diffuse.specular)
// half3 spec = (C.rgb*.5h + .5h)*C.w + hspecular + hspecular + hspecular; // replicated specular
half3 spec = C.www + hspecular; // replicated specular
#ifdef USE_SUPER_SPECULAR
spec = (C.rgb*.5h + .5h)*C.w + hspecular ;
#endif
// half3 color = C.rgb + D.rgb*spec ;
// half3 color = C.rgb + (D.rgb*spec+spec)/0.5h;
half3 color = C.rgb + spec ;
// half3 color = C.rgb + D.rgb*spec+hspecular+hspecular ; // More realistic and contrast specular - Ugrumiy edition
////////////////////////////////////////////////////////////////////////////////
/// For Test ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#ifdef DBG_TEST_NMAP
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + N;
#endif
#ifdef DBG_TEST_NMAP_SPEC
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + N + spec;
#endif
#ifdef DBG_TEST_LIGHT
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb;
#endif
#ifdef DBG_TEST_LIGHT_SPEC
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + spec;
#endif
#ifdef DBG_TEST_SPEC
//. only lighting and specular
color = spec;
#endif
////////////////////////////////////////////////////////////////////////////////
// here should be distance fog
float3 pos = P.xyz;
float distance = length (pos);
float fog = saturate (distance*fog_params.w + fog_params.x); //
color = lerp (color,fog_color,fog); //
half skyblend = saturate (fog*fog);
#ifdef DBG_TMAPPING
color = D.xyz;
#endif
// final tone-mapping
#ifdef USE_VTF
half tm_scale = I.tc0.w; // interpolated from VS
#else
half tm_scale = tex2D (s_tonemap,I.tc0).x;
#endif
#ifdef USE_SUPER_SPECULAR
color = spec - hspecular ;
#endif
// color = N; //show normals
// color = N.w; //show normals
// color = float4(occ.xxx,1.0f); //show occlusion
// color = occ;
_out o;
tonemap (o.low, o.high, color, tm_scale ) ;
o.low.a = skyblend ;
o.high.a = skyblend ;
// o.low = skyblend;
// o.hight = 0;
return o;
}

View file

@ -0,0 +1,63 @@
#include "common.hlsli"
uniform sampler2D s_half_depth;
uniform float3x4 m_v2w;
#include "lmodel.hlsli"
#include "hmodel.hlsli"
#include "ssao_blur.ps.hlsl"
#include "ssao.ps.hlsl"
struct _input
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0;
float2 tcJ : TEXCOORD1;
};
float4 main(_input I) : COLOR0
{
// Sample the buffers:
float4 P = tex2D(s_position, I.tc0); // position.(mtl or sun)
float4 N = tex2D(s_normal, I.tc0); // normal.hemi
float4 D = tex2D(s_diffuse, I.tc0); // rgb.gloss
float4 L = tex2D(s_accumulator, I.tc0); // diffuse.specular
#ifdef USE_GAMMA_22
D.rgb = (D.rgb * D.rgb);
#endif
// static sun
float mtl = P.w;
#ifdef USE_R2_STATIC_SUN
float sun_occ = P.w * 2.0f;
mtl = xmaterial;
L += Ldynamic_color * sun_occ * plight_infinity(mtl, P.xyz, N.xyz, Ldynamic_dir);
#endif
// Calculate SSAO
// #ifdef USE_SSAO_BLUR
// float occ = ssao_blur_ps(I.tc0);
float occ = calc_ssao(P, N, I.tc0, I.tcJ);
float3 hdiffuse, hspecular;
hmodel(hdiffuse, hspecular, mtl, N.w, D.w, P.xyz, N.xyz);
hdiffuse *= occ;
hspecular *= occ;
float4 light = float4(L.xyz + hdiffuse, L.w);
float4 C = D * light;
float3 spec = C.www + hspecular;
spec *= 0.4f;
float3 color = C.xyz + spec;
// here should be distance fog
float distance = length(P.xyz);
float fog = saturate(distance * fog_params.w + fog_params.x);
color = lerp(color, fog_color, fog);
return float4(color, fog * fog);
}

View file

@ -0,0 +1,35 @@
#include "common.h"
struct _in {
float4 p : POSITION ; // xy=pos, zw=tc0
float2 tcJ : TEXCOORD0; // jitter coords
};
struct _out {
float4 hpos : POSITION ;
#ifdef USE_VTF
float4 tc0 : TEXCOORD0 ; // tc.xy, tc.w = tonemap scale
#else
float2 tc0 : TEXCOORD0 ; // tc.xy
#endif
float2 tcJ : TEXCOORD1; // jitter coords
};
//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
_out main ( _in I )
{
_out O;
O.hpos = float4 (I.p.x, -I.p.y, 0, 1);
#ifdef USE_VTF
float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
O.tc0 = float4 (I.p.zw, scale, scale);
#else
O.tc0 = I.p.zw ;
#endif
O.tcJ = I.tcJ;
return O;
}
FXVS;

View file

@ -0,0 +1,22 @@
#include "common.hlsli"
struct _in
{
float4 p : POSITION;
float2 tcJ : TEXCOORD0;
};
struct _out
{
float4 hpos : POSITION;
float4 tc0 : TEXCOORD0;
float2 tcJ : TEXCOORD1;
};
void main(in _in I, out _out O)
{
O.hpos = float4(I.p.x, -I.p.y, 0.0f, 1.0f);
O.tc0 = float4(I.p.zw, 1.0f, 1.0f);
O.tcJ = I.tcJ;
}

View file

@ -0,0 +1,75 @@
#include "common.h"
#include "mblur.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Center
float4 tc1: TEXCOORD1; // LT
float4 tc2: TEXCOORD2; // RB
float4 tc3: TEXCOORD3; // RT
float4 tc4: TEXCOORD4; // LB
float4 tc5: TEXCOORD5; // Left / Right
float4 tc6: TEXCOORD6; // Top / Bottom
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform sampler2D s_distort;
uniform half4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
uniform half4 e_weights; // x=norm, y=depth, z=clr
uniform half4 e_kernel; // x=norm, y=depth, z=clr
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
// Normal discontinuety filter
half3 nc = tex2D (s_normal, I.tc0);
half4 nd;
nd.x = dot (nc, (half3)tex2D(s_normal,I.tc1));
nd.y = dot (nc, (half3)tex2D(s_normal,I.tc2));
nd.z = dot (nc, (half3)tex2D(s_normal,I.tc3));
nd.w = dot (nc, (half3)tex2D(s_normal,I.tc4));
nd -= e_barrier.x ;
nd = step (0,nd); // bw
half ne = saturate (dot(nd,e_weights.x));
// Opposite coords
float4 tc5r = I.tc5.wzyx;
float4 tc6r = I.tc6.wzyx;
// Depth filter : compute gradiental difference: (c-sample1)+(c-sample1_opposite)
half4 dc = tex2D (s_position, I.tc0);
half4 dd;
dd.x = (half)tex2D(s_position,I.tc1).z + (half)tex2D(s_position,I.tc2).z;
dd.y = (half)tex2D(s_position,I.tc3).z + (half)tex2D(s_position,I.tc4).z;
dd.z = (half)tex2D(s_position,I.tc5).z + (half)tex2D(s_position,tc5r).z;
dd.w = (half)tex2D(s_position,I.tc6).z + (half)tex2D(s_position,tc6r).z;
dd = abs(2*dc.z-dd)-e_barrier.y;
dd = step (dd,0); // bw
half de = saturate (dot(dd,e_weights.y));
// weight
half w = (1-de*ne)*e_kernel.x; // 0 - no aa, 1=full aa
#ifdef USE_DISTORT
half4 distort = tex2D (s_distort, I.tc0) ;
half2 doffs = (distort.xy-.5h)*def_distort ;
float2 center = I.tc0 + doffs;
#else
float2 center = I.tc0;
#endif
// Smoothed color
// (a-c)*w + c = a*w + c(1-w)
float2 offset = center * (1-w);
half4 s0 = tex2D (s_image, offset + I.tc1*w);
half4 s1 = tex2D (s_image, offset + I.tc2*w);
half4 s2 = tex2D (s_image, offset + I.tc3*w);
half4 s3 = tex2D (s_image, offset + I.tc4*w);
half3 final = mblur (center, dc, (s0+s1+s2+s3)/4.h);
half3 bloom = tex2D (s_bloom, I.tc0);
return combine_bloom (final,bloom);
}

View file

@ -0,0 +1,48 @@
#include "common.hlsli"
#include "mblur.hlsli"
#include "dof.hlsli"
struct v2p
{
float4 tc0 : TEXCOORD0; // Center
float4 tc1 : TEXCOORD1; // LT
float4 tc2 : TEXCOORD2; // RB
float4 tc3 : TEXCOORD3; // RT
float4 tc4 : TEXCOORD4; // LB
float4 tc5 : TEXCOORD5; // Left / Right
float4 tc6 : TEXCOORD6; // Top / Bottom
};
uniform sampler2D s_distort;
#define EPSDEPTH 0.001
float4 main(v2p I) : COLOR
{
#ifdef USE_DISTORT
float depth = tex2D(s_position, I.tc0).z;
float4 distort = tex2D(s_distort, I.tc0);
float2 offset = (distort.xy - (127.0f / 255.0f)) * def_distort;
float2 center = I.tc0 + offset;
float depth_x = tex2D(s_position, center).z;
if ((depth_x + EPSDEPTH) < depth)
{
center = I.tc0;
}
#else
float2 center = I.tc0;
#endif
float3 img = dof(center);
float4 bloom = tex2D(s_bloom, center);
img = mblur(center, tex2D(s_position, I.tc0), img.rgb);
img = tonemap(img, tex2Dlod(s_tonemap, float4(0.5f, 0.5f, 0.5f, 0.5f)).x);
#ifdef USE_DISTORT
float3 blurred = bloom * def_hdr;
img = lerp(img, blurred, distort.z);
#endif
return combine_bloom(img, bloom);
}

View file

@ -0,0 +1,74 @@
#include "common.h"
#include "mblur.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Center
float4 tc1: TEXCOORD1; // LT
float4 tc2: TEXCOORD2; // RB
float4 tc3: TEXCOORD3; // RT
float4 tc4: TEXCOORD4; // LB
float4 tc5: TEXCOORD5; // Left / Right
float4 tc6: TEXCOORD6; // Top / Bottom
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform sampler2D s_distort;
uniform half4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
uniform half4 e_weights; // x=norm, y=depth, z=clr
uniform half4 e_kernel; // x=norm, y=depth, z=clr
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
// Normal discontinuety filter
half3 nc = tex2D (s_normal, I.tc0);
half4 nd;
nd.x = dot (nc, (half3)tex2D(s_normal,I.tc1));
nd.y = dot (nc, (half3)tex2D(s_normal,I.tc2));
nd.z = dot (nc, (half3)tex2D(s_normal,I.tc3));
nd.w = dot (nc, (half3)tex2D(s_normal,I.tc4));
nd -= e_barrier.x ;
nd = step (0,nd); // bw
half ne = saturate (dot(nd,e_weights.x));
// Opposite coords
float4 tc5r = I.tc5.wzyx;
float4 tc6r = I.tc6.wzyx;
// Depth filter : compute gradiental difference: (c-sample1)+(c-sample1_opposite)
half4 dc = tex2D (s_position, I.tc0);
half4 dd;
dd.x = (half)tex2D(s_position,I.tc1).z + (half)tex2D(s_position,I.tc2).z;
dd.y = (half)tex2D(s_position,I.tc3).z + (half)tex2D(s_position,I.tc4).z;
dd.z = (half)tex2D(s_position,I.tc5).z + (half)tex2D(s_position,tc5r).z;
dd.w = (half)tex2D(s_position,I.tc6).z + (half)tex2D(s_position,tc6r).z;
dd = abs(2*dc.z-dd)-e_barrier.y;
dd = step (dd,0); // bw
half de = saturate (dot(dd,e_weights.y));
// weight
half w = (1-de*ne)*e_kernel.x; // 0 - no aa, 1=full aa
#ifdef USE_DISTORT
half4 distort = tex2D (s_distort, I.tc0);
half2 doffs = (distort.xy-.5h)*def_distort;
float2 center = I.tc0 + doffs;
#else
float2 center = I.tc0;
#endif
// Smoothed color
// (a-c)*w + c = a*w + c(1-w)
float2 offset = center * (1-w);
half4 s0 = tex2D (s_image, offset + I.tc1*w);
half4 s1 = tex2D (s_image, offset + I.tc2*w);
half4 s2 = tex2D (s_image, offset + I.tc3*w);
half4 s3 = tex2D (s_image, offset + I.tc4*w);
half3 final = mblur (center, dc, (s0+s1+s2+s3)/4.h);
return combine_bloom(final,tex2D (s_bloom, I.tc0));
}

View file

@ -0,0 +1,3 @@
#define USE_DISTORT //- shader defined
#include "combine_2_AA.ps"

View file

@ -0,0 +1,178 @@
#include "common.h"
#include "mblur.h"
#include "dof.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Center
float4 tc1: TEXCOORD1; // LT
float4 tc2: TEXCOORD2; // RB
float4 tc3: TEXCOORD3; // RT
float4 tc4: TEXCOORD4; // LB
float4 tc5: TEXCOORD5; // Left / Right
float4 tc6: TEXCOORD6; // Top / Bottom
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform sampler2D s_distort;
uniform half4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
uniform half4 e_weights; // x=norm, y=depth, z=clr
uniform half4 e_kernel; // x=norm, y=depth, z=clr
#define EPSDEPTH 0.001
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( v2p I ) : COLOR
{
#ifdef USE_DISTORT
half depth = tex2D (s_position, I.tc0).z;
half4 distort = tex2D (s_distort, I.tc0) ;
// half2 offset = (distort.xy-.5h)*def_distort ;
half2 offset = (distort.xy-(127.0h/255.0h))*def_distort; // fix newtral offset
float2 center = I.tc0 + offset;
half depth_x = tex2D (s_position, center).z ;
if ((depth_x+EPSDEPTH)<depth) center = I.tc0; // discard new sample
#else
float2 center = I.tc0 ;
#endif
//half3 img = tex2D (s_image, center);
half3 img = dof(center);
half4 bloom = tex2D (s_bloom, center);
img = mblur (center,tex2D(s_position,I.tc0),img.rgb);
#ifdef USE_DISTORT
half3 blurred = bloom*def_hdr ;
img = lerp (img,blurred,distort.z);
#endif
return combine_bloom (img,bloom);
}
/**/
/*
#define NEAR 0.2h
//#define MINDIST 0.4h
#define MINDIST 1.0h
//#define MAXDIST 100.h
//#define MAXDIST 300.h
#define MAXDIST 1.1h
#define MAXCOF 5.h
#define MAXCOF_NEAR 100.h
#define EPSDEPTH 0.0001h
half4 main ( v2p I ) : COLOR
{
// Scale tap offsets based on render target size
float2 center = I.tc0;
half depth = tex2D(s_position,center).z;
if (depth<=EPSDEPTH) depth = MAXDIST;
half blur = saturate( (depth-MINDIST)/(MAXDIST-MINDIST) );
blur*=blur;
//half blur_near = pow(saturate( 1-(depth-NEAR)/MINDIST ), 2) * MAXCOF_NEAR;
//half blur = (blur_near+blur_far);
// half blur = 1;
half2 scale = half2 (.5f / 1024.h, .5f / 768.h) * MAXCOF * blur;
// poison
half2 o [12];
o[0] = half2(-0.326212f , -0.405810f)*scale;
o[1] = half2(-0.840144f , -0.073580f)*scale;
o[2] = half2(-0.695914f , 0.457137f)*scale;
o[3] = half2(-0.203345f , 0.620716f)*scale;
o[4] = half2( 0.962340f , -0.194983f)*scale;
o[5] = half2( 0.473434f , -0.480026f)*scale;
o[6] = half2( 0.519456f , 0.767022f)*scale;
o[7] = half2( 0.185461f , -0.893124f)*scale;
o[8] = half2( 0.507431f , 0.064425f)*scale;
o[9] = half2( 0.896420f , 0.412458f)*scale;
o[10] = half2(-0.321940f , -0.932615f)*scale;
o[11] = half2(-0.791559f , -0.597710f)*scale;
// sample
half3 sum = tex2D(s_image,center);
half contrib = 1.h;
for (int i=0; i<12; i++)
{
float2 tap = center + o[i];
half4 tap_color = tex2D (s_image,tap);
half tap_depth = tex2D (s_position,tap).z;
half tap_contrib = 1.h; //(tap_depth>depth)?1.h:0.h;
sum += tap_color * tap_contrib;
contrib += tap_contrib ;
}
return half4 (sum/contrib,1);
}
/**/
/*
// Igor: cheap dof
#define NEAR 0.2h
#define MINDIST 0.4h
#define MAXDIST 100.h
//#define MAXDIST 10.h
#define MAXCOF 5.h
#define MAXCOF_NEAR 100.h
#define EPSDEPTH 0.0001h
half4 main ( v2p I ) : COLOR
{
#ifdef USE_DISTORT
half depth = tex2D (s_position, I.tc0).z;
half4 distort = tex2D (s_distort, I.tc0) ;
half2 offset = (distort.xy-.5h)*def_distort ;
float2 center = I.tc0 + offset;
half depth_x = tex2D (s_position, center).z ;
if ((depth_x+EPSDEPTH)<depth) center = I.tc0; // discard new sample
#else
float2 center = I.tc0 ;
#endif
half3 img = tex2D (s_image, center);
half4 bloom = tex2D (s_bloom, center);
img = mblur (center,tex2D(s_position,I.tc0),img.rgb);
#ifdef USE_DISTORT
// half3 blurred = bloom*def_hdr ;
// img = lerp (img,blurred,distort.z);
#endif
#ifndef USE_DISTORT
half depth = tex2D(s_position,center).z;
#endif // USE_DISTORT
if (depth<=EPSDEPTH) depth = MAXDIST;
half3 blurred = bloom*def_hdr/4;
half blur = saturate( (depth-MINDIST)/(MAXDIST-MINDIST) );
blur *= blur;
blur *= 0.5;
// blur *= 1;
img = lerp( img, blurred, blur);
return combine_bloom (img,bloom);
}
/**/
/*
// Igor: original
half4 main ( v2p I ) : COLOR
{
#ifdef USE_DISTORT
half depth = tex2D (s_position, I.tc0).z;
half4 distort = tex2D (s_distort, I.tc0) ;
half2 offset = (distort.xy-.5h)*def_distort ;
float2 center = I.tc0 + offset;
half depth_x = tex2D (s_position, center).z ;
if ((depth_x+EPSDEPTH)<depth) center = I.tc0; // discard new sample
#else
float2 center = I.tc0 ;
#endif
half3 img = tex2D (s_image, center);
half4 bloom = tex2D (s_bloom, center);
img = mblur (center,tex2D(s_position,I.tc0),img.rgb);
#ifdef USE_DISTORT
half3 blurred = bloom*def_hdr ;
img = lerp (img,blurred,distort.z);
#endif
return combine_bloom (img,bloom);
}
/**/

View file

@ -0,0 +1,3 @@
#define USE_DISTORT //- shader defined
#include "combine_2_NAA.ps"

View file

@ -0,0 +1,8 @@
function normal(shader, t_base, t_second, t_detail)
shader:begin("combine_1", "combine_volumetric")
:fog(false)
:zb(false, false)
:blend(true, blend.one, blend.one)
:sorting(2, false)
shader:sampler("s_vollight"):texture("$user$generic2")
end

View file

@ -0,0 +1,41 @@
#include "common.h"
// Igor: used for volumetric light
uniform sampler2D s_vollight;
struct _input {
float4 hpos : POSITION;
#ifdef USE_VTF
float4 tc0 : TEXCOORD0; // tc.xy, tc.w = tonemap scale
#else
float2 tc0 : TEXCOORD0; // tc.xy
#endif
};
struct _out {
half4 low : COLOR0;
half4 high : COLOR1;
};
_out main ( _input I )
{
// final tone-mapping
#ifdef USE_VTF
half tm_scale = I.tc0.w; // interpolated from VS
#else
half tm_scale = tex2D(s_tonemap,I.tc0).x;
#endif
_out o;
half4 color;
color = tex2D(s_vollight, I.tc0);
tonemap(o.low, o.high, color, tm_scale );
// o.low = half4(1,0,0,0);
// o.high = half4(0,0,0,0);
// o.low = half4(0,0,0,0);
return o;
}

View file

@ -0,0 +1,8 @@
#include "common.hlsli"
uniform sampler2D s_vollight;
float4 main(float2 tc : TEXCOORD0) : COLOR
{
return tex2D(s_vollight, tc);
}

View file

@ -0,0 +1,10 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("combine_1", "combine_volumetric")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
-- : aref (true,0) -- enable to save bandwith?
: sorting (2, false)
shader:sampler ("s_vollight") :texture ("$user$generic2")
shader:sampler ("s_tonemap") :texture ("$user$tonemap")
end

View file

@ -0,0 +1,309 @@
#ifndef COMMON_H
#define COMMON_H
// #define USE_SUPER_SPECULAR
#include "shared\common.h"
//////////////////////////////////////////////////////////////////////////////////////////
// *** options
// #define DBG_TEST_NMAP
// #define DBG_TEST_NMAP_SPEC
// #define DBG_TEST_SPEC
// #define DBG_TEST_LIGHT
// #define DBG_TEST_LIGHT_SPEC
// #define USE_GAMMA_22
// #define USE_SJITTER
// #define USE_SUNFILTER
// #define USE_FETCH4
// #define USE_MBLUR //- HW-options defined
// #define USE_HWSMAP //- HW-options defined
// #define USE_HWSMAP_PCF //- nVidia GF3+, R600+
// #define USE_BRANCHING //- HW-options defined
// #define USE_VTF //- HW-options defined, VertexTextureFetch
// #define FP16_FILTER //- HW-options defined
// #define FP16_BLEND //- HW-options defined
//
// #define USE_PARALLAX //- shader defined
// #define USE_TDETAIL //- shader defined
// #define USE_LM_HEMI //- shader defined
// #define USE_DISTORT //- shader defined
// #define USE_SUNMASK //- shader defined
// #define DBG_TMAPPING
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef SMAP_size
#define SMAP_size 1024
#endif
#define PARALLAX_H 0.02
#define parallax float2(PARALLAX_H, -PARALLAX_H/2)
#ifdef USE_R2_STATIC_SUN
# define xmaterial half(1.0h/4.h)
#else
# define xmaterial half(L_material.w)
#endif
//////////////////////////////////////////////////////////////////////////////////////////
uniform half4 hemi_cube_pos_faces;
uniform half4 hemi_cube_neg_faces;
uniform half4 L_material; // 0,0,0,mid
uniform half4 Ldynamic_color; // dynamic light color (rgb1) - spot/point
uniform half4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point
uniform half4 Ldynamic_dir; // dynamic light direction - sun
uniform half4 J_direct [6];
uniform half4 J_spot [6];
half calc_fogging (half4 w_pos) { return dot(w_pos,fog_plane); }
half2 calc_detail (half3 w_pos) {
float dtl = distance (w_pos,eye_position)*dt_params.w;
dtl = min (dtl*dtl, 1);
half dt_mul = 1 - dtl; // dt* [1 .. 0 ]
half dt_add = .5 * dtl; // dt+ [0 .. 0.5]
return half2 (dt_mul,dt_add);
}
float3 calc_reflection (float3 pos_w, float3 norm_w)
{
return reflect(normalize(pos_w-eye_position), norm_w);
}
float3 calc_sun_r1 (float3 norm_w) { return L_sun_color*saturate(dot((norm_w),-L_sun_dir_w)); }
float3 calc_model_hemi_r1 (float3 norm_w) { return max(0,norm_w.y)*L_hemi_color; }
float3 calc_model_lq_lighting (float3 norm_w) { return L_material.x*calc_model_hemi_r1(norm_w) + L_ambient + L_material.y*calc_sun_r1(norm_w); }
//////////////////////////////////////////////////////////////////////////////////////////
struct v_static {
float4 P : POSITION; // (float,float,float,1)
float4 Nh : NORMAL; // (nx,ny,nz,hemi occlusion)
float4 T : TANGENT; // tangent
float4 B : BINORMAL; // binormal
float2 tc : TEXCOORD0; // (u,v)
float2 lmh : TEXCOORD1; // (lmu,lmv)
float4 color : COLOR0; // (r,g,b,dir-occlusion)
};
struct v_tree {
float4 P : POSITION; // (float,float,float,1)
float4 Nh : NORMAL; // (nx,ny,nz)
float3 T : TANGENT; // tangent
float3 B : BINORMAL; // binormal
float4 tc : TEXCOORD0; // (u,v,frac,???)
};
struct v_model {
float4 P : POSITION; // (float,float,float,1)
float3 N : NORMAL; // (nx,ny,nz)
float3 T : TANGENT; // (nx,ny,nz)
float3 B : BINORMAL; // (nx,ny,nz)
float2 tc : TEXCOORD0; // (u,v)
};
struct v_detail {
float4 pos : POSITION; // (float,float,float,1)
int4 misc : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id)
};
#ifdef USE_HWSMAP
struct v_shadow_direct_aref
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float2 tc0: TEXCOORD1; // Diffuse map for aref
};
struct v_shadow_direct
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
};
#else
struct v_shadow_direct_aref
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float depth: TEXCOORD0; // Depth
float2 tc0: TEXCOORD1; // Diffuse map for aref
};
struct v_shadow_direct
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float depth: TEXCOORD0; // Depth
};
#endif
//////////////////////////////////////////////////////////////////////////////////////////
struct p_bumped {
float4 hpos : POSITION;
#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI)
float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion
#else
float2 tcdh : TEXCOORD0; // Texture coordinates
#endif
float4 position : TEXCOORD1; // position + hemi
half3 M1 : TEXCOORD2; // nmap 2 eye - 1
half3 M2 : TEXCOORD3; // nmap 2 eye - 2
half3 M3 : TEXCOORD4; // nmap 2 eye - 3
#ifdef USE_TDETAIL
float2 tcdbump : TEXCOORD5; // d-bump
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD6; // lm-hemi
#endif
#else
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD5; // lm-hemi
#endif
#endif
};
//////////////////////////////////////////////////////////////////////////////////////////
struct p_flat {
float4 hpos : POSITION;
#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI)
float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion
#else
float2 tcdh : TEXCOORD0; // Texture coordinates
#endif
float4 position : TEXCOORD1; // position + hemi
half3 N : TEXCOORD2; // Eye-space normal (for lighting)
#ifdef USE_TDETAIL
float2 tcdbump : TEXCOORD3; // d-bump
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD4; // lm-hemi
#endif
#else
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD3; // lm-hemi
#endif
#endif
};
//////////////////////////////////////////////////////////////////////////////////////////
struct f_deffer {
half4 position : COLOR0; // px,py,pz, m-id
half4 Ne : COLOR1; // nx,ny,nz, hemi
half4 C : COLOR2; // r, g, b, gloss
};
//////////////////////////////////////////////////////////////////////////////////////////
struct p_screen {
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // Texture coordinates (for sampling maps)
};
//////////////////////////////////////////////////////////////////////////////////////////
// Geometry phase / deferring //
uniform sampler2D s_base; //
uniform sampler2D s_bump; //
uniform sampler2D s_bumpX; //
uniform sampler2D s_detail; //
uniform sampler2D s_detailBump; //
uniform sampler2D s_detailBumpX; // Error for bump detail
uniform sampler2D s_bumpD; //
uniform sampler2D s_hemi; //
uniform sampler2D s_mask; //
uniform sampler2D s_dt_r; //
uniform sampler2D s_dt_g; //
uniform sampler2D s_dt_b; //
uniform sampler2D s_dt_a; //
uniform sampler2D s_dn_r; //
uniform sampler2D s_dn_g; //
uniform sampler2D s_dn_b; //
uniform sampler2D s_dn_a; //
//////////////////////////////////////////////////////////////////////////////////////////
// Lighting/shadowing phase //
uniform sampler2D s_depth; //
uniform sampler2D s_position; //
uniform sampler2D s_normal; //
uniform sampler s_lmap; // 2D/cube projector lightmap
uniform sampler3D s_material; //
uniform sampler1D s_attenuate; //
//////////////////////////////////////////////////////////////////////////////////////////
// Combine phase //
uniform sampler2D s_diffuse; // rgb.a = diffuse.gloss
uniform sampler2D s_accumulator; // rgb.a = diffuse.specular
uniform sampler2D s_generic; //
uniform sampler2D s_bloom; //
uniform sampler s_image; // used in various post-processing
uniform sampler2D s_tonemap; // actually MidleGray / exp(Lw + eps)
//////////////////////////////////////////////////////////////////////////////////////////
// Defines //
#define def_gloss half(2.f /255.f)
#define def_aref half(200.f/255.f)
#define def_dbumph half(0.333f)
#define def_virtualh half(0.05f) // 5cm
#define def_distort half(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it
#define def_hdr half(9.h) // hight luminance range half(3.h)
#define def_hdr_clip half(0.75h) //
//////////////////////////////////////////////////////////////////////////////////////////
#define LUMINANCE_VECTOR half3(0.3f, 0.38f, 0.22f)
void tonemap (out half4 low, out half4 high, half3 rgb, half scale)
{
rgb = rgb*scale ;
const float fWhiteIntensity = 1.7;
const float fWhiteIntensitySQR = fWhiteIntensity*fWhiteIntensity;
#ifdef USE_BRANCHING // ps_3_0
//low = rgb.xyzz ;
low = ( (rgb*(1+rgb/fWhiteIntensitySQR)) / (rgb+1) ).xyzz;
high = low/def_hdr ; // 8x dynamic range
#else
low = half4 ( ( (rgb*(1+rgb/fWhiteIntensitySQR)) / (rgb+1) ), 0 ) ;
high = half4 (rgb/def_hdr, 0 ) ; // 8x dynamic range
#endif
/*
rgb = rgb*scale;
low = rgb.xyzz;
high = low/def_hdr; // 8x dynamic range
*/
// low = half4 (rgb, 0);
// rgb /= def_hdr ;
// high = half4 (rgb, dot(rgb,0.333f)-def_hdr_clip) ;
}
half4 combine_bloom (half3 low, half4 high) {
return half4(low + high*high.a, 1.h);
}
float3 v_hemi (float3 n) { return L_hemi_color*(.5f + .5f*n.y); }
float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color*(w + (1-w)*n.y); }
float3 v_sun (float3 n) { return L_sun_color*dot(n,-L_sun_dir_w); }
float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); }
half3 p_hemi (float2 tc) {
// half3 t_lmh = tex2D (s_hemi, tc);
// return dot (t_lmh,1.h/4.h);
half4 t_lmh = tex2D (s_hemi, tc);
return t_lmh.a;
}
half get_hemi( half4 lmh)
{
return lmh.a;
}
half get_sun( half4 lmh)
{
return lmh.g;
}
// contrast function
half Contrast(half Input, half ContrastPower)
{
//piecewise contrast function
bool IsAboveHalf = Input > 0.5 ;
half ToRaise = saturate(2*(IsAboveHalf ? 1-Input : Input));
half Output = 0.5*pow(ToRaise, ContrastPower);
Output = IsAboveHalf ? 1-Output : Output;
return Output;
}
#define FXPS technique _render{pass _code{PixelShader=compile ps_3_0 main();}}
#define FXVS technique _render{pass _code{VertexShader=compile vs_3_0 main();}}
#endif

View file

@ -0,0 +1,350 @@
#ifndef COMMON_H
#define COMMON_H
// #define USE_SUPER_SPECULAR
#include "shared\common.hlsli"
//////////////////////////////////////////////////////////////////////////////////////////
// *** options
// #define DBG_TEST_NMAP
// #define DBG_TEST_NMAP_SPEC
// #define DBG_TEST_SPEC
// #define DBG_TEST_LIGHT
// #define DBG_TEST_LIGHT_SPEC
// #define USE_GAMMA_22
// #define USE_FETCH4
// #define USE_HWSMAP //- HW-options defined
// #define USE_HWSMAP_PCF //- nVidia GF3+, R600+
// #define USE_BRANCHING //- HW-options defined
// #define USE_VTF //- HW-options defined, VertexTextureFetch
// #define FP16_FILTER //- HW-options defined
// #define FP16_BLEND //- HW-options defined
//
// #define USE_PARALLAX //- shader defined
// #define USE_TDETAIL //- shader defined
// #define USE_LM_HEMI //- shader defined
// #define USE_DISTORT //- shader defined
// #define DBG_TMAPPING
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef SMAP_size
#define SMAP_size 1024
#endif
#ifdef USE_R2_STATIC_SUN
#define xmaterial float(1.0f / 4.0f)
#else
#define xmaterial float(L_material.w)
#endif
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 def_aref;
uniform float4 parallax;
uniform float4 hemi_cube_pos_faces;
uniform float4 hemi_cube_neg_faces;
uniform float4 L_material;
uniform float4 Ldynamic_color;
uniform float4 Ldynamic_pos;
uniform float4 Ldynamic_dir;
uniform float4 J_direct[6];
uniform float4 J_spot[6];
float calc_fogging(float3 w_pos)
{
return 1.0f - saturate(length(w_pos.xyz - eye_position.xyz) * fog_params.w + fog_params.x);
}
float2 calc_detail(float3 w_pos)
{
float dtl = distance(w_pos, eye_position) * dt_params.w;
dtl = min(dtl * dtl, 1.0f);
float dt_mul = 1.0f - dtl; // dt* [1 .. 0 ]
float dt_add = 0.5f * dtl; // dt+ [0 .. 0.5]
return float2(dt_mul, dt_add);
}
float3 calc_reflection(float3 pos_w, float3 norm_w)
{
return reflect(normalize(pos_w - eye_position), norm_w);
}
float3 calc_sun_r1(float3 norm_w)
{
return L_sun_color * saturate(dot((norm_w), -L_sun_dir_w));
}
float3 calc_model_hemi_r1(float3 norm_w)
{
return max(0, norm_w.y) * L_hemi_color;
}
float3 calc_model_lq_lighting(float3 norm_w)
{
return L_material.x * calc_model_hemi_r1(norm_w) + L_ambient + L_material.y * calc_sun_r1(norm_w);
}
//////////////////////////////////////////////////////////////////////////////////////////
struct v_static
{
float4 P : POSITION; // (float,float,float,1)
float4 Nh : NORMAL; // (nx,ny,nz,hemi occlusion)
float4 T : TANGENT; // tangent
float4 B : BINORMAL; // binormal
float2 tc : TEXCOORD0; // (u,v)
float2 lmh : TEXCOORD1; // (lmu,lmv)
float4 color : COLOR0; // (r,g,b,dir-occlusion)
};
struct v_tree
{
float4 P : POSITION; // (float,float,float,1)
float4 Nh : NORMAL; // (nx,ny,nz)
float3 T : TANGENT; // tangent
float3 B : BINORMAL; // binormal
float4 tc : TEXCOORD0; // (u,v,frac,???)
};
struct v_model
{
float4 P : POSITION; // (float,float,float,1)
float3 N : NORMAL; // (nx,ny,nz)
float3 T : TANGENT; // (nx,ny,nz)
float3 B : BINORMAL; // (nx,ny,nz)
float2 tc : TEXCOORD0; // (u,v)
};
struct v_detail
{
float4 pos : POSITION; // (float,float,float,1)
int4 misc : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id)
};
struct v_shadow_direct_aref
{
float4 P : POSITION; // Clip-space position (for rasterization)
float4 tc : TEXCOORD1; // Diffuse map for aref
};
struct p_bumped_new
{
float4 hpos : POSITION;
float4 tcdh : TEXCOORD0; // Texture coordinates, sun_occlusion || lm-hemi
float4 position : TEXCOORD1; // position + hemi
float3 M1 : TEXCOORD2; // nmap 2 eye - 1
float3 M2 : TEXCOORD3; // nmap 2 eye - 2
float3 M3 : TEXCOORD4; // nmap 2 eye - 3
};
//////////////////////////////////////////////////////////////////////////////////////////
struct p_bumped
{
float4 hpos : POSITION;
#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI)
float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion
#else
float2 tcdh : TEXCOORD0; // Texture coordinates
#endif
float4 position : TEXCOORD1; // position + hemi
float3 M1 : TEXCOORD2; // nmap 2 eye - 1
float3 M2 : TEXCOORD3; // nmap 2 eye - 2
float3 M3 : TEXCOORD4; // nmap 2 eye - 3
#ifdef USE_TDETAIL
float2 tcdbump : TEXCOORD5; // d-bump
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD6; // lm-hemi
#endif
#else
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD5; // lm-hemi
#endif
#endif
};
//////////////////////////////////////////////////////////////////////////////////////////
struct p_flat
{
float4 hpos : POSITION;
#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI)
float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion
#else
float2 tcdh : TEXCOORD0; // Texture coordinates
#endif
float4 position : TEXCOORD1; // position + hemi
float3 N : TEXCOORD2; // Eye-space normal (for lighting)
#ifdef USE_TDETAIL
float2 tcdbump : TEXCOORD3; // d-bump
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD4; // lm-hemi
#endif
#else
#ifdef USE_LM_HEMI
float2 lmh : TEXCOORD3; // lm-hemi
#endif
#endif
};
//////////////////////////////////////////////////////////////////////////////////////////
// struct f_deffer {
// float4 position : COLOR0; // px,py,pz, m-id
// float4 Ne : COLOR1; // nx,ny,nz, hemi
// float4 C : COLOR2; // r, g, b, gloss
// };
struct f_deffer
{
float4 P : COLOR0;
float4 N : COLOR1;
float4 C : COLOR2;
};
struct f_forward
{
float4 Color : COLOR0;
};
struct p_shadow
{
float2 tc0 : TEXCOORD0;
float4 hpos : POSITION;
};
//////////////////////////////////////////////////////////////////////////////////////////
struct p_screen
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0;
};
//////////////////////////////////////////////////////////////////////////////////////////
// Geometry phase / deferring //
uniform sampler2D s_base; //
uniform sampler2D s_bump; //
uniform sampler2D s_bumpX; //
uniform sampler2D s_detail; //
uniform sampler2D s_detailBump; //
uniform sampler2D s_detailBumpX; // Error for bump detail
uniform sampler2D s_bumpD; //
uniform sampler2D s_hemi; //
uniform sampler2D s_mask; //
uniform sampler2D s_dt_r; //
uniform sampler2D s_dt_g; //
uniform sampler2D s_dt_b; //
uniform sampler2D s_dt_a; //
uniform sampler2D s_dn_r; //
uniform sampler2D s_dn_g; //
uniform sampler2D s_dn_b; //
uniform sampler2D s_dn_a; //
//////////////////////////////////////////////////////////////////////////////////////////
// Lighting/shadowing phase //
uniform sampler2D s_depth; //
uniform sampler2D s_position; //
uniform sampler2D s_normal; //
uniform sampler s_lmap; // 2D/cube projector lightmap
uniform sampler3D s_material; //
uniform sampler1D s_attenuate; //
//////////////////////////////////////////////////////////////////////////////////////////
// Combine phase //
uniform sampler2D s_diffuse; // rgb.a = diffuse.gloss
uniform sampler2D s_accumulator; // rgb.a = diffuse.specular
uniform sampler2D s_generic; //
uniform sampler2D s_bloom; //
uniform sampler s_image; // used in various post-processing
uniform sampler2D s_tonemap; // actually MidleGray / exp(Lw + eps)
#define def_gloss float(4.0f / 255.0f)
#define def_dbumph float(0.333f)
#define def_virtualh float(0.05f)
#define def_distort float(0.05f)
#define def_hdr float(9.0f)
#define def_hdr_clip float(0.75f)
#define LUMINANCE_VECTOR float3(0.3f, 0.38f, 0.22f)
float3 tonemap(float3 rgb, float scale)
{
rgb = rgb * scale;
const float fWhiteIntensity = 1.7f;
const float fWhiteIntensitySQR = fWhiteIntensity * fWhiteIntensity;
return rgb * (1.0f + rgb / fWhiteIntensitySQR) / (rgb + 1.0f);
}
float4 combine_bloom(float3 low, float4 high)
{
return float4(low + high * high.a, 1.0f);
}
float3 v_hemi(float3 n)
{
return L_hemi_color * (.5f + .5f * n.y);
}
float3 v_hemi_wrap(float3 n, float w)
{
return L_hemi_color * (w + (1 - w) * n.y);
}
float3 v_sun(float3 n)
{
return L_sun_color * dot(n, -L_sun_dir_w);
}
float3 v_sun_wrap(float3 n, float w)
{
return L_sun_color * (w + (1 - w) * dot(n, -L_sun_dir_w));
}
float3 p_hemi(float2 tc)
{
// float3 t_lmh = tex2D (s_hemi, tc);
// return dot (t_lmh,1.h/4.h);
float4 t_lmh = tex2D(s_hemi, tc);
return t_lmh.a;
}
float get_hemi(float4 lmh)
{
return lmh.a;
}
float get_sun(float4 lmh)
{
return lmh.g;
}
// contrast function
float Contrast(float Input, float ContrastPower)
{
// piecewise contrast function
bool IsAbovefloat = Input > 0.5f;
float ToRaise = saturate(2.0f * (IsAbovefloat ? 1.0f - Input : Input));
float Output = 0.5f * pow(ToRaise, ContrastPower);
Output = IsAbovefloat ? 1.0f - Output : Output;
return Output;
}
f_deffer pack_gbuffer(float4 Normal, float4 Point, float4 Color)
{
f_deffer Output;
Output.N = Normal;
Output.P = Point;
Output.C = Color;
return Output;
}
#define FXPS \
technique _render \
{ \
pass _code \
{ \
PixelShader = compile ps_3_0 main(); \
} \
}
#define FXVS \
technique _render \
{ \
pass _code \
{ \
VertexShader = compile vs_3_0 main(); \
} \
}
#endif

View file

@ -0,0 +1,8 @@
#include "common.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( float2 tc : TEXCOORD0 ) : COLOR
{
return tex2D (s_base,tc);
}

View file

@ -0,0 +1,7 @@
#include "common.hlsli"
// Pixel
float4 main(float2 tc : TEXCOORD0) : COLOR
{
return tex2D(s_base, tc);
}

View file

@ -0,0 +1,8 @@
#include "common.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
half4 main ( float4 tc : TEXCOORD0 ) : COLOR
{
return tex2Dproj (s_base,tc);
}

View file

@ -0,0 +1,7 @@
#include "common.hlsli"
// Pixel
float4 main(float4 tc : TEXCOORD0) : COLOR
{
return tex2Dproj(s_base, tc);
}

View file

@ -0,0 +1,33 @@
#include "common.hlsli"
#include "sload.hlsli"
void main(p_bumped_new I, out f_deffer O)
{
XrayMaterial M;
M.Sun = I.tcdh.w;
M.Hemi = I.tcdh.z;
M.Point = I.position.xyz;
SloadNew(I, M);
#ifdef USE_AREF
clip(M.Color.w - def_aref);
#endif
M.Normal = mul(float3x3(I.M1, I.M2, I.M3), M.Normal);
M.Normal = normalize(M.Normal);
#ifdef USE_LM_HEMI
float4 lm = tex2D(s_hemi, I.tcdh.zw);
M.Sun = get_sun(lm);
M.Hemi = get_hemi(lm);
#endif
#ifndef USE_R2_STATIC_SUN
M.Sun = xmaterial;
#endif
O = pack_gbuffer(float4(M.Normal, M.Hemi), float4(M.Point, M.Sun), float4(M.Color.xyz, 1.0f - M.Roughness));
}

View file

@ -0,0 +1,31 @@
#include "common.hlsli"
void main(in v_static I, out p_bumped_new O)
{
float2 tc = unpack_tc_base(I.tc, I.T.w, I.B.w);
float3 Pe = mul(m_WV, I.P);
O.tcdh = float4(tc.xy, I.Nh.w, I.Nh.w);
O.position = float4(Pe, 1.0f);
float3 N = unpack_bx4(I.Nh);
float3 T = unpack_bx4(I.T);
float3 B = unpack_bx4(I.B);
float3x3 xform = mul((float3x3)m_WV, float3x3(
T.x, B.x, N.x,
T.y, B.y, N.y,
T.z, B.z, N.z));
O.M1 = xform[0];
O.M2 = xform[1];
O.M3 = xform[2];
#ifdef USE_LM_HEMI
O.tcdh.zw = unpack_tc_lmap(I.lmh);
#else
O.tcdh.w = I.color.w;
#endif
O.hpos = mul(m_WVP, I.P);
}

View file

@ -0,0 +1,2 @@
#define USE_PARALLAX
#include "deffer_base_aref_bump.ps"

View file

@ -0,0 +1,37 @@
#include "common.h"
#include "sload.h"
f_deffer main ( p_bumped I )
{
f_deffer O;
surface_bumped S = sload (I);
clip (S.base.w-def_aref);
// Sample normal, rotate it by matrix, encode position
half3 Ne = mul (half3x3(I.M1, I.M2, I.M3), S.normal);
Ne = normalize (Ne);
// hemi,sun,material
half ms = xmaterial ;
#ifdef USE_LM_HEMI
half4 lm = tex2D (s_hemi, I.lmh);
// half h = dot (lm.rgb,1.h/3.h);
half h = get_hemi(lm);
# ifdef USE_R2_STATIC_SUN
//ms = lm.w;
ms = get_sun(lm);
# endif
#else
half h = I.position.w ;
# ifdef USE_R2_STATIC_SUN
ms = I.tcdh.w ;
# endif
#endif
O.Ne = half4 (Ne, h);
O.position = half4 (I.position.xyz + Ne*S.height*def_virtualh, ms);
O.C = half4 (S.base.x,S.base.y,S.base.z, S.gloss); // OUT: rgb.gloss
return O ;
}

View file

@ -0,0 +1,2 @@
#define USE_PARALLAX
#include "deffer_base_aref_bump_d.ps"

View file

@ -0,0 +1,2 @@
#define USE_TDETAIL //- shader defined
#include "deffer_base_aref_bump.ps"

View file

@ -0,0 +1,2 @@
#define USE_TDETAIL_BUMP
#include "deffer_base_aref_bump_d-hq.ps"

Some files were not shown because too many files have changed in this diff Show more