/******************************************************************************/
// NOTE: Change the path to suit your location of "material_user_shader.enum.h"
#include "C:/EsenthelEngine_DX10plus/Editor/Projects/material_user_shader.enum.h"
/******************************************************************************/
// --------------------------------------------------
// This is the "material_user_shader.enum.h" file :
// --------------------------------------------------
//enum MATERIAL_USER_SHADER
//{
// MUS_DEFAULT,
// MUS_CUSTOM ,
// MUS_CUSTOM2,
//};
// --------------------------------------------------
/******************************************************************************/
Mesh ball1, ball2;
Matrix ball1_matrix, ball2_matrix;
MaterialPtr mat0;
Material mat0_with_custom_shader;
MaterialPtr mat1;
Material mat1_with_custom_shader;
Slider slider1 ; // gui slider
Slider slider2 ; // gui slider
/******************************************************************************/
void CompileShaders_1()
{
if(D.shaderModel()==SM_GL)
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_1.cpp", S+DataPath()+"Shader/GL/User/Custom Shader", SM_GL);
}else
if(D.shaderModel()>=SM_4)
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_1.cpp", S+DataPath()+"Shader/4/User/Custom Shader", SM_4);
}else
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_1.cpp", S+DataPath()+"Shader/2/User/Custom Shader", SM_2);
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_1.cpp", S+DataPath()+"Shader/3/User/Custom Shader", SM_3);
}
}
/******************************************************************************/
void CompileShaders_2()
{
if(D.shaderModel()==SM_GL)
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_2.cpp", S+DataPath()+"Shader/GL/User/Custom Shader2", SM_GL);
}else
if(D.shaderModel()>=SM_4)
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_2.cpp", S+DataPath()+"Shader/4/User/Custom Shader2", SM_4);
}else
{
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_2cpp", S+DataPath()+"Shader/2/User/Custom Shader2", SM_2);
ShaderCompile("C:/EsenthelEngine_DX10plus/Editor/Projects/Shader HLSL/TwoShader_2.cpp", S+DataPath()+"Shader/3/User/Custom Shader2", SM_3);
}
}
/******************************************************************************/
ShaderTech* GetShader(RENDER_MODE mode, Material *material[4], UInt mesh_base_flag, Int lod_index, Bool allow_tesselation)
{
if(material[0])switch(material[0]->user_shader)
{
case MUS_CUSTOM:
{
if(mode==RM_BLEND)return Shaders("User/Custom Shader")->firstTech();
return NULL;
}break;
case MUS_CUSTOM2:
{
if(mode==RM_BLEND)return Shaders("User/Custom Shader2")->firstTech();
return NULL;
}break;
}
return GetDefaultShader(mode, material, mesh_base_flag, lod_index, allow_tesselation);
}
/******************************************************************************/
void InitPre()
{
EE_INIT();
D.ambientPower(0.3f);
D.setGetShaderFunc(GetShader);
}
/******************************************************************************/
Bool Init()
{
// set initial camera position
Vec InitialCameraLocation = Vec(0.0f, 0.0f,-4.0f);
Cam.setPosDir(InitialCameraLocation);
// compile shaders
CompileShaders_1(); // compile "TwoShader_1" as "Custom Shader"
CompileShaders_2(); // compile "TwoShader_2" as "Custom shader2"
// create sliders to control opacity of each ball
Gui+=slider1.create(Rect( -1.0, -0.6, -0.2, -0.5), 0.5); // create slider1 with initial value 0.5
Gui+=slider2.create(Rect( 0.4, -0.6, 1.2, -0.5), 0.5); // create slider2 with initial value 0.5
// set materials and meshes
mat0.require(UID(674972757, 1342010767, 2106461592, 1897094128));
mat0_with_custom_shader=*mat0;
mat0_with_custom_shader.user_shader=MUS_CUSTOM; // custom shader for ball1 material
mat0_with_custom_shader.validate();
mat1.require(UID(674972757, 1342010767, 2106461592, 1897094128));
mat1_with_custom_shader=*mat1;
mat1_with_custom_shader.user_shader=MUS_CUSTOM2; // custom shader for ball2 material
mat1_with_custom_shader.validate();
ball1.parts.New().base.create(Ball(1), VTX_TEX0|VTX_NRM|VTX_TAN);
ball2.parts.New().base.create(Ball(1), VTX_TEX0|VTX_NRM|VTX_TAN);
ball1.setMaterial(&mat0_with_custom_shader ).setRender().setBox(); // ball1 to use MUS_CUSTOM
ball2.setMaterial(&mat1_with_custom_shader ).setRender().setBox(); // ball2 to use MUS_CUSTOM2
ball1_matrix.setPos(Vec(-2, 0, 0));
ball2_matrix.setPos(Vec(2, 0, 0));
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Update()
{
if(Kb.bp(KB_ESC))return false;
//Cam.transformByMouse(0.1f, 1000, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
Cam.set();
Gui.update();
// set shader's custom parameter value
SPSet(8"Opacity_1", slider1());
SPSet(8"Opacity_2", slider2());
return true;
}
/******************************************************************************/
void Render()
{
switch(Renderer())
{
case RM_PREPARE:
{
LightDir(!Vec(0, 0, -1)).add();
}break;
case RM_BLEND:
{
ball1.drawBlend(ball1_matrix);
ball2.drawBlend(ball2_matrix);
}break;
}
}
void Draw()
{
Renderer(Render);
Gui.draw();
}
/******************************************************************************/