shader update

This commit is contained in:
turanszkij
2016-02-04 23:16:33 +01:00
parent a22c62a2ad
commit 92c09d7544
13 changed files with 146 additions and 144 deletions
+14
View File
@@ -1126,6 +1126,20 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="dirLightSoftPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="dirLightVS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">4.1</ShaderModel>
@@ -2148,6 +2148,9 @@
<FxCompile Include="screenPS.hlsl">
<Filter>shaders\image</Filter>
</FxCompile>
<FxCompile Include="dirLightSoftPS.hlsl">
<Filter>shaders\lighting</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Image Include="fonts\basic.dds">
+22 -5
View File
@@ -1,3 +1,6 @@
#ifndef _DIRLIGHT_HF_
#define _DIRLIGHT_HF_
#include "toonHF.hlsli"
// dir light constant buffer is global
@@ -22,10 +25,11 @@ inline float shadowCascade(float4 shadowPos, float2 ShTex, Texture2D<float> shad
float scale = g_xDirLight_mBiasResSoftshadow.y;
float retVal = 1;
[branch]if(g_xDirLight_mBiasResSoftshadow.z){
#ifdef DIRECTIONALLIGHT_SOFT
//[branch]if(g_xDirLight_mBiasResSoftshadow.z)
{
float samples = 0.0f;
float range = 0.5f;
if(g_xDirLight_mBiasResSoftshadow.z==2.0f) range = 1.5f;
static const float range = 1.5f;
for (float y = -range; y <= range; y += 1.0f)
for (float x = -range; x <= range; x += 1.0f)
{
@@ -35,7 +39,10 @@ inline float shadowCascade(float4 shadowPos, float2 ShTex, Texture2D<float> shad
retVal *= sum / samples;
}
else retVal *= offset_lookup(shadowTexture, sampler_cmp_depth, ShTex, float2(0, 0), scale, realDistance);
//else
#else
retVal *= offset_lookup(shadowTexture, sampler_cmp_depth, ShTex, float2(0, 0), scale, realDistance);
#endif
return retVal;
}
@@ -75,4 +82,14 @@ inline float dirLight(in float3 pos3D, in float3 normal, inout float4 color, in
difLight *= shadows[0];
}
return difLight;
}
}
// MACROS
#define DEFERRED_DIRLIGHT_MAIN \
float lighting = dirLight(pos3D,normal,color,toonshaded); \
color.rgb *= lighting; \
applySpecular(color, color*lighting, normal, eyevector, g_xDirLight_direction.xyz, 1, specular_power, specular, toonshaded);
#endif // _DIRLIGHT_HF_
+3 -37
View File
@@ -5,43 +5,9 @@
float4 main( VertexToPixel PSIn ) : SV_TARGET
{
float4 color = float4(g_xDirLight_col.rgb,1);
float2 screenPos = float2(1,-1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f;
float depth = depthMap.SampleLevel(sampler_point_clamp,screenPos,0);
//clip(depth<1?1:-1);
DEFERREDLIGHT_MAKEPARAMS(g_xDirLight_col)
//[branch]if(depth<g_xCamera_ZFarP)
{
DEFERRED_DIRLIGHT_MAIN
float4 norU = normalMap.SampleLevel(sampler_point_clamp,screenPos,0);
bool unshaded = isUnshaded(norU.w);
[branch]if(!unshaded){
float4 material = materialMap.SampleLevel(sampler_point_clamp,screenPos,0);
float specular = material.w*specularMaximumIntensity;
uint specular_power = material.z;
float3 normal = norU.xyz;
bool toonshaded = isToon(norU.w);
float3 pos3D = getPosition(screenPos,depth);
float3 eyevector = normalize(g_xCamera_CamPos -pos3D.xyz);
float lighting = dirLight(pos3D,normal,color,toonshaded);
//float rimLight = saturate(1.0f-specular) * saturate(pow(saturate(1.0f-dot(normal,eyevector)),3));
//lighting+=rimLight;
color.rgb *= (lighting);
//SPECULAR
applySpecular(color, color*lighting, normal, eyevector, g_xDirLight_direction.xyz, 1, specular_power, specular, toonshaded);
//else
// color.a=0;
}
else
color=float4(1,1,1,1);
}
return max(color, 0);
DEFERREDLIGHT_RETURN
}
+15
View File
@@ -0,0 +1,15 @@
#include "lightHF.hlsli"
#define DIRECTIONALLIGHT_SOFT
#include "dirLightHF.hlsli"
float4 main(VertexToPixel PSIn) : SV_TARGET
{
DEFERREDLIGHT_MAKEPARAMS(g_xDirLight_col)
DEFERRED_DIRLIGHT_MAIN
DEFERREDLIGHT_RETURN
}
+24
View File
@@ -19,6 +19,30 @@ Texture2D<float4> materialMap:register(t2);
static const float specularMaximumIntensity = 1;
// MACROS
// C : (float4) light color
#define DEFERREDLIGHT_MAKEPARAMS(C) \
float4 color = float4(C.rgb,1); \
float2 screenPos = float2(1, -1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f; \
float depth = depthMap.SampleLevel(sampler_point_clamp, screenPos, 0); \
float4 norU = normalMap.SampleLevel(sampler_point_clamp,screenPos,0); \
bool unshaded = isUnshaded(norU.w); \
float4 material = materialMap.SampleLevel(sampler_point_clamp,screenPos,0); \
float specular = material.w*specularMaximumIntensity; \
uint specular_power = material.z; \
float3 normal = norU.xyz; \
bool toonshaded = isToon(norU.w); \
float3 pos3D = getPosition(screenPos, depth); \
float3 eyevector = normalize(g_xCamera_CamPos - pos3D.xyz);
#define DEFERREDLIGHT_RETURN \
return max(unshaded? 1 : color, 0.0f);
#endif // _LIGHTHF_
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef _POINTLIGHTHF_
#define _POINTLIGHTHF_
#ifndef _POINTLIGHT_HF_
#define _POINTLIGHT_HF_
#include "globals.hlsli"
TextureCube xTextureSh:register(t7);
@@ -30,4 +30,4 @@ inline float pointLight(in float3 pos3D, in float3 normal, out float3 lightDir,
return saturate(attenuation*lightint);
}
#endif // _POINTLIGHTHF_
#endif // _POINTLIGHT_HF_
+9 -44
View File
@@ -3,50 +3,15 @@
float4 main(VertexToPixel PSIn) : SV_TARGET
{
float4 light = float4(lightColor.rgb,1);
float2 screenPos = float2(1,-1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f;
float depth = depthMap.SampleLevel(sampler_point_clamp,screenPos,0);
{
DEFERREDLIGHT_MAKEPARAMS(lightColor)
[branch]if(depth<g_xCamera_ZFarP){
float3 lightDir;
float attenuation;
float lightInt = pointLight(pos3D, normal, lightDir, attenuation, toonshaded);
color *= lightInt;
applySpecular(color, color * lightInt, normal, eyevector, lightDir, 1, specular_power, specular, toonshaded);
color *= attenuation;
float4 norU = normalMap.SampleLevel(sampler_point_clamp,screenPos,0);
bool unshaded = isUnshaded(norU.w);
[branch]if(!unshaded){
float4 material = materialMap.SampleLevel(sampler_point_clamp,screenPos,0);
float specular = material.w*specularMaximumIntensity;
uint specular_power = material.z;
float3 normal = norU.xyz;
bool toonshaded = isToon(norU.w);
float3 pos3D = getPosition(screenPos,depth);
float3 eyevector = normalize(g_xCamera_CamPos.xyz-pos3D.xyz);
float3 lightDir;
float attenuation;
float lightInt = pointLight(pos3D, normal, lightDir, attenuation, toonshaded);
light *= lightInt;
//float rimLight = saturate(1.0f-specular) * saturate(pow(saturate(1.0f-dot(normal,eyevector)),3));
//light.rgb+=rimLight;
//SPECULAR
applySpecular(light, lightColor * lightInt, normal, eyevector, lightDir, 1, specular_power, specular, toonshaded);
//else
// light.a=0;
light*=attenuation;
}
else
light=float4(1,1,1,1);
//float3 lv = pos3D.xyz-lightPos.xyz;
//light=xTextureSh.Sample(sampler_point_clamp,lv);
//light=lightColor;
}
return max(light, 0);
DEFERREDLIGHT_RETURN
}
+6 -1
View File
@@ -1,3 +1,6 @@
#ifndef _SPOTLIGHT_HF_
#define _SPOTLIGHT_HF_
Texture2D<float> xTextureSh:register(t4);
@@ -62,4 +65,6 @@ inline float spotLight(in float3 pos3D, in float3 normal, out float attenuation,
return l;
}
}
#endif // _SPOTLIGHT_HF_
+8 -45
View File
@@ -4,51 +4,14 @@
float4 main(VertexToPixel PSIn) : SV_TARGET
{
float4 light = float4(lightColor.rgb,1);
float2 screenPos = float2(1,-1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f;
float depth = depthMap.SampleLevel(sampler_point_clamp,screenPos,0);
//clip(depth<1?1:-1);
DEFERREDLIGHT_MAKEPARAMS(lightColor)
float attenuation;
float3 lightToPixel;
float lightInt = spotLight(pos3D, normal, attenuation, lightToPixel, toonshaded);
color *= lightInt;
applySpecular(color, color * lightInt, normal, eyevector, lightToPixel, 1, specular_power, specular, toonshaded);
color *= attenuation;
[branch]if(depth<g_xCamera_ZFarP){
float4 norU = normalMap.SampleLevel(sampler_point_clamp,screenPos,0);
bool unshaded = isUnshaded(norU.w);
[branch]if(!unshaded){
float4 material = materialMap.SampleLevel(sampler_point_clamp,screenPos,0);
float specular = material.w*specularMaximumIntensity;
uint specular_power = material.z;
float3 normal = norU.xyz;
bool toonshaded = isToon(norU.w);
float3 pos3D = getPosition(screenPos,depth);
float3 eyevector = normalize(g_xCamera_CamPos.xyz-pos3D.xyz);
float attenuation;
float3 lightToPixel;
float lightInt = spotLight(pos3D, normal, attenuation, lightToPixel, toonshaded);
light.rgb *= lightInt;
//float rimLight = saturate(1.0f-specular) * saturate(pow(saturate(1.0f-dot(normal,eyevector)),3));
//light.rgb+=rimLight;
//SPECULAR
applySpecular(light, lightColor * lightInt, normal, eyevector, lightToPixel, 1, specular_power, specular, toonshaded);
//else
// light.a=0;
light*=attenuation;
}
else
light=float4(1,1,1,1);
}
return max(light, 0);
DEFERREDLIGHT_RETURN
}
+1
View File
@@ -100,6 +100,7 @@ enum PSTYPES
PSTYPE_WATER,
PSTYPE_EFFECT_TRANSPARENT,
PSTYPE_DIRLIGHT,
PSTYPE_DIRLIGHT_SOFT,
PSTYPE_POINTLIGHT,
PSTYPE_SPOTLIGHT,
PSTYPE_VOLUMELIGHT,
+7 -7
View File
@@ -832,13 +832,13 @@ void LoadWiLights(const string& directory, const string& name, const string& ide
lights.back()->shadow = true;
lights.back()->shadowMaps_dirLight.resize(3);
lights.back()->shadowBias = 9.99995464e-005f;
for (int i = 0; i < 3; ++i)
{
lights.back()->shadowMaps_dirLight[i].Initialize(
wiRenderer::SHADOWMAPRES, wiRenderer::SHADOWMAPRES
, 0, true
);
}
//for (int i = 0; i < 3; ++i)
//{
// lights.back()->shadowMaps_dirLight[i].Initialize(
// wiRenderer::SHADOWMAPRES, wiRenderer::SHADOWMAPRES
// , 0, true
// );
//}
}
break;
case 'S':
+31 -2
View File
@@ -825,6 +825,7 @@ void wiRenderer::LoadBasicShaders()
pixelShaders[PSTYPE_BLACKOUT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_blackout.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_TEXTUREONLY] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_textureonly.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_DIRLIGHT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_DIRLIGHT_SOFT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightSoftPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_POINTLIGHT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "pointLightPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SPOTLIGHT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "spotLightPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_VOLUMELIGHT] = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "volumeLightPS.cso", wiResourceManager::PIXELSHADER));
@@ -1891,7 +1892,28 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context
BindVS(vertexShaders[VSTYPE_DIRLIGHT + type],context);
BindPS(pixelShaders[PSTYPE_DIRLIGHT + type],context);
switch (type)
{
case 0:
if (SOFTSHADOW)
{
BindPS(pixelShaders[PSTYPE_DIRLIGHT_SOFT], context);
}
else
{
BindPS(pixelShaders[PSTYPE_DIRLIGHT], context);
}
break;
case 1:
BindPS(pixelShaders[PSTYPE_POINTLIGHT], context);
break;
case 2:
BindPS(pixelShaders[PSTYPE_SPOTLIGHT], context);
break;
default:
break;
}
for(Cullable* c : culledObjects){
@@ -2146,7 +2168,7 @@ void wiRenderer::DrawForShadowMap(DeviceContext context)
if (l->shadow)
{
l->shadowMap_index = -1;
l->lastSquaredDistMulThousand = (long)(wiMath::DistanceEstimated(l->translation, cam->translation) * 1000);
l->lastSquaredDistMulThousand = (long)(wiMath::DistanceSquared(l->translation, cam->translation) * 1000);
switch (l->type)
{
case Light::SPOT:
@@ -2172,6 +2194,13 @@ void wiRenderer::DrawForShadowMap(DeviceContext context)
CulledList culledObjects;
CulledCollection culledRenderer;
auto texDesc = l->shadowMaps_dirLight[index].GetDesc();
if (texDesc.Height != SHADOWMAPRES)
{
// Create the shadow map
l->shadowMaps_dirLight[index].Initialize(SHADOWMAPRES, SHADOWMAPRES, 0, true);
}
l->shadowMaps_dirLight[index].Activate(context);
const float siz = l->shadowCam[index].size * 0.5f;