13 BufferUpdater const& updater,
int select, std::shared_ptr<Material>
const& material,
14 std::shared_ptr<Lighting>
const& lighting, std::shared_ptr<LightCameraGeometry>
const& geometry)
16 LightingEffect(factory, updater, msVSSource[select & 1], msPSSource[select & 1],
17 material, lighting, geometry)
28 if ((select & 1) == 0)
82 " vec4 materialEmissive;\n" 83 " vec4 materialAmbient;\n" 84 " vec4 materialDiffuse;\n" 85 " vec4 materialSpecular;\n" 90 " vec4 lightingAmbient;\n" 91 " vec4 lightingDiffuse;\n" 92 " vec4 lightingSpecular;\n" 93 " vec4 lightingSpotCutoff;\n" 94 " vec4 lightingAttenuation;\n" 97 "uniform LightCameraGeometry\n" 99 " vec4 lightModelPosition;\n" 100 " vec4 lightModelDirection;\n" 101 " vec4 cameraModelPosition;\n" 104 "layout(location = 0) in vec3 modelPosition;\n" 105 "layout(location = 1) in vec3 modelNormal;\n" 107 "layout(location = 0) out vec4 vertexColor;\n" 112 " vec3 modelLightDiff = modelPosition - lightModelPosition.xyz;\n" 113 " vec3 vertexDirection = normalize(modelLightDiff);\n" 114 " float vertexCosAngle = dot(lightModelDirection.xyz, vertexDirection);\n" 115 " if (vertexCosAngle >= lightingSpotCutoff.y)\n" 117 " float NDotL = -dot(modelNormal, vertexDirection);\n" 118 " vec3 viewVector = normalize(cameraModelPosition.xyz - modelPosition);\n" 119 " vec3 halfVector = normalize(viewVector - vertexDirection);\n" 120 " float NDotH = dot(modelNormal, halfVector);\n" 121 " lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 122 " lighting.w = pow(abs(vertexCosAngle), lightingSpotCutoff.w);\n" 126 " lighting = vec4(1.0f, 0.0f, 0.0f, 0.0f);\n" 129 " float distance = length(modelLightDiff);\n" 130 " float attenuation = lightingAttenuation.w / (lightingAttenuation.x + distance *\n" 131 " (lightingAttenuation.y + distance * lightingAttenuation.z));\n" 133 " vec3 color = materialAmbient.rgb * lightingAmbient.rgb + lighting.w * (\n" 134 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 135 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb);\n" 137 " vertexColor.rgb = materialEmissive.rgb + attenuation * color;\n" 138 " vertexColor.a = materialDiffuse.a;\n" 139 "#if GTE_USE_MAT_VEC\n" 140 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n" 142 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n" 146 "uniform PVWMatrix\n" 151 "layout(location = 0) in vec3 modelPosition;\n" 152 "layout(location = 1) in vec3 modelNormal;\n" 154 "layout(location = 0) out vec3 vertexPosition;\n" 155 "layout(location = 1) out vec3 vertexNormal;\n" 159 " vertexPosition = modelPosition;\n" 160 " vertexNormal = modelNormal;\n" 161 "#if GTE_USE_MAT_VEC\n" 162 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n" 164 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n" 171 "layout(location = 0) in vec4 vertexColor;\n" 173 "layout(location = 0) out vec4 pixelColor0;\n" 177 " pixelColor0 = vertexColor;\n" 183 " vec4 materialEmissive;\n" 184 " vec4 materialAmbient;\n" 185 " vec4 materialDiffuse;\n" 186 " vec4 materialSpecular;\n" 191 " vec4 lightingAmbient;\n" 192 " vec4 lightingDiffuse;\n" 193 " vec4 lightingSpecular;\n" 194 " vec4 lightingSpotCutoff;\n" 195 " vec4 lightingAttenuation;\n" 198 "uniform LightCameraGeometry\n" 200 " vec4 lightModelPosition;\n" 201 " vec4 lightModelDirection;\n" 202 " vec4 cameraModelPosition;\n" 205 "layout(location = 0) in vec3 vertexPosition;\n" 206 "layout(location = 1) in vec3 vertexNormal;\n" 208 "layout(location = 0) out vec4 pixelColor0;\n" 213 " vec3 normal = normalize(vertexNormal);\n" 214 " vec3 modelLightDiff = vertexPosition - lightModelPosition.xyz;\n" 215 " vec3 vertexDirection = normalize(modelLightDiff);\n" 216 " float vertexCosAngle = dot(lightModelDirection.xyz, vertexDirection);\n" 217 " if (vertexCosAngle >= lightingSpotCutoff.y)\n" 219 " float NDotL = -dot(normal, vertexDirection);\n" 220 " vec3 viewVector = normalize(cameraModelPosition.xyz - vertexPosition);\n" 221 " vec3 halfVector = normalize(viewVector - vertexDirection);\n" 222 " float NDotH = dot(normal, halfVector);\n" 223 " lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 224 " lighting.w = pow(abs(vertexCosAngle), lightingSpotCutoff.w);\n" 228 " lighting = vec4(1.0f, 0.0f, 0.0f, 0.0f);\n" 231 " // Compute the distance-based attenuation.\n" 232 " float distance = length(modelLightDiff);\n" 233 " float attenuation = lightingAttenuation.w / (lightingAttenuation.x + distance *\n" 234 " (lightingAttenuation.y + distance * lightingAttenuation.z));\n" 236 " // Compute the lighting color.\n" 237 " vec3 color = materialAmbient.rgb * lightingAmbient.rgb + lighting.w * (\n" 238 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 239 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb);\n" 241 " // Compute the pixel color.\n" 242 " pixelColor0.rgb = materialEmissive.rgb + attenuation*color;\n" 243 " pixelColor0.a = materialDiffuse.a;\n" 249 "cbuffer PVWMatrix\n" 251 " float4x4 pvwMatrix;\n" 256 " float4 materialEmissive;\n" 257 " float4 materialAmbient;\n" 258 " float4 materialDiffuse;\n" 259 " float4 materialSpecular;\n" 264 " float4 lightingAmbient;\n" 265 " float4 lightingDiffuse;\n" 266 " float4 lightingSpecular;\n" 267 " float4 lightingSpotCutoff;\n" 268 " float4 lightingAttenuation;\n" 271 "cbuffer LightCameraGeometry\n" 273 " float4 lightModelPosition;\n" 274 " float4 lightModelDirection;\n" 275 " float4 cameraModelPosition;\n" 280 " float3 modelPosition : POSITION;\n" 281 " float3 modelNormal : NORMAL;\n" 286 " float4 vertexColor : COLOR0;\n" 287 " float4 clipPosition : SV_POSITION;\n" 290 "VS_OUTPUT VSMain(VS_INPUT input)\n" 292 " VS_OUTPUT output;\n" 294 " float4 lighting;\n" 295 " float3 modelLightDiff = input.modelPosition - lightModelPosition.xyz;\n" 296 " float3 vertexDirection = normalize(modelLightDiff);\n" 297 " float vertexCosAngle = dot(lightModelDirection.xyz, vertexDirection);\n" 298 " if (vertexCosAngle >= lightingSpotCutoff.y)\n" 300 " float NDotL = -dot(input.modelNormal, vertexDirection);\n" 301 " float3 viewVector = normalize(cameraModelPosition.xyz - input.modelPosition);\n" 302 " float3 halfVector = normalize(viewVector - vertexDirection);\n" 303 " float NDotH = dot(input.modelNormal, halfVector);\n" 304 " lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 305 " lighting.w = pow(abs(vertexCosAngle), lightingSpotCutoff.w);\n" 309 " lighting = float4(1.0f, 0.0f, 0.0f, 0.0f);\n" 312 " float distance = length(modelLightDiff);\n" 313 " float attenuation = lightingAttenuation.w / (lightingAttenuation.x + distance *\n" 314 " (lightingAttenuation.y + distance * lightingAttenuation.z));\n" 316 " float3 color = materialAmbient.rgb * lightingAmbient.rgb + lighting.w * (\n" 317 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 318 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb);\n" 320 " output.vertexColor.rgb = materialEmissive.rgb + attenuation * color;\n" 321 " output.vertexColor.a = materialDiffuse.a;\n" 322 "#if GTE_USE_MAT_VEC\n" 323 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n" 325 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n" 332 " float4 vertexColor : COLOR0;\n" 337 " float4 pixelColor0 : SV_TARGET0;\n" 340 "PS_OUTPUT PSMain(PS_INPUT input)\n" 342 " PS_OUTPUT output;\n" 343 " output.pixelColor0 = input.vertexColor;\n" 347 "cbuffer PVWMatrix\n" 349 " float4x4 pvwMatrix;\n" 354 " float3 modelPosition : POSITION;\n" 355 " float3 modelNormal : NORMAL;\n" 360 " float3 vertexPosition : TEXCOORD0;\n" 361 " float3 vertexNormal : TEXCOORD1;\n" 362 " float4 clipPosition : SV_POSITION;\n" 365 "VS_OUTPUT VSMain(VS_INPUT input)\n" 367 " VS_OUTPUT output;\n" 369 " output.vertexPosition = input.modelPosition;\n" 370 " output.vertexNormal = input.modelNormal;\n" 371 "#if GTE_USE_MAT_VEC\n" 372 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n" 374 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n" 381 " float4 materialEmissive;\n" 382 " float4 materialAmbient;\n" 383 " float4 materialDiffuse;\n" 384 " float4 materialSpecular;\n" 389 " float4 lightingAmbient;\n" 390 " float4 lightingDiffuse;\n" 391 " float4 lightingSpecular;\n" 392 " float4 lightingSpotCutoff;\n" 393 " float4 lightingAttenuation;\n" 396 "cbuffer LightCameraGeometry\n" 398 " float4 lightModelPosition;\n" 399 " float4 lightModelDirection;\n" 400 " float4 cameraModelPosition;\n" 405 " float3 vertexPosition : TEXCOORD0;\n" 406 " float3 vertexNormal : TEXCOORD1;\n" 411 " float4 pixelColor0 : SV_TARGET0;\n" 414 "PS_OUTPUT PSMain(PS_INPUT input)\n" 416 " PS_OUTPUT output;\n" 418 " float4 lighting;\n" 419 " float3 normal = normalize(input.vertexNormal);\n" 420 " float3 modelLightDiff = input.vertexPosition - lightModelPosition.xyz;\n" 421 " float3 vertexDirection = normalize(modelLightDiff);\n" 422 " float vertexCosAngle = dot(lightModelDirection.xyz, vertexDirection);\n" 423 " if (vertexCosAngle >= lightingSpotCutoff.y)\n" 425 " float NDotL = -dot(normal, vertexDirection);\n" 426 " float3 viewVector = normalize(cameraModelPosition.xyz - input.vertexPosition);\n" 427 " float3 halfVector = normalize(viewVector - vertexDirection);\n" 428 " float NDotH = dot(normal, halfVector);\n" 429 " lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 430 " lighting.w = pow(abs(vertexCosAngle), lightingSpotCutoff.w);\n" 434 " lighting = float4(1.0f, 0.0f, 0.0f, 0.0f);\n" 437 " // Compute the distance-based attenuation.\n" 438 " float distance = length(modelLightDiff);\n" 439 " float attenuation = lightingAttenuation.w / (lightingAttenuation.x + distance *\n" 440 " (lightingAttenuation.y + distance * lightingAttenuation.z));\n" 442 " // Compute the lighting color.\n" 443 " float3 color = materialAmbient.rgb * lightingAmbient.rgb + lighting.w * (\n" 444 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 445 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb);\n" 447 " // Compute the pixel color.\n" 448 " output.pixelColor0.rgb = materialEmissive.rgb + attenuation*color;\n" 449 " output.pixelColor0.a = materialDiffuse.a;\n" virtual void UpdateMaterialConstant()
std::shared_ptr< Material > mMaterial
virtual void UpdateLightingConstant()
static std::string const msHLSLSource[2]
Vector4< float > attenuation
std::shared_ptr< LightCameraGeometry > mGeometry
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
static std::string const * msVSSource[2][ProgramFactory::PF_NUM_API]
std::shared_ptr< ConstantBuffer > mGeometryConstant
Vector4< float > spotCutoff
SpotLightEffect(std::shared_ptr< ProgramFactory > const &factory, BufferUpdater const &updater, int select, std::shared_ptr< Material > const &material, std::shared_ptr< Lighting > const &lighting, std::shared_ptr< LightCameraGeometry > const &geometry)
std::shared_ptr< Lighting > mLighting
virtual void UpdateGeometryConstant()
Vector4< float > cameraModelPosition
virtual void UpdateLightingConstant()
static std::string const msGLSLVSSource[2]
Vector4< float > emissive
Vector4< float > specular
Vector4< float > lightModelPosition
GLsizei const GLchar *const * string
std::shared_ptr< ConstantBuffer > mLightingConstant
static std::string GetShaderSourceLitFunctionGLSL()
Vector4< float > lightModelDirection
std::shared_ptr< ConstantBuffer > mMaterialConstant
virtual void UpdateGeometryConstant()
Vector4< float > specular
static std::string const * msPSSource[2][ProgramFactory::PF_NUM_API]
virtual void UpdateMaterialConstant()
static std::string const msGLSLPSSource[2]
std::shared_ptr< VisualProgram > mProgram