GteAmbientLightEffect.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
12 AmbientLightEffect::AmbientLightEffect(std::shared_ptr<ProgramFactory> const& factory,
13  BufferUpdater const& updater, std::shared_ptr<Material> const& material,
14  std::shared_ptr<Lighting> const& lighting)
15  :
16  LightingEffect(factory, updater, msVSSource, msPSSource, material, lighting, nullptr)
17 {
18  mMaterialConstant = std::make_shared<ConstantBuffer>(sizeof(InternalMaterial), true);
20  mProgram->GetVShader()->Set("Material", mMaterialConstant);
21 
22  mLightingConstant = std::make_shared<ConstantBuffer>(sizeof(InternalLighting), true);
24  mProgram->GetVShader()->Set("Lighting", mLightingConstant);
25 }
26 
28 {
29  InternalMaterial* internalMaterial = mMaterialConstant->Get<InternalMaterial>();
30  internalMaterial->emissive = mMaterial->emissive;
31  internalMaterial->ambient = mMaterial->ambient;
33 }
34 
36 {
37  InternalLighting* internalLighting = mLightingConstant->Get<InternalLighting>();
38  internalLighting->ambient = mLighting->ambient;
39  internalLighting->attenuation = mLighting->attenuation;
41 }
42 
44 "uniform PVWMatrix\n"
45 "{\n"
46 " mat4 pvwMatrix;\n"
47 "};\n"
48 "\n"
49 "uniform Material\n"
50 "{\n"
51 " vec4 materialEmissive;\n"
52 " vec4 materialAmbient;\n"
53 "};\n"
54 "\n"
55 "uniform Light\n"
56 "{\n"
57 " vec4 lightingAmbient;\n"
58 " vec4 lightingAttenuation;\n"
59 "};\n"
60 "\n"
61 "layout(location = 0) in vec3 modelPosition;\n"
62 "\n"
63 "layout(location = 0) out vec4 vertexColor;\n"
64 "\n"
65 "void main()\n"
66 "{\n"
67 " vec3 ambient = lightingAttenuation.w * lightingAmbient.rgb;\n"
68 " vertexColor.rgb = materialEmissive.rgb + materialAmbient.rgb * ambient;\n"
69 " vertexColor.a = 1.0f;\n"
70 "#if GTE_USE_MAT_VEC\n"
71 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n"
72 "#else\n"
73 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n"
74 "#endif\n"
75 "}\n";
76 
78 "layout(location = 0) in vec4 vertexColor;\n"
79 "\n"
80 "layout(location = 0) out vec4 pixelColor0;\n"
81 "\n"
82 "void main()\n"
83 "{\n"
84 " pixelColor0 = vertexColor;\n"
85 "}\n";
86 
87 
89 "cbuffer PVWMatrix\n"
90 "{\n"
91 " float4x4 pvwMatrix;\n"
92 "};\n"
93 "\n"
94 "cbuffer Material\n"
95 "{\n"
96 " float4 materialEmissive;\n"
97 " float4 materialAmbient;\n"
98 "};\n"
99 "\n"
100 "cbuffer Light\n"
101 "{\n"
102 " float4 lightingAmbient;\n"
103 " float4 lightingAttenuation;\n"
104 "};\n"
105 "\n"
106 "struct VS_INPUT\n"
107 "{\n"
108 " float3 modelPosition : POSITION;\n"
109 "};\n"
110 "\n"
111 "struct VS_OUTPUT\n"
112 "{\n"
113 " float4 vertexColor : COLOR0;\n"
114 " float4 clipPosition : SV_POSITION;\n"
115 "};\n"
116 "\n"
117 "VS_OUTPUT VSMain(VS_INPUT input)\n"
118 "{\n"
119 " VS_OUTPUT output;\n"
120 "\n"
121 " float3 ambient = lightingAttenuation.w * lightingAmbient.rgb;\n"
122 " output.vertexColor.rgb = materialEmissive.rgb + materialAmbient.rgb * ambient;\n"
123 " output.vertexColor.a = 1.0f;\n"
124 "#if GTE_USE_MAT_VEC\n"
125 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n"
126 "#else\n"
127 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n"
128 "#endif\n"
129 " return output;\n"
130 "}\n"
131 "\n"
132 "struct PS_INPUT\n"
133 "{\n"
134 " float4 vertexColor : COLOR0;\n"
135 "};\n"
136 "\n"
137 "struct PS_OUTPUT\n"
138 "{\n"
139 " float4 pixelColor0 : SV_TARGET0;\n"
140 "};\n"
141 "\n"
142 "PS_OUTPUT PSMain(PS_INPUT input)\n"
143 "{\n"
144 " PS_OUTPUT output;\n"
145 " output.pixelColor0 = input.vertexColor;\n"
146 " return output;\n"
147 "}\n";
148 
150 {
152  &msHLSLSource
153 };
154 
156 {
158  &msHLSLSource
159 };
static std::string const msGLSLVSSource
virtual void UpdateMaterialConstant()
std::shared_ptr< Material > mMaterial
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
Definition: GteBuffer.h:24
static std::string const * msPSSource[ProgramFactory::PF_NUM_API]
static std::string const * msVSSource[ProgramFactory::PF_NUM_API]
static std::string const msGLSLPSSource
std::shared_ptr< Lighting > mLighting
virtual void UpdateLightingConstant()
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
std::shared_ptr< ConstantBuffer > mLightingConstant
std::shared_ptr< ConstantBuffer > mMaterialConstant
AmbientLightEffect(std::shared_ptr< ProgramFactory > const &factory, BufferUpdater const &updater, std::shared_ptr< Material > const &material, std::shared_ptr< Lighting > const &lighting)
std::shared_ptr< VisualProgram > mProgram
static std::string const msHLSLSource


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:58