13 BufferUpdater const& updater, std::shared_ptr<Material>
const& material,
14 std::shared_ptr<Lighting>
const& lighting, std::shared_ptr<LightCameraGeometry>
const& geometry,
15 std::shared_ptr<Texture2>
const&
texture, SamplerState::Filter
filter, SamplerState::Mode mode0,
16 SamplerState::Mode mode1)
18 LightingEffect(factory, updater, msVSSource, msPSSource, material, lighting, geometry),
21 mSampler = std::make_shared<SamplerState>();
38 #if defined(GTE_DEV_OPENGL) 80 "layout(location = 0) in vec3 modelPosition;\n" 81 "layout(location = 1) in vec3 modelNormal;\n" 82 "layout(location = 2) in vec2 modelTCoord;\n" 84 "layout(location = 0) out vec3 vertexPosition;\n" 85 "layout(location = 1) out vec3 vertexNormal;\n" 86 "layout(location = 2) out vec2 vertexTCoord;\n" 90 " vertexPosition = modelPosition;\n" 91 " vertexNormal = modelNormal;\n" 92 " vertexTCoord = modelTCoord;\n" 93 "#if GTE_USE_MAT_VEC\n" 94 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n" 96 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n" 104 " vec4 materialEmissive;\n" 105 " vec4 materialAmbient;\n" 106 " vec4 materialDiffuse;\n" 107 " vec4 materialSpecular;\n" 112 " vec4 lightingAmbient;\n" 113 " vec4 lightingDiffuse;\n" 114 " vec4 lightingSpecular;\n" 115 " vec4 lightingAttenuation;\n" 118 "uniform LightCameraGeometry\n" 120 " vec4 lightModelDirection;\n" 121 " vec4 cameraModelPosition;\n" 124 "uniform sampler2D baseSampler;\n" 126 "layout(location = 0) in vec3 vertexPosition;\n" 127 "layout(location = 1) in vec3 vertexNormal;\n" 128 "layout(location = 2) in vec2 vertexTCoord;\n" 130 "layout(location = 0) out vec4 pixelColor0;\n" 134 " vec3 normal = normalize(vertexNormal);\n" 135 " float NDotL = -dot(normal, lightModelDirection.xyz);\n" 136 " vec3 viewVector = normalize(cameraModelPosition.xyz - vertexPosition);\n" 137 " vec3 halfVector = normalize(viewVector - lightModelDirection.xyz);\n" 138 " float NDotH = dot(normal, halfVector);\n" 139 " vec4 lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 140 " vec3 lightingColor = materialAmbient.rgb * lightingAmbient.rgb +\n" 141 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 142 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb;\n" 144 " vec4 textureColor = texture(baseSampler, vertexTCoord);\n" 146 " vec3 color = lightingColor * textureColor.rgb;\n" 147 " pixelColor0.rgb = materialEmissive.rgb + lightingAttenuation.w * color;\n" 148 " pixelColor0.a = materialDiffuse.a * textureColor.a;\n" 153 "cbuffer PVWMatrix\n" 155 " float4x4 pvwMatrix;\n" 160 " float3 modelPosition : POSITION;\n" 161 " float3 modelNormal : NORMAL;\n" 162 " float2 modelTCoord : TEXCOORD0;\n" 167 " float3 vertexPosition : TEXCOORD0;\n" 168 " float3 vertexNormal : TEXCOORD1;\n" 169 " float2 vertexTCoord : TEXCOORD2;\n" 170 " float4 clipPosition : SV_POSITION;\n" 173 "VS_OUTPUT VSMain(VS_INPUT input)\n" 175 " VS_OUTPUT output;\n" 177 " output.vertexPosition = input.modelPosition;\n" 178 " output.vertexNormal = input.modelNormal;\n" 179 " output.vertexTCoord = input.modelTCoord;\n" 180 "#if GTE_USE_MAT_VEC\n" 181 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n" 183 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n" 190 " float4 materialEmissive;\n" 191 " float4 materialAmbient;\n" 192 " float4 materialDiffuse;\n" 193 " float4 materialSpecular;\n" 198 " float4 lightingAmbient;\n" 199 " float4 lightingDiffuse;\n" 200 " float4 lightingSpecular;\n" 201 " float4 lightingAttenuation;\n" 204 "cbuffer LightCameraGeometry\n" 206 " float4 lightModelDirection;\n" 207 " float4 cameraModelPosition;\n" 210 "Texture2D<float4> baseTexture;\n" 211 "SamplerState baseSampler;\n" 215 " float3 vertexPosition : TEXCOORD0;\n" 216 " float3 vertexNormal : TEXCOORD1;\n" 217 " float2 vertexTCoord : TEXCOORD2;\n" 222 " float4 pixelColor0 : SV_TARGET0;\n" 225 "PS_OUTPUT PSMain(PS_INPUT input)\n" 227 " PS_OUTPUT output;\n" 229 " float3 normal = normalize(input.vertexNormal);\n" 230 " float NDotL = -dot(normal, lightModelDirection.xyz);\n" 231 " float3 viewVector = normalize(cameraModelPosition.xyz - input.vertexPosition);\n" 232 " float3 halfVector = normalize(viewVector - lightModelDirection.xyz);\n" 233 " float NDotH = dot(normal, halfVector);\n" 234 " float4 lighting = lit(NDotL, NDotH, materialSpecular.a);\n" 235 " float3 lightingColor = materialAmbient.rgb * lightingAmbient.rgb +\n" 236 " lighting.y * materialDiffuse.rgb * lightingDiffuse.rgb +\n" 237 " lighting.z * materialSpecular.rgb * lightingSpecular.rgb;\n" 239 " float4 textureColor = baseTexture.Sample(baseSampler, input.vertexTCoord);\n" 241 " float3 color = lightingColor * textureColor.rgb;\n" 242 " output.pixelColor0.rgb = materialEmissive.rgb + lightingAttenuation.w * color;\n" 243 " output.pixelColor0.a = materialDiffuse.a * textureColor.a;\n" static std::string const msGLSLPSSource
virtual void UpdateMaterialConstant()
std::shared_ptr< Material > mMaterial
Vector4< float > cameraModelPosition
std::shared_ptr< LightCameraGeometry > mGeometry
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
virtual void UpdateLightingConstant()
Vector4< float > emissive
std::shared_ptr< ConstantBuffer > mGeometryConstant
Vector4< float > specular
std::shared_ptr< Lighting > mLighting
virtual void UpdateGeometryConstant()
virtual void UpdateLightingConstant()
GLsizei const GLchar *const * string
std::shared_ptr< ConstantBuffer > mLightingConstant
static std::string GetShaderSourceLitFunctionGLSL()
std::shared_ptr< SamplerState > mSampler
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Vector4< float > attenuation
virtual void UpdateGeometryConstant()
std::shared_ptr< ConstantBuffer > mMaterialConstant
static std::string const * msVSSource[ProgramFactory::PF_NUM_API]
Vector4< float > specular
static std::string const msGLSLVSSource
static std::string const * msPSSource[ProgramFactory::PF_NUM_API]
std::shared_ptr< Texture2 > mTexture
Vector4< float > lightModelDirection
static std::string const msHLSLSource
std::shared_ptr< VisualProgram > mProgram
virtual void UpdateMaterialConstant()
DirectionalLightTextureEffect(std::shared_ptr< ProgramFactory > const &factory, BufferUpdater const &updater, std::shared_ptr< Material > const &material, std::shared_ptr< Lighting > const &lighting, std::shared_ptr< LightCameraGeometry > const &geometry, std::shared_ptr< Texture2 > const &texture, SamplerState::Filter filter, SamplerState::Mode mode0, SamplerState::Mode mode1)