| 344 | } |
| 345 | |
| 346 | void SetProgramConstant(dmRender::HRenderContext render_context, dmGraphics::HContext graphics_context, const dmVMath::Matrix4& world_matrix, const dmVMath::Matrix4& texture_matrix, dmRenderDDF::MaterialDesc::ConstantType type, dmGraphics::HUniformLocation location, HConstant constant) |
| 347 | { |
| 348 | switch (type) |
| 349 | { |
| 350 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_USER: |
| 351 | { |
| 352 | uint32_t num_values; |
| 353 | dmVMath::Vector4* values = GetConstantValues(constant, &num_values); |
| 354 | dmGraphics::SetConstantV4(graphics_context, values, num_values, location); |
| 355 | break; |
| 356 | } |
| 357 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_USER_MATRIX4: |
| 358 | { |
| 359 | uint32_t num_values; |
| 360 | dmVMath::Vector4* values = GetConstantValues(constant, &num_values); |
| 361 | dmGraphics::SetConstantM4(graphics_context, values, num_values / 4, location); |
| 362 | break; |
| 363 | } |
| 364 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_VIEWPROJ: |
| 365 | { |
| 366 | const Matrix4 view_projection = GetViewProjectionMatrixForProgram(render_context); |
| 367 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&view_projection, 1, location); |
| 368 | break; |
| 369 | } |
| 370 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_WORLD: |
| 371 | { |
| 372 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&world_matrix, 1, location); |
| 373 | break; |
| 374 | } |
| 375 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_TEXTURE: |
| 376 | { |
| 377 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&texture_matrix, 1, location); |
| 378 | break; |
| 379 | } |
| 380 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_VIEW: |
| 381 | { |
| 382 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&render_context->m_View, 1, location); |
| 383 | break; |
| 384 | } |
| 385 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_PROJECTION: |
| 386 | { |
| 387 | const Matrix4 projection = GetProjectionMatrixForProgram(render_context); |
| 388 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&projection, 1, location); |
| 389 | break; |
| 390 | } |
| 391 | case dmRenderDDF::MaterialDesc::CONSTANT_TYPE_NORMAL: |
| 392 | { |
| 393 | { |
| 394 | // normalT = transp(inv(view * world)) |
| 395 | Matrix4 normalT = render_context->m_View * world_matrix; |
| 396 | // The world transform might include non-uniform scaling, which breaks the orthogonality of the combined model-view transform |
| 397 | // It is always affine however |
| 398 | normalT = affineInverse(normalT); |
| 399 | normalT = transpose(normalT); |
| 400 | dmGraphics::SetConstantM4(graphics_context, (Vector4*)&normalT, 1, location); |
| 401 | } |
| 402 | break; |
| 403 | } |