1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /////////////
- // GLOBALS //
- /////////////
- Texture2D shaderTexture : register( t0 );
- SamplerState SampleType;
- // The position of the kamera
- struct KameraBuffer
- {
- float4 kPosition;
- };
- // these values should sum up to 1
- struct Material
- {
- float ambientFactor;
- float diffusFactor;
- float specularFactor;
- };
- struct LightCount
- {
- int diffuseLightCount;
- int pointLightCount;
- };
- ConstantBuffer<KameraBuffer> Kamera : register( b2 );
- ConstantBuffer<Material> Object : register( b3 );
- ConstantBuffer<LightCount> Light : register( b4 );
- // lights
- struct DiffuseLight
- {
- float3 direction;
- float3 color;
- };
- struct PointLight
- {
- float3 position;
- float3 color;
- float radius;
- };
- //StructuredBuffer< DiffuseLight > difuseLights : register( t1 );
- //StructuredBuffer< PointLight > pointLights : register( t2 );
- //////////////
- // TYPEDEFS //
- //////////////
- struct PixelInputType
- {
- float4 worldPos : POSITION;
- float4 position : SV_POSITION;
- float2 tex : TEXCOORD0;
- float3 normal : TEXCOORD1;
- };
- ////////////////////////////////////////////////////////////////////////////////
- // Pixel Shader
- ////////////////////////////////////////////////////////////////////////////////
- float4 main( PixelInputType input ) : SV_TARGET
- {
- float3 diffuseLight = float3( 0, 0, 0 );
- float3 specularLight = float3( 0, 0, 0 );
- /* for( int j = 0; j < Light.diffuseLightCount; j++ )
- {
- if( dot( input.normal, -difuseLights[ j ].direction ) < 0 )
- continue;
- diffuseLight += difuseLights[ j ].color * dot( input.normal, -difuseLights[ j ].direction );
- }
- for( int i = 0; i < Light.pointLightCount; i++ )
- {
- float3 lightDir = pointLights[ i ].position - input.worldPos.xyz;
- float factor = pointLights[ i ].radius / length( lightDir );
- float f = dot( input.normal, normalize( lightDir ) );
- if( f > 0 )
- {
- diffuseLight += pointLights[ i ].color * f * factor;
- f = dot( normalize( reflect( normalize( -lightDir ), input.normal ) ), normalize( Kamera.kPosition.xyz - input.worldPos.xyz ) );
- if( f > 0 )
- specularLight += pointLights[ i ].color * f * factor;
- }
- }*/
- float4 materialColor = shaderTexture.Sample( SampleType, input.tex );
- float4 textureColor = saturate( materialColor * Object.ambientFactor + float4( diffuseLight.x, diffuseLight.y, diffuseLight.z, 0 ) * Object.diffusFactor + float4( specularLight.x, specularLight.y, specularLight.z, 0 ) * Object.specularFactor );
- textureColor.a = materialColor.a;
- return textureColor;
- }
|