123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- Texture2D shaderTexture : register(t0);
- SamplerState SampleType;
- cbuffer Kamera : register(b0)
- {
- float4 kPosition;
- }
- cbuffer Material : register(b1)
- {
- float ambientFactor;
- float diffusFactor;
- float specularFactor;
- };
- cbuffer LightCount : register(b2)
- {
- int diffuseLightCount;
- int pointLightCount;
- }
- struct DiffuseLight
- {
- float3 direction;
- float3 color;
- };
- struct PointLight
- {
- float3 position;
- float3 color;
- float radius;
- };
- cbuffer TexturEffect : register(b3)
- {
- bool effectEnabled;
- float effectPercentage;
- };
- StructuredBuffer< DiffuseLight > difuseLights : register(t1);
- StructuredBuffer< PointLight > pointLights : register(t2);
- Texture2D additionalTexture : register(t3);
- struct PixelInputType
- {
- float4 worldPos : POSITION;
- float4 position : SV_POSITION;
- float2 tex : TEXCOORD0;
- float3 normal : TEXCOORD1;
- float4 light1 : TEXCOORD2;
- float4 light2 : TEXCOORD3;
- };
- float4 TexturePixelShader(PixelInputType input) : SV_TARGET
- {
- float3 diffuseLight = float3(0, 0, 0);
- float3 specularLight = float3(0, 0, 0);
- float4 materialColor = shaderTexture.Sample(SampleType, input.tex);
- if (effectEnabled)
- {
- bool effectAlpha = effectPercentage > 1.f;
- float percentage = effectPercentage;
- if (effectAlpha) percentage -= 1.f;
- if (effectEnabled && !effectAlpha) clip(materialColor.a - 0.25);
- float dist = sqrt((input.tex.x - 0.5f) * (input.tex.x - 0.5f) + (input.tex.y - 0.5f) * (input.tex.y - 0.5f)) / sqrt(0.5f);
- if (dist < percentage)
- {
- float alphaMultiplier = (percentage - dist) / 0.2f;
- if (alphaMultiplier > 1)
- alphaMultiplier = 1.f;
- float4 effectColor = additionalTexture.Sample(SampleType, input.tex);
- float effectA = effectColor.a;
- materialColor = effectColor * (effectColor.a * alphaMultiplier) + materialColor * (1 - effectColor.a * alphaMultiplier);
- if (effectAlpha)
- {
- materialColor.a = effectA * alphaMultiplier;
- if (materialColor.a > 1.0) materialColor.a = 1.0;
- }
- }
- }
- else
- {
- clip(materialColor.a - 0.25);
- }
- if (input.light1.w > 0)
- {
- diffuseLight = float3(materialColor.x * input.light1.x,
- materialColor.y * input.light1.y,
- materialColor.z * input.light1.z);
- float4 diffuseLight2 = float4(materialColor.x * input.light2.x,
- materialColor.y * input.light2.y,
- materialColor.z * input.light2.z, 0);
- if (diffuseLightCount > 0)
- {
- float factor = dot(input.normal, -difuseLights[0].direction);
- if (factor < 0)
- factor = 0;
- factor = factor * 0.5 + 0.5;
- diffuseLight = diffuseLight * factor;
- }
- else
- {
- diffuseLight = diffuseLight * 0.5;
- }
- if (diffuseLight2.x > diffuseLight.x)
- {
- diffuseLight.x = diffuseLight2.x;
- }
- if (diffuseLight2.y > diffuseLight.y)
- {
- diffuseLight.y = diffuseLight2.y;
- }
- if (diffuseLight2.z > diffuseLight.z)
- {
- diffuseLight.z = diffuseLight2.z;
- }
- }
- else
- {
- for (int j = 0; j < diffuseLightCount; j++)
- {
- if (dot(input.normal, -difuseLights[j].direction) < 0)
- continue;
- diffuseLight += difuseLights[j].color * dot(input.normal, -difuseLights[j].direction);
- }
- diffuseLight = float3(1.0, 1.0, 1.0);
-
- }
-
-
- float4 textureColor = saturate((materialColor * ambientFactor) + (float4(diffuseLight.x, diffuseLight.y, diffuseLight.z, 0) * diffusFactor) + (float4(specularLight.x, specularLight.y, specularLight.z, 0) * specularFactor));
- textureColor.a = materialColor.a;
- if (isnan(diffuseLight.x * diffusFactor))
- textureColor = materialColor;
- return textureColor;
-
-
-
-
- }
|