add game&rawdata
This commit is contained in:
parent
0133cd976c
commit
49b34b5546
45731 changed files with 709831 additions and 0 deletions
93
gamedata/shaders/r3/dx11/tess.ds
Normal file
93
gamedata/shaders/r3/dx11/tess.ds
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include "common.h"
|
||||
#include "DX11\tess.h"
|
||||
|
||||
//if you use ccw then corresponding coefs are w, v, u
|
||||
//if you use cw then corresponding coefs are u, v, w
|
||||
[domain("tri")]
|
||||
v2p_bumped main( HS_CONSTANT_DATA_OUTPUT input,
|
||||
float3 uvw : SV_DomainLocation,
|
||||
const OutputPatch<p_bumped, 3> bp )
|
||||
{
|
||||
v2p_bumped output;
|
||||
|
||||
//interpolate in screen space
|
||||
//uvw = uvw*input.www/dot(uvw,input.www);
|
||||
|
||||
float minc = min( uvw.x, min( uvw.y, uvw.z ) );
|
||||
// if the vertex is not on an edge of the original triangle
|
||||
[flatten]if (minc!=0.0f)
|
||||
{
|
||||
// if we are at not the centre of the triangle
|
||||
[flatten]if( ((1.0f/3.0f)-minc)> 0.01f )
|
||||
{
|
||||
// solving for making the smallest uvw component 0.0f as this means the bigger ones sum to 1.0f and
|
||||
// are on the edge of the triangle
|
||||
// if vertex gets too close to the edge move it on to the edge to replace to old edge vertex
|
||||
// otherwise keep fK at 1.0f to restore the old uvw position
|
||||
|
||||
float fK = (1.0f/3.0f)/((1.0f/3.0f)-minc);
|
||||
fK = minc < 0.1 ? fK : 1.0f;
|
||||
// update uvw
|
||||
uvw = lerp((1.0f/3.0f).xxx, uvw, fK);
|
||||
}
|
||||
}
|
||||
|
||||
float u = uvw.x;
|
||||
float v = uvw.y;
|
||||
float w = uvw.z;
|
||||
|
||||
output.tcdh = bp[0].tcdh*w + bp[1].tcdh*v + bp[2].tcdh*u;
|
||||
output.position = bp[0].position*w + bp[1].position*v + bp[2].position*u;
|
||||
|
||||
float3 M1 = bp[0].M1*w + bp[1].M1*v + bp[2].M1*u; output.M1 = M1;
|
||||
float3 M2 = bp[0].M2*w + bp[1].M2*v + bp[2].M2*u; output.M2 = M2;
|
||||
float3 M3 = bp[0].M3*w + bp[1].M3*v + bp[2].M3*u; output.M3 = M3;
|
||||
float3 Normal = normalize(float3(M1.z, M2.z, M3.z));
|
||||
|
||||
float3 triPos = output.position.xyz;
|
||||
|
||||
#ifdef USE_TDETAIL
|
||||
output.tcdbump = bp[0].tcdbump*w + bp[1].tcdbump*v + bp[2].tcdbump*u;
|
||||
#endif
|
||||
#ifdef USE_LM_HEMI
|
||||
output.lmh = bp[0].lmh*w + bp[1].lmh*v + bp[2].lmh*u;
|
||||
#endif
|
||||
|
||||
#if TESS_PN
|
||||
float3 N[3] =
|
||||
{
|
||||
float3(bp[0].M1.z, bp[0].M2.z, bp[0].M3.z),
|
||||
float3(bp[1].M1.z, bp[1].M2.z, bp[1].M3.z),
|
||||
float3(bp[2].M1.z, bp[2].M2.z, bp[2].M3.z)
|
||||
};
|
||||
|
||||
float3 P[3] =
|
||||
{
|
||||
bp[0].position.xyz,
|
||||
bp[1].position.xyz,
|
||||
bp[2].position.xyz
|
||||
};
|
||||
|
||||
ComputePatchVertex(P, N, uvw, input.patch, output.position.xyz, Normal);
|
||||
#endif
|
||||
|
||||
#if TESS_HM
|
||||
# ifdef USE_TDETAIL
|
||||
ComputeDisplacedVertex(output.position.xyz, Normal, output.tcdh, output.tcdbump);
|
||||
# else
|
||||
ComputeDisplacedVertex(output.position.xyz, Normal, output.tcdh, 0);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
[flatten]if( minc==0 )
|
||||
output.position.xyz = triPos;
|
||||
|
||||
|
||||
//output.M1.z = Normal.x;
|
||||
//output.M2.z = Normal.y;
|
||||
//output.M3.z = Normal.z;
|
||||
output.hpos = mul(m_P, float4(output.position.xyz,1));
|
||||
|
||||
return output;
|
||||
}
|
||||
117
gamedata/shaders/r3/dx11/tess.h
Normal file
117
gamedata/shaders/r3/dx11/tess.h
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#ifndef TESS_H_INCLUDED
|
||||
# define TESS_H_INCLUDED
|
||||
|
||||
// Output patch constant data.
|
||||
struct PNPatch
|
||||
{
|
||||
// Geometry cubic control points (excluding corners)
|
||||
float3 f3B210 : POSITION3;
|
||||
float3 f3B120 : POSITION4;
|
||||
float3 f3B021 : POSITION5;
|
||||
float3 f3B012 : POSITION6;
|
||||
float3 f3B102 : POSITION7;
|
||||
float3 f3B201 : POSITION8;
|
||||
float3 f3B111 : CENTER;
|
||||
|
||||
// Normal quadratic control points (excluding corners)
|
||||
float3 f3N110 : NORMAL3;
|
||||
float3 f3N011 : NORMAL4;
|
||||
float3 f3N101 : NORMAL5;
|
||||
};
|
||||
|
||||
struct HS_CONSTANT_DATA_OUTPUT
|
||||
{
|
||||
float Edges[3] : SV_TessFactor;
|
||||
float Inside : SV_InsideTessFactor;
|
||||
//float3 www : DUBBIES;
|
||||
#ifdef TESS_PN
|
||||
PNPatch patch;
|
||||
#endif
|
||||
};
|
||||
|
||||
float triLOD;
|
||||
|
||||
void ComputeTessFactor(out float Edges[3] : SV_TessFactor, out float Inside : SV_InsideTessFactor)
|
||||
{
|
||||
//float factor = clamp(triLOD, 1, 1);//factor = (Output.N.z>0)?-1:10;//max(factor*10, 1);
|
||||
|
||||
Edges[0] = Edges[1] = Edges[2] = /*63;//*/triLOD;//factor;
|
||||
Inside = /*63;//*/triLOD;//factor;
|
||||
}
|
||||
|
||||
void ComputePNPatch(float3 P[3], float3 N[3], out PNPatch patch)
|
||||
{
|
||||
// Compute the cubic geometry control points
|
||||
// Edge control points
|
||||
patch.f3B210 = (2.0f*P[0].xyz + P[1].xyz - dot(P[1].xyz-P[0].xyz, N[0])*N[0]) / 3.0f;
|
||||
patch.f3B120 = (2.0f*P[1].xyz + P[0].xyz - dot(P[0].xyz-P[1].xyz, N[1])*N[1]) / 3.0f;
|
||||
patch.f3B021 = (2.0f*P[1].xyz + P[2].xyz - dot(P[2].xyz-P[1].xyz, N[1])*N[1]) / 3.0f;
|
||||
patch.f3B012 = (2.0f*P[2].xyz + P[1].xyz - dot(P[1].xyz-P[2].xyz, N[2])*N[2]) / 3.0f;
|
||||
patch.f3B102 = (2.0f*P[2].xyz + P[0].xyz - dot(P[0].xyz-P[2].xyz, N[2])*N[2]) / 3.0f;
|
||||
patch.f3B201 = (2.0f*P[0].xyz + P[2].xyz - dot(P[2].xyz-P[0].xyz, N[0])*N[0]) / 3.0f;
|
||||
|
||||
// Center control point
|
||||
float3 f3E = ( patch.f3B210 + patch.f3B120 + patch.f3B021 + patch.f3B012 + patch.f3B102 + patch.f3B201 ) / 6.0f;
|
||||
float3 f3V = ( P[0].xyz + P[1].xyz + P[2].xyz ) / 3.0f;
|
||||
patch.f3B111 = f3E + ( ( f3E - f3V ) / 2.0f );
|
||||
|
||||
// Compute the quadratic normal control points, and rotate into world space
|
||||
float fV12 = 2.0f * dot( P[1].xyz - P[0].xyz, N[0] + N[1] ) / dot( P[1].xyz - P[0].xyz, P[1].xyz - P[0].xyz );
|
||||
patch.f3N110 = normalize( N[0] + N[1] - fV12 * ( P[1].xyz - P[0].xyz ));
|
||||
float fV23 = 2.0f * dot( P[2].xyz - P[1].xyz, N[1] + N[2] ) / dot( P[2].xyz - P[1].xyz, P[2].xyz - P[1].xyz );
|
||||
patch.f3N011 = normalize( N[1] + N[2] - fV23 * ( P[2].xyz - P[1].xyz ));
|
||||
float fV31 = 2.0f * dot( P[0].xyz - P[2].xyz, N[2] + N[0] ) / dot( P[0].xyz - P[2].xyz, P[0].xyz - P[2].xyz );
|
||||
patch.f3N101 = normalize( N[2] + N[0] - fV31 * ( P[0].xyz - P[2].xyz ));
|
||||
}
|
||||
|
||||
void ComputePatchVertex(float3 P[3], float3 N[3], float3 uvw, in PNPatch patch, out float3 Pos, out float3 Norm)
|
||||
{
|
||||
float u = uvw.y;
|
||||
float v = uvw.x;
|
||||
float w = uvw.z;
|
||||
|
||||
Pos = P[0] * w * w * w +
|
||||
P[1] * u * u * u +
|
||||
P[2] * v * v * v +
|
||||
patch.f3B210 * 3.0f * w * w * u +
|
||||
patch.f3B120 * 3.0f * w * u * u +
|
||||
patch.f3B201 * 3.0f * w * w * v +
|
||||
patch.f3B021 * 3.0f * u * u * v +
|
||||
patch.f3B102 * 3.0f * w * v * v +
|
||||
patch.f3B012 * 3.0f * u * v * v +
|
||||
patch.f3B111 * 6.0f * w * u * v;
|
||||
|
||||
|
||||
// Compute normal from quadratic control points and barycentric coords
|
||||
Norm = N[0] * w * w +
|
||||
N[1] * u * u +
|
||||
N[2] * v * v +
|
||||
patch.f3N110 * w * u +
|
||||
patch.f3N011 * u * v +
|
||||
patch.f3N101 * w * v;
|
||||
}
|
||||
|
||||
sampler smp_bump_ds; // Use D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC
|
||||
Texture2D s_tbump; //
|
||||
Texture2D s_tbumpX; //
|
||||
Texture2D s_tdetailBumpX; // Error for bump detail
|
||||
|
||||
void ComputeDisplacedVertex(inout float3 P, float3 N, float2 tc, float2 tcd)
|
||||
{
|
||||
#ifdef USE_TDETAIL
|
||||
float4 Nu = s_tbump.SampleLevel (smp_bump_ds, tc, 0); // IN: normal.gloss
|
||||
float4 NuE = s_tbumpX.SampleLevel(smp_bump_ds, tc, 0); // IN: normal_error.height
|
||||
|
||||
float3 Ne = Nu.wzy + (NuE.xyz - 1.0h); //(Nu.wzyx - .5h) + (E-.5)
|
||||
float height = NuE.w;
|
||||
|
||||
# ifdef USE_TDETAIL_BUMP
|
||||
float4 NDetailX = s_tdetailBumpX.SampleLevel(smp_bump_ds, tcd, 0);
|
||||
height += (NDetailX.w-0.5)*0.2;
|
||||
# endif
|
||||
|
||||
P += N*height*0.07;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
77
gamedata/shaders/r3/dx11/tess.hs
Normal file
77
gamedata/shaders/r3/dx11/tess.hs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include "common.h"
|
||||
#include "DX11\tess.h"
|
||||
|
||||
HS_CONSTANT_DATA_OUTPUT PatchConstantsHS(
|
||||
InputPatch<p_bumped, 3> ip,
|
||||
uint PatchID : SV_PrimitiveID )
|
||||
{
|
||||
HS_CONSTANT_DATA_OUTPUT Output;
|
||||
|
||||
ComputeTessFactor(Output.Edges, Output.Inside);
|
||||
|
||||
#ifdef TESS_PN
|
||||
float3 N[3] =
|
||||
{
|
||||
normalize(float3(ip[0].M1.z, ip[0].M2.z, ip[0].M3.z)),
|
||||
normalize(float3(ip[1].M1.z, ip[1].M2.z, ip[1].M3.z)),
|
||||
normalize(float3(ip[2].M1.z, ip[2].M2.z, ip[2].M3.z))
|
||||
};
|
||||
|
||||
float3 P[3] =
|
||||
{
|
||||
ip[0].position.xyz,
|
||||
ip[1].position.xyz,
|
||||
ip[2].position.xyz
|
||||
};
|
||||
|
||||
ComputePNPatch(P, N, Output.patch);
|
||||
|
||||
//Discard back facing patches
|
||||
# ifndef TESS_HM
|
||||
bool doDiscard = (N[0].z>0.1) && (N[1].z>0.1) && (N[2].z>0.1)
|
||||
&& (Output.patch.f3N110.z>0.1) && (Output.patch.f3N011.z>0.1) && (Output.patch.f3N101.z>0.1)
|
||||
&& (P[0].z>5) && (P[1].z>5) && (P[2].z>5);
|
||||
|
||||
if (doDiscard)
|
||||
Output.Edges[0]= Output.Edges[1]=Output.Edges[2]=Output.Inside=-1;
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
// Data for interpolation in screen space
|
||||
// float w0 = mul(m_P, float4(ip[2].position.xyz, 1)).w;
|
||||
// float w1 = mul(m_P, float4(ip[1].position.xyz, 1)).w;
|
||||
// float w2 = mul(m_P, float4(ip[0].position.xyz, 1)).w;
|
||||
|
||||
// Output.www = float3(w0, w1, w2);
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
||||
[domain("tri")]
|
||||
[partitioning("pow2")]
|
||||
[outputtopology("triangle_ccw")]
|
||||
[outputcontrolpoints(3)]
|
||||
[patchconstantfunc("PatchConstantsHS")]
|
||||
p_bumped main( InputPatch<p_bumped, 3> ip,
|
||||
uint i : SV_OutputControlPointID,
|
||||
uint PatchID : SV_PrimitiveID )
|
||||
{
|
||||
p_bumped ouput;
|
||||
|
||||
ouput.tcdh = ip[i].tcdh;
|
||||
ouput.position = ip[i].position;
|
||||
ouput.M1 = ip[i].M1;
|
||||
ouput.M2 = ip[i].M2;
|
||||
ouput.M3 = ip[i].M3;
|
||||
#ifdef USE_TDETAIL
|
||||
ouput.tcdbump = ip[i].tcdbump;
|
||||
#endif
|
||||
#ifdef USE_LM_HEMI
|
||||
ouput.lmh = ip[i].lmh;
|
||||
#endif
|
||||
|
||||
return ouput;
|
||||
}
|
||||
|
||||
|
||||
55
gamedata/shaders/r3/dx11/tess_shadow.ds
Normal file
55
gamedata/shaders/r3/dx11/tess_shadow.ds
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "common.h"
|
||||
#include "DX11\tess.h"
|
||||
|
||||
//if you use ccw then corresponding coefs are w, v, u
|
||||
//if you use cw then corresponding coefs are u, v, w
|
||||
[domain("tri")]
|
||||
v2p_shadow_direct main( HS_CONSTANT_DATA_OUTPUT input,
|
||||
float3 uvw : SV_DomainLocation,
|
||||
const OutputPatch<p_bumped, 3> bp )
|
||||
{
|
||||
v2p_shadow_direct output;
|
||||
float u = uvw.x;
|
||||
float v = uvw.y;
|
||||
float w = uvw.z;
|
||||
|
||||
float3 Pos = bp[0].position.xyz*w + bp[1].position.xyz*v + bp[2].position.xyz*u;
|
||||
float3 M1 = bp[0].M1*w + bp[1].M1*v + bp[2].M1*u;
|
||||
float3 M2 = bp[0].M2*w + bp[1].M2*v + bp[2].M2*u;
|
||||
float3 M3 = bp[0].M3*w + bp[1].M3*v + bp[2].M3*u;
|
||||
float3 Norm = normalize(float3(M1.z, M2.z, M3.z));
|
||||
float2 tc = bp[0].tcdh*w + bp[1].tcdh*v + bp[2].tcdh*u;
|
||||
# ifdef USE_TDETAIL
|
||||
float2 tcd = bp[0].tcdbump*w + bp[1].tcdbump*v + bp[2].tcdbump*u;
|
||||
# else
|
||||
float2 tcd = 0;
|
||||
# endif
|
||||
|
||||
|
||||
#if TESS_PN
|
||||
float3 N[3] =
|
||||
{
|
||||
float3(bp[0].M1.z, bp[0].M2.z, bp[0].M3.z),
|
||||
float3(bp[1].M1.z, bp[1].M2.z, bp[1].M3.z),
|
||||
float3(bp[2].M1.z, bp[2].M2.z, bp[2].M3.z)
|
||||
};
|
||||
|
||||
float3 P[3] =
|
||||
{
|
||||
bp[0].position.xyz,
|
||||
bp[1].position.xyz,
|
||||
bp[2].position.xyz
|
||||
};
|
||||
|
||||
ComputePatchVertex(P, N, uvw, input.patch, Pos, Norm);
|
||||
#endif
|
||||
|
||||
#if TESS_HM
|
||||
ComputeDisplacedVertex(Pos, Norm, tc, tcd);
|
||||
#endif
|
||||
|
||||
output.hpos = mul(m_P, float4(Pos,1));
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue