| 541 | } |
| 542 | |
| 543 | void Sample_ShaderSystem::generateShaders(Entity* entity) |
| 544 | { |
| 545 | for (unsigned int i=0; i < entity->getNumSubEntities(); ++i) |
| 546 | { |
| 547 | SubEntity* curSubEntity = entity->getSubEntity(i); |
| 548 | MaterialPtr curMaterial = curSubEntity->getMaterial(); |
| 549 | bool success; |
| 550 | |
| 551 | // Create the shader based technique of this material. |
| 552 | success = mShaderGenerator->createShaderBasedTechnique(*curMaterial, MSN_DEFAULT, MSN_SHADERGEN); |
| 553 | |
| 554 | // Setup custom shader sub render states according to current setup. |
| 555 | if (success) |
| 556 | { |
| 557 | Pass* curPass = curMaterial->getTechnique(0)->getPass(0); |
| 558 | |
| 559 | bool cookTorrance = mCurLightingModel == SSLM_CookTorranceLighting || mCurLightingModel == SSLM_ImageBasedLighting; |
| 560 | |
| 561 | if (mSpecularEnable) |
| 562 | { |
| 563 | curPass->setSpecular(!cookTorrance ? ColourValue::White : ColourValue(0.1, 0.0)); |
| 564 | curPass->setShininess(32.0); |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | curPass->setSpecular(!cookTorrance ? ColourValue::Black : ColourValue(1.0, 0.0)); |
| 569 | curPass->setShininess(0.0); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | // Grab the first pass render state. |
| 574 | // NOTE: For more complicated samples iterate over the passes and build each one of them as desired. |
| 575 | RTShader::RenderState* renderState = mShaderGenerator->getRenderState( |
| 576 | MSN_SHADERGEN, *curMaterial); |
| 577 | |
| 578 | // Remove all sub render states. |
| 579 | renderState->resetToBuiltinSubRenderStates(); |
| 580 | |
| 581 | |
| 582 | #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS |
| 583 | if (mCurLightingModel == SSLM_CookTorranceLighting || mCurLightingModel == SSLM_ImageBasedLighting) |
| 584 | { |
| 585 | auto lightModel = mShaderGenerator->createSubRenderState(RTShader::SRS_COOK_TORRANCE_LIGHTING); |
| 586 | renderState->addTemplateSubRenderState(lightModel); |
| 587 | } |
| 588 | else if (mCurLightingModel == SSLM_PerPixelLighting) |
| 589 | { |
| 590 | RTShader::SubRenderState* perPixelLightModel = mShaderGenerator->createSubRenderState(RTShader::SRS_PER_PIXEL_LIGHTING); |
| 591 | |
| 592 | renderState->addTemplateSubRenderState(perPixelLightModel); |
| 593 | } |
| 594 | else if (mCurLightingModel == SSLM_NormalMapLightingObjectSpace) |
| 595 | { |
| 596 | // Apply normal map only on main entity. |
| 597 | if (entity->getName() == MAIN_ENTITY_NAME) |
| 598 | { |
| 599 | RTShader::SubRenderState* normalMapSubRS = mShaderGenerator->createSubRenderState(RTShader::SRS_NORMALMAP); |
| 600 |
nothing calls this directly
no test coverage detected