-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# This file is part of Magnum. | ||
# | ||
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015 | ||
# Vladimír Vondruš <[email protected]> | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the "Software"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
cmake_minimum_required(VERSION 2.8.9) | ||
project(MagnumPickingExample) | ||
|
||
find_package(Magnum REQUIRED | ||
MeshTools | ||
Primitives | ||
SceneGraph | ||
Sdl2Application) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}") | ||
include_directories(${MAGNUM_INCLUDE_DIRS} ${MAGNUM_APPLICATION_INCLUDE_DIRS}) | ||
|
||
corrade_add_resource(PickingData resources.conf) | ||
|
||
add_executable(magnum-picking | ||
PickingExample.cpp | ||
${PickingData}) | ||
target_link_libraries(magnum-picking | ||
${MAGNUM_LIBRARIES} | ||
${MAGNUM_MESHTOOLS_LIBRARIES} | ||
${MAGNUM_PRIMITIVES_LIBRARIES} | ||
${MAGNUM_SCENEGRAPH_LIBRARIES} | ||
${MAGNUM_APPLICATION_LIBRARIES}) | ||
|
||
install(TARGETS magnum-picking DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) | ||
install(FILES README.md DESTINATION ${MAGNUM_DATA_INSTALL_DIR}/examples RENAME README-picking.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
This file is part of Magnum. | ||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 | ||
Vladimír Vondruš <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
uniform lowp vec3 ambientColor; | ||
uniform lowp vec3 color; | ||
uniform lowp int objectId; | ||
|
||
in mediump vec3 transformedNormal; | ||
in highp vec3 lightDirection; | ||
in highp vec3 cameraDirection; | ||
|
||
layout(location = 0) out lowp vec4 fragmentColor; | ||
layout(location = 1) out lowp int fragmentObjectId; | ||
|
||
void main() { | ||
mediump vec3 normalizedTransformedNormal = normalize(transformedNormal); | ||
highp vec3 normalizedLightDirection = normalize(lightDirection); | ||
|
||
/* Add ambient color */ | ||
fragmentColor.rgb = ambientColor; | ||
|
||
/* Add diffuse color */ | ||
lowp float intensity = max(0.0, dot(normalizedTransformedNormal, normalizedLightDirection)); | ||
fragmentColor.rgb += color*intensity; | ||
|
||
/* Add specular color, if needed */ | ||
if(intensity > 0.001) { | ||
highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal); | ||
mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), 80.0); | ||
fragmentColor.rgb += vec3(1.0)*specularity; | ||
} | ||
|
||
/* Force alpha to 1 */ | ||
fragmentColor.a = 1.0; | ||
fragmentObjectId = objectId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
This file is part of Magnum. | ||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 | ||
Vladimír Vondruš <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
uniform highp mat4 transformationMatrix; | ||
uniform highp mat4 projectionMatrix; | ||
uniform mediump mat3 normalMatrix; | ||
uniform highp vec3 light; | ||
|
||
layout(location = 0) in highp vec4 position; | ||
layout(location = 1) in mediump vec3 normal; | ||
|
||
out mediump vec3 transformedNormal; | ||
out highp vec3 lightDirection; | ||
out highp vec3 cameraDirection; | ||
|
||
void main() { | ||
/* Transformed vertex position */ | ||
highp vec4 transformedPosition4 = transformationMatrix*position; | ||
highp vec3 transformedPosition = transformedPosition4.xyz/transformedPosition4.w; | ||
|
||
/* Transformed normal vector */ | ||
transformedNormal = normalMatrix*normal; | ||
|
||
/* Direction to the light */ | ||
lightDirection = normalize(light - transformedPosition); | ||
|
||
/* Direction to the camera */ | ||
cameraDirection = -transformedPosition; | ||
|
||
/* Transform the position */ | ||
gl_Position = projectionMatrix*transformedPosition4; | ||
} |
Oops, something went wrong.