├── .idea └── uiDesigner.xml ├── LICENSE ├── README.md ├── TutorialsComp.pdf ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── main │ ├── data │ ├── Colored.frag │ ├── Colored.vert │ ├── GenAxes.lua │ ├── GenCube.lua │ ├── GenPlane.lua │ ├── GenSphere.lua │ ├── Infinity.dae │ ├── Infinity.xml │ ├── UnitAxes.xml │ ├── UnitCube.xml │ ├── UnitPlane.xml │ ├── UnitSphere.xml │ ├── Unlit.frag │ ├── Unlit.vert │ ├── concrete649_small.dds │ ├── dsc_1621_small.dds │ ├── rough645_small.dds │ ├── seamless_rock1_small.dds │ └── wood4_rotate.dds │ ├── framework │ ├── Framework.java │ ├── Semantic.java │ └── component │ │ ├── Attribute.java │ │ ├── AttributeType.java │ │ ├── Mesh.java │ │ ├── Pair.java │ │ ├── PrimitiveType.java │ │ ├── RenderCmd.java │ │ └── VAO.java │ ├── tut01 │ └── HelloTriangle.java │ ├── tut02 │ ├── FragPosition.java │ └── VertexColor.java │ ├── tut03 │ ├── CpuPositionOffset.java │ ├── FragChangeColor.java │ ├── VertCalcOffset.java │ └── VertPositionOffset.java │ ├── tut04 │ ├── AspectRatio.java │ ├── MatrixPerspective.java │ ├── OrthoCube.java │ └── ShaderPerspective.java │ ├── tut05 │ ├── BaseVertexOverlap.java │ ├── DepthBuffer.java │ ├── DepthClamping.java │ ├── DepthFighting.java │ ├── OverlapNoDepth.java │ └── VertexClipping.java │ ├── tut06 │ ├── Hierarchy.java │ ├── Rotations.java │ ├── Scale.java │ └── Translation.java │ ├── tut07 │ ├── WorldScene.java │ └── WorldWithUBO.java │ ├── tut08 │ ├── CameraRelative.java │ ├── GimbalLock.java │ ├── Interpolation.java │ └── QuaternionYPR.java │ ├── tut09 │ ├── AmbientLighting.java │ ├── BasicLighting.java │ └── ScaleAndLighting.java │ ├── tut10 │ ├── FragmentAttenuation.java │ ├── FragmentPointLighting.java │ └── VertexPointLighting.java │ ├── tut11 │ ├── BlinnVsPhongLighting.java │ ├── GaussianSpecularLighting.java │ └── PhongLighting.java │ ├── tut12 │ └── sceneLighting │ │ ├── Light.java │ │ ├── LightInterpolator.java │ │ ├── LightManager.java │ │ ├── ProgramData.java │ │ ├── Scene.java │ │ ├── SceneLighting.java │ │ ├── UnlitProgData.java │ │ └── shaders │ │ ├── diffuse-only-mtl.frag │ │ ├── diffuse-only.frag │ │ ├── diffuse-specular-mtl.frag │ │ ├── diffuse-specular.frag │ │ ├── pcn.vert │ │ └── pn.vert │ ├── tut13 │ ├── BasicImpostor.java │ └── GeomImpostor.java │ ├── tut14 │ ├── BasicTexture.java │ ├── MaterialTexture.java │ └── PerspectiveInterpolation.java │ ├── tut15 │ └── ManyImages.java │ └── tut16 │ ├── GammaCheckers.java │ └── GammaRamp.java ├── kotlin ├── glNext │ ├── buffer.kt │ ├── depth.kt │ ├── faceCull.kt │ ├── glf.kt │ ├── misc.kt │ ├── program.kt │ ├── sampler.kt │ ├── shader.kt │ ├── test.kt │ ├── texture.kt │ ├── tut01 │ │ └── helloTriangle.kt │ ├── tut02 │ │ ├── fragPosition.kt │ │ └── vertexColor.kt │ ├── tut03 │ │ ├── cpuPositionOffset.kt │ │ ├── fragChangeColor.kt │ │ ├── vertCalcOffset.kt │ │ └── vertPositionOffset.kt │ ├── tut04 │ │ ├── aspectRatio.kt │ │ ├── matrixPerspective.kt │ │ ├── orthoCube.kt │ │ └── shaderPerspective.kt │ ├── tut05 │ │ ├── baseVertexOverlap.kt │ │ ├── depthBuffer.kt │ │ ├── depthClamping.kt │ │ ├── overlapNoDepth.kt │ │ └── vertexClipping.kt │ ├── tut06 │ │ ├── hierarchy.kt │ │ ├── rotations.kt │ │ └── scale.kt │ ├── tut07 │ │ ├── worldScene.kt │ │ └── worldWithUBO.kt │ ├── tut08 │ │ ├── cameraRelative.kt │ │ ├── gimbalLock.kt │ │ ├── interpolation.kt │ │ └── quaternionYPR.kt │ ├── tut09 │ │ ├── ambientLighting.kt │ │ ├── basicLighting.kt │ │ └── scaleAndLighting.kt │ ├── tut10 │ │ ├── fragAttenuation.kt │ │ ├── fragmentPointLighting.kt │ │ └── vertexPointLighting.kt │ ├── tut11 │ │ ├── blinnVsPhongLighting.kt │ │ ├── gaussianSpecularLighting.kt │ │ └── phongLighting.kt │ ├── tut13 │ │ ├── basicImpostor.kt │ │ └── geomImpostor.kt │ ├── tut14 │ │ ├── basicTexture.kt │ │ ├── materialTexture.kt │ │ └── perspectiveInterpolation.kt │ ├── tut15 │ │ └── manyImages.kt │ ├── tut16 │ │ ├── gammaCheckers.kt │ │ └── gammaRamp.kt │ └── vertexArray.kt └── main │ ├── tut01 │ └── helloTriangle.kt │ ├── tut02 │ ├── fragPosition.kt │ └── vertexColor.kt │ ├── tut03 │ ├── cpuPositionOffset.kt │ ├── fragChangeColor.kt │ ├── vertCalcOffset.kt │ └── vertPositionOffset.kt │ ├── tut04 │ ├── aspectRatio.kt │ ├── matrixPerspective.kt │ ├── orthoCube.kt │ └── shaderPerspective.kt │ ├── tut05 │ ├── baseVertexOverlap.kt │ ├── depthBuffer.kt │ ├── depthClamping.kt │ ├── overlapNoDepth.kt │ └── vertexClipping.kt │ ├── tut06 │ ├── hierarchy.kt │ ├── rotations.kt │ ├── scale.kt │ └── translation.kt │ ├── tut07 │ ├── worldScene.kt │ └── worldWithUBO.kt │ ├── tut08 │ ├── cameraRelative.kt │ ├── gimbalLock.kt │ ├── interpolation.kt │ └── quaternionYPR.kt │ ├── tut09 │ ├── ambientLighting.kt │ ├── basicLighting.kt │ └── scaleAndLighting.kt │ ├── tut10 │ ├── fragAttenuation.kt │ ├── fragmentPointLighting.kt │ └── vertexPointLighting.kt │ ├── tut11 │ ├── blinnVsPhongLighting.kt │ ├── gaussianSpecularLighting.kt │ └── phongLighting.kt │ ├── tut13 │ ├── basicImpostor.kt │ └── geomImpostor.kt │ ├── tut14 │ ├── basicTexture.kt │ ├── materialTexture.kt │ └── perspectiveInterpolation.kt │ ├── tut15 │ └── manyImages.kt │ └── tut16 │ ├── gammaCheckers.kt │ └── gammaRamp.kt └── resources ├── screenshots └── jogl.png ├── tut01 ├── semantic.glsl ├── shader.frag └── shader.vert ├── tut02 ├── frag-position.frag ├── frag-position.vert ├── semantic.glsl ├── vertex-colors.frag └── vertex-colors.vert ├── tut03 ├── calc-color.frag ├── calc-offset.vert ├── position-offset.vert ├── semantic.glsl ├── standard.frag └── standard.vert ├── tut04 ├── manual-perspective.vert ├── matrix-perspective.vert ├── ortho-with-offset.vert ├── semantic.glsl └── standard-colors.frag ├── tut05 ├── semantic.glsl ├── standard.frag └── standard.vert ├── tut06 ├── color-passthrough.frag ├── pos-color-local-transform.vert └── semantic.glsl ├── tut07 ├── UnitConeTint.xml ├── UnitCubeColor.xml ├── UnitCubeTint.xml ├── UnitCylinderTint.xml ├── UnitPlane.xml ├── color-mult-uniform.frag ├── color-passthrough.frag ├── color-uniform.frag ├── pos-color-world-transform-ubo.vert ├── pos-color-world-transform.vert ├── pos-only-world-transform-ubo.vert ├── pos-only-world-transform.vert └── semantic.glsl ├── tut08 ├── LargeGimbal.xml ├── MediumGimbal.xml ├── Ship.xml ├── SmallGimbal.xml ├── UnitPlane.xml ├── color-mult-uniform.frag ├── pos-color-local-transform.vert └── semantic.glsl ├── tut09 ├── LargePlane.xml ├── UnitCylinder.xml ├── color-passthrough.frag ├── dir-amb-vertex-lighting-PCN.vert ├── dir-amb-vertex-lighting-PN.vert ├── dir-vertex-lighting-PCN.vert ├── dir-vertex-lighting-PN.vert └── semantic.glsl ├── tut10 ├── LargePlane.xml ├── UnitCube.xml ├── UnitCylinder.xml ├── UnitPlane.xml ├── color-passthrough.frag ├── frag-light-atten-PCN.vert ├── frag-light-atten-PN.vert ├── frag-light-atten.frag ├── fragment-lighting-PCN.vert ├── fragment-lighting-PN.vert ├── fragment-lighting.frag ├── model-pos-vertex-lighting-PCN.vert ├── model-pos-vertex-lighting-PN.vert ├── pos-transform.vert ├── pos-vertex-lighting-PCN.vert ├── pos-vertex-lighting-PN.vert ├── semantic.glsl └── uniform-color.frag ├── tut11 ├── LargePlane.xml ├── UnitCube.xml ├── UnitCylinder.xml ├── UnitPlane.xml ├── blinn-lighting.frag ├── blinn-only.frag ├── gaussian-lighting.frag ├── gaussian-only.frag ├── no-phong.frag ├── pcn.vert ├── phong-lighting.frag ├── phong-only.frag ├── pn.vert ├── pos-transform.vert ├── semantic.glsl └── uniform-color.frag ├── tut13 ├── LargePlane.xml ├── UnitCube.xml ├── UnitPlane.xml ├── UnitSphere.xml ├── basic-impostor.frag ├── basic-impostor.vert ├── depth-impostor.frag ├── depth-impostor.vert ├── geom-impostor.frag ├── geom-impostor.geom ├── geom-impostor.vert ├── lighting.frag ├── persp-impostor.frag ├── persp-impostor.vert ├── pn.vert ├── semantic.glsl ├── unlit.frag └── unlit.vert ├── tut14 ├── FauxHallway.xml ├── Infinity.xml ├── RealHallway.xml ├── UnitCube.xml ├── UnitPlane.xml ├── fixed-shininess.frag ├── main.dds ├── no-correct-vertex-colors.frag ├── no-correct-vertex-colors.vert ├── pn.vert ├── pnt.vert ├── semantic.glsl ├── shader-gaussian.frag ├── smooth-vertex-colors.frag ├── smooth-vertex-colors.vert ├── texture-compute.frag ├── texture-gaussian.frag ├── texture-shininess.frag ├── unlit.frag └── unlit.vert ├── tut15 ├── BigPlane.xml ├── Corridor.xml ├── checker.dds ├── pt.vert ├── semantic.glsl └── tex.frag └── tut16 ├── BigPlane.xml ├── Corridor.xml ├── checker_gamma.dds ├── checker_linear.dds ├── gamma_ramp.png ├── pt.vert ├── screen-coords.vert ├── semantic.glsl ├── texture-gamma.frag └── texture-no-gamma.frag /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 elect86 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | modern-jogl-examples 2 | ==================== 3 | 4 | This porting is free but needs your support to sustain its development. There are lots of desirable new features and maintenance to do. If you are an individual using dear imgui, please consider donating via Patreon or PayPal. If your company is using dear imgui, please consider financial support (e.g. sponsoring a few weeks/months of development) 5 | 6 | Monthly donations via Patreon: 7 |
[![Patreon](https://cloud.githubusercontent.com/assets/8225057/5990484/70413560-a9ab-11e4-8942-1a63607c0b00.png)](https://www.patreon.com/user?u=7285753) 8 | 9 | One-off donations via PayPal: 10 |
[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KBKVJBQ3NNH8E) 11 | 12 | 13 | 14 | Examples ported in JOGL from the tutorials "Learning Modern 3D Graphic Programming" by J.L.McKesson, (original bitbucket [repository](https://bitbucket.org/alfonse/gltut/overview)). 15 | 16 | The original website (http://www.arcsynthesis.org/gltut) is down because probably the domain [expired](https://bitbucket.org/alfonse/gltut/issues/127/arcsynthesisorg-web-site). Pavel Rojtberg is continuing the manteinance of the tutorial [here](https://github.com/paroj/gltut). 17 | 18 | He is also supporting the html form of the documentation [here](https://paroj.github.io/gltut/), I strongly suggest you to read and refer it during the learning of each tutorial sample. 19 | 20 | You can find the examples in java under [`src/main/java`](https://github.com/java-opengl-labs/modern-jogl-examples/tree/master/src/main/java/main) and the corresponding in kotlin under [`src/main/kotlin`](https://github.com/java-opengl-labs/modern-jogl-examples/tree/master/src/main/kotlin/main) 21 | 22 | Few comments on Kotlin: 23 | 24 | - it's awesome 25 | - [`src/main/kotlin/main`](https://github.com/java-opengl-labs/modern-jogl-examples/tree/master/src/main/kotlin/main) is an example, showing also how you can exploit some overloading gl functions to reduce the boiler plate arguments 26 | - [`src/main/kotlin/glNext`](https://github.com/java-opengl-labs/modern-jogl-examples/tree/master/src/main/kotlin/glNext) pushes reduction and expressiveness to the top, substituting many gl commands with constructs that rearrange some common gl patterns to bring *a lot* of code down 27 | 28 | Status: 29 | 30 | - [x] Chapter 1, Hello Triangle 31 | - [x] Chapter 2, Playing with Colors 32 | - [x] Chapter 3, Moving Triangle 33 | - [x] Chapter 4, Objects at Rest 34 | - [x] Chapter 5, Objects at Depth 35 | - [x] Chapter 6, Objects in Motion 36 | - [x] Chapter 7, World in Motion 37 | - [x] Chapter 8, Getting Oriented 38 | - [x] Chapter 9, Lights On 39 | - [x] Chapter 10, Plane Lights 40 | - [x] Chapter 11, Shinies 41 | - [ ] Chapter 12, Dynamic Lights 42 | - [x] Chapter 13, Lies and Impostors 43 | - [x] Chapter 14, Textures are not Pictures 44 | - [x] Chapter 15, Many Images 45 | - [ ] Chapter 16, Gamma and Textures: 46 | - [x] Gamma Ramp 47 | - [x] Gamma Checkers 48 | - [ ] Gamma Landscape 49 | - [ ] Chapter 17, Spotlight on Textures 50 | -------------------------------------------------------------------------------- /TutorialsComp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/TutorialsComp.pdf -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'kotlin' 3 | 4 | 5 | 6 | buildscript { 7 | 8 | ext.kotlin_version = '1.2-M1' 9 | 10 | repositories { 11 | mavenCentral() 12 | maven { url "https://dl.bintray.com/kotlin/kotlin-dev" } 13 | } 14 | 15 | dependencies { 16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 17 | } 18 | } 19 | 20 | 21 | dependencies { 22 | 23 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 24 | 25 | compile 'com.github.kotlin-graphics:uno-sdk:c80ea0425a2913ecc2006d0fd475d7714028883c' 26 | 27 | def jogl = '2.3.2' 28 | 29 | compile "org.jogamp.gluegen:gluegen-rt-main:$jogl" 30 | compile "org.jogamp.jogl:jogl-all-main:$jogl" 31 | } 32 | 33 | repositories { 34 | mavenCentral() 35 | maven { url 'https://jitpack.io' } 36 | maven { url "https://dl.bintray.com/kotlin/kotlin-dev" } 37 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 07 21:38:00 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.buildFileName = 'build.gradle' 2 | -------------------------------------------------------------------------------- /src/main/java/main/data/Colored.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | smooth in vec4 objectColor; 4 | 5 | out vec4 outputColor; 6 | 7 | void main() 8 | { 9 | outputColor = objectColor; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/main/data/Colored.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout(std140) uniform; 4 | 5 | layout(location = 0) in vec3 position; 6 | layout(location = 1) in vec4 color; 7 | 8 | smooth out vec4 objectColor; 9 | 10 | uniform Projection 11 | { 12 | mat4 cameraToClipMatrix; 13 | }; 14 | 15 | uniform mat4 modelToCameraMatrix; 16 | 17 | void main() 18 | { 19 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 20 | objectColor = color; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/main/data/GenAxes.lua: -------------------------------------------------------------------------------- 1 | require "XmlWriter" 2 | require "vmath" 3 | 4 | local function GenStringFromArray(theArray, bAsInt) 5 | local array = {" "} 6 | for i, vector in ipairs(theArray) do 7 | local elements = vector; 8 | if(bAsInt) then 9 | elements = {}; 10 | for i, value in ipairs(vector) do 11 | elements[#elements + 1] = string.format("%i", value); 12 | end 13 | end 14 | 15 | array[#array + 1] = " " .. table.concat(vector, " "); 16 | end 17 | 18 | return table.concat(array, "\n"); 19 | end 20 | 21 | local positions = 22 | { 23 | vmath.vec3(0.0, 0.0, 0.0), 24 | vmath.vec3(0.5, 0.0, 0.0), 25 | 26 | vmath.vec3(0.0, 0.0, 0.0), 27 | vmath.vec3(0.0, 0.5, 0.0), 28 | 29 | vmath.vec3(0.0, 0.0, 0.0), 30 | vmath.vec3(0.0, 0.0, 0.5), 31 | }; 32 | 33 | local colors = 34 | { 35 | vmath.vec4(1.0, 0.0, 0.0, 1.0), 36 | vmath.vec4(1.0, 0.0, 0.0, 1.0), 37 | 38 | vmath.vec4(0.0, 1.0, 0.0, 1.0), 39 | vmath.vec4(0.0, 1.0, 0.0, 1.0), 40 | 41 | vmath.vec4(0.0, 0.0, 1.0, 1.0), 42 | vmath.vec4(0.0, 0.0, 1.0, 1.0), 43 | }; 44 | 45 | do 46 | local writer = XmlWriter.XmlWriter("UnitAxes.xml"); 47 | writer:AddPI("oxygen", [[RNGSchema="../Documents/meshFormat.rnc" type="compact"]]); 48 | writer:PushElement("mesh", "http://www.arcsynthesis.com/gltut/mesh"); 49 | writer:PushElement("attribute"); 50 | writer:AddAttribute("index", "0"); 51 | writer:AddAttribute("type", "float"); 52 | writer:AddAttribute("size", "3"); 53 | writer:AddText(GenStringFromArray(positions)); 54 | writer:PopElement(); 55 | writer:PushElement("attribute"); 56 | writer:AddAttribute("index", "1"); 57 | writer:AddAttribute("type", "float"); 58 | writer:AddAttribute("size", "4"); 59 | writer:AddText(GenStringFromArray(colors)); 60 | writer:PopElement(); 61 | writer:PushElement("arrays"); 62 | writer:AddAttribute("cmd", "lines"); 63 | writer:AddAttribute("start", "0"); 64 | writer:AddAttribute("count", "6"); 65 | writer:PopElement(); 66 | writer:PopElement(); 67 | writer:Close(); 68 | end 69 | 70 | -------------------------------------------------------------------------------- /src/main/java/main/data/UnitAxes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0 0 0 7 | 0.5 0 0 8 | 0 0 0 9 | 0 0.5 0 10 | 0 0 0 11 | 0 0 0.5 12 | 13 | 1 0 0 1 14 | 1 0 0 1 15 | 0 1 0 1 16 | 0 1 0 1 17 | 0 0 1 1 18 | 0 0 1 1 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/main/data/UnitCube.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 0.25 1 0.25 1 32 | 0.25 1 0.25 1 33 | 0.25 1 0.25 1 34 | 0.25 1 0.25 1 35 | 0.5 0.5 1 1 36 | 0.5 0.5 1 1 37 | 0.5 0.5 1 1 38 | 0.5 0.5 1 1 39 | 1 0.5 0.5 1 40 | 1 0.5 0.5 1 41 | 1 0.5 0.5 1 42 | 1 0.5 0.5 1 43 | 1 1 0.5 1 44 | 1 1 0.5 1 45 | 1 1 0.5 1 46 | 1 1 0.5 1 47 | 0.5 1 1 1 48 | 0.5 1 1 1 49 | 0.5 1 1 1 50 | 0.5 1 1 1 51 | 1 0.5 1 1 52 | 1 0.5 1 1 53 | 1 0.5 1 1 54 | 1 0.5 1 1 55 | 56 | 0 0 1 57 | 0 0 1 58 | 0 0 1 59 | 0 0 1 60 | 0 1 0 61 | 0 1 0 62 | 0 1 0 63 | 0 1 0 64 | 1 0 0 65 | 1 0 0 66 | 1 0 0 67 | 1 0 0 68 | 0 0 -1 69 | 0 0 -1 70 | 0 0 -1 71 | 0 0 -1 72 | 0 -1 0 73 | 0 -1 0 74 | 0 -1 0 75 | 0 -1 0 76 | -1 0 0 77 | -1 0 0 78 | -1 0 0 79 | -1 0 0 80 | 81 | 1 1 82 | 1 0 83 | 0 0 84 | 0 1 85 | 1 1 86 | 1 0 87 | 0 0 88 | 0 1 89 | 0 1 90 | 1 1 91 | 1 0 92 | 0 0 93 | 0 1 94 | 1 1 95 | 1 0 96 | 0 0 97 | 1 1 98 | 1 0 99 | 0 0 100 | 0 1 101 | 1 1 102 | 1 0 103 | 0 0 104 | 0 1 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 0 1 2 143 | 2 3 0 144 | 4 5 6 145 | 6 7 4 146 | 8 9 10 147 | 10 11 8 148 | 12 13 14 149 | 14 15 12 150 | 16 17 18 151 | 18 19 16 152 | 20 21 22 153 | 22 23 20 154 | -------------------------------------------------------------------------------- /src/main/java/main/data/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 0.5 0 -0.5 11 | 0.5 0 0.5 12 | -0.5 0 0.5 13 | -0.5 0 -0.5 14 | 15 | 1 1 1 1 16 | 1 1 1 1 17 | 1 1 1 1 18 | 1 1 1 1 19 | 1 1 1 1 20 | 1 1 1 1 21 | 1 1 1 1 22 | 1 1 1 1 23 | 24 | 0 1 0 25 | 0 1 0 26 | 0 1 0 27 | 0 1 0 28 | 0 -1 0 29 | 0 -1 0 30 | 0 -1 0 31 | 0 -1 0 32 | 33 | 1 0 34 | 1 1 35 | 0 1 36 | 0 0 37 | 1 0 38 | 1 1 39 | 0 1 40 | 0 0 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 0 1 2 70 | 2 3 0 71 | 4 6 5 72 | 6 4 7 73 | -------------------------------------------------------------------------------- /src/main/java/main/data/Unlit.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform vec4 objectColor; 4 | 5 | out vec4 outputColor; 6 | 7 | void main() 8 | { 9 | outputColor = objectColor; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/main/data/Unlit.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout(std140) uniform; 4 | 5 | layout(location = 0) in vec3 position; 6 | 7 | uniform Projection 8 | { 9 | mat4 cameraToClipMatrix; 10 | }; 11 | 12 | uniform mat4 modelToCameraMatrix; 13 | 14 | void main() 15 | { 16 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/main/data/concrete649_small.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/java/main/data/concrete649_small.dds -------------------------------------------------------------------------------- /src/main/java/main/data/dsc_1621_small.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/java/main/data/dsc_1621_small.dds -------------------------------------------------------------------------------- /src/main/java/main/data/rough645_small.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/java/main/data/rough645_small.dds -------------------------------------------------------------------------------- /src/main/java/main/data/seamless_rock1_small.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/java/main/data/seamless_rock1_small.dds -------------------------------------------------------------------------------- /src/main/java/main/data/wood4_rotate.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/java/main/data/wood4_rotate.dds -------------------------------------------------------------------------------- /src/main/java/main/framework/Semantic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.framework; 7 | 8 | /** 9 | * 10 | * @author gbarbieri 11 | */ 12 | public class Semantic { 13 | 14 | public static class Attr { 15 | 16 | public static final int POSITION = 0; 17 | public static final int NORMAL = 2; 18 | public static final int COLOR = 1; 19 | public static final int TEX_COORD = 5; 20 | public static final int CAMERA_SPHERE_POS = 6; 21 | public static final int SPHERE_RADIUS = 7; 22 | } 23 | 24 | public static class Buffer { 25 | 26 | public static final int STATIC = 0; 27 | public static final int DYNAMIC = 1; 28 | } 29 | 30 | public static class Frag { 31 | 32 | public static final int COLOR = 0; 33 | public static final int RED = 0; 34 | public static final int GREEN = 1; 35 | public static final int BLUE = 2; 36 | public static final int ALPHA = 0; 37 | } 38 | 39 | public static class Image { 40 | 41 | public static final int DIFFUSE = 0; 42 | public static final int PICKING = 1; 43 | } 44 | 45 | public static class Object { 46 | 47 | public static final int VAO = 0; 48 | public static final int VBO = 1; 49 | public static final int IBO = 2; 50 | public static final int TEXTURE = 3; 51 | public static final int SAMPLER = 4; 52 | public static final int SIZE = 5; 53 | } 54 | 55 | public static class Renderbuffer { 56 | 57 | public static final int DEPTH = 0; 58 | public static final int COLOR0 = 1; 59 | } 60 | 61 | public static class Sampler { 62 | 63 | public static final int DIFFUSE = 0; 64 | public static final int POSITION = 4; 65 | public static final int TEXCOORD = 5; 66 | public static final int COLOR = 6; 67 | public static final int GAUSSIAN_TEXTURE = 7; 68 | public static final int SHININESS_TEXTURE = 8; 69 | } 70 | 71 | public static class Storage { 72 | 73 | public static final int VERTEX = 0; 74 | } 75 | 76 | public static class Uniform { 77 | 78 | public static final int GLOBAL_MATRICES = 0; 79 | public static final int PROJECTION = 1; 80 | public static final int UNPROJECTION = 2; 81 | public static final int MATERIAL = 3; 82 | public static final int LIGHT = 4; 83 | 84 | public static final int TRANSFORM0 = 1; 85 | public static final int TRANSFORM1 = 2; 86 | public static final int INDIRECTION = 3; 87 | public static final int CONSTANT = 0; 88 | public static final int PER_FRAME = 1; 89 | public static final int PER_PASS = 2; 90 | } 91 | 92 | public static class Vert { 93 | 94 | public static final int POSITION = 0; 95 | public static final int COLOR = 3; 96 | public static final int TEXCOORD = 4; 97 | public static final int INSTANCE = 7; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/main/framework/component/AttributeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.framework.component; 7 | 8 | import com.jogamp.opengl.GL3; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | import static com.jogamp.opengl.GL.*; 13 | import static com.jogamp.opengl.GL2ES2.GL_INT; 14 | 15 | /** 16 | * 17 | * @author elect 18 | */ 19 | public class AttributeType { 20 | 21 | private final String nameFromFile; 22 | private final boolean normalized; 23 | private final int glType; 24 | private final int numBytes; 25 | 26 | private AttributeType(String nameFromFile, boolean normalized, int glType, int numBytes) { 27 | this.nameFromFile = nameFromFile; 28 | this.normalized = normalized; 29 | this.glType = glType; 30 | this.numBytes = numBytes; 31 | } 32 | 33 | public void writeToBuffer(GL3 gl, int buffer, ByteBuffer theData, int offset) { 34 | // System.out.println("glBufferData(" + (buffer == GL_ARRAY_BUFFER ? "GL_ARRAY_BUFFER" 35 | // : buffer == GL_ELEMENT_ARRAY_BUFFER ? "GL_ELEMENT_ARRAY_BUFFER" : buffer) 36 | // + ", " + offset + ", " + theData.capacity() + ")"); 37 | gl.glBufferSubData(buffer, offset, theData.capacity(), theData); 38 | } 39 | 40 | public static AttributeType get(String type) { 41 | for (AttributeType attributeType : allAttributeTypes) { 42 | if (type.equals(attributeType.nameFromFile)) { 43 | return attributeType; 44 | } 45 | } 46 | throw new Error("Unknown 'type' field (" + type + ")."); 47 | } 48 | 49 | private static final AttributeType[] allAttributeTypes = { 50 | new AttributeType("float", false, GL_FLOAT, Float.BYTES), 51 | new AttributeType("half", false, GL_HALF_FLOAT, Float.BYTES / 2), 52 | new AttributeType("int", false, GL_INT, Integer.BYTES), 53 | new AttributeType("uint", false, GL_UNSIGNED_INT, Integer.BYTES), 54 | new AttributeType("norm-int", true, GL_INT, Integer.BYTES), 55 | new AttributeType("norm-uint", true, GL_UNSIGNED_INT, Integer.BYTES), 56 | new AttributeType("short", false, GL_SHORT, Short.BYTES), 57 | new AttributeType("ushort", false, GL_UNSIGNED_SHORT, Short.BYTES), 58 | new AttributeType("norm-short", true, GL_SHORT, Short.BYTES), 59 | new AttributeType("norm-ushort", true, GL_UNSIGNED_SHORT, Short.BYTES), 60 | new AttributeType("byte", false, GL_BYTE, Byte.BYTES), 61 | new AttributeType("ubyte", false, GL_UNSIGNED_BYTE, Byte.BYTES), 62 | new AttributeType("norm-byte", true, GL_BYTE, Byte.BYTES), 63 | new AttributeType("norm-ubyte", true, GL_UNSIGNED_BYTE, Byte.BYTES)}; 64 | 65 | public boolean normalized() { 66 | return normalized; 67 | } 68 | 69 | public int glType() { 70 | return glType; 71 | } 72 | 73 | public int numBytes() { 74 | return numBytes; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/main/framework/component/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.framework.component; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * 13 | * @author GBarbieri 14 | */ 15 | public class Pair { 16 | 17 | private String name = ""; 18 | private List attributes = new ArrayList<>(); 19 | 20 | public String name() { 21 | return name; 22 | } 23 | 24 | public void name(String name) { 25 | this.name = name; 26 | } 27 | 28 | public List attributes() { 29 | return attributes; 30 | } 31 | 32 | public void attributes(ArrayList attributes) { 33 | this.attributes = attributes; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/main/framework/component/PrimitiveType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.framework.component; 7 | 8 | import static com.jogamp.opengl.GL.*; 9 | 10 | /** 11 | * 12 | * @author elect 13 | */ 14 | public class PrimitiveType { 15 | 16 | private String primitiveName; 17 | private int glPrimType; 18 | 19 | public PrimitiveType(String primitiveName, int glPrimType) { 20 | this.primitiveName = primitiveName; 21 | this.glPrimType = glPrimType; 22 | } 23 | 24 | public static PrimitiveType get(String type) { 25 | for (PrimitiveType primitiveType : allPrimitiveTypes) { 26 | if (type.equals(primitiveType.primitiveName)) { 27 | return primitiveType; 28 | } 29 | } 30 | throw new Error("Unknown 'cmd' field (" + type + ")."); 31 | } 32 | 33 | private static PrimitiveType[] allPrimitiveTypes = { 34 | new PrimitiveType("triangles", GL_TRIANGLES), 35 | new PrimitiveType("tri-strip", GL_TRIANGLE_STRIP), 36 | new PrimitiveType("tri-fan", GL_TRIANGLE_FAN), 37 | new PrimitiveType("lines", GL_LINES), 38 | new PrimitiveType("line-strip", GL_LINE_STRIP), 39 | new PrimitiveType("line-loop", GL_LINE_LOOP), 40 | new PrimitiveType("points", GL_POINTS)}; 41 | 42 | public int glPrimType() { 43 | return glPrimType; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/main/framework/component/VAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package main.framework.component; 6 | 7 | import org.w3c.dom.Element; 8 | import org.w3c.dom.Node; 9 | import org.w3c.dom.NodeList; 10 | 11 | /** 12 | * 13 | * @author gbarbieri 14 | */ 15 | public class VAO { 16 | 17 | public static void process(Element element, Pair pair) { 18 | 19 | pair.name(element.getAttribute("name")); 20 | 21 | NodeList children = element.getChildNodes(); 22 | 23 | if (children != null && children.getLength() > 0) { 24 | 25 | for (int i = 0; i < children.getLength(); i++) { 26 | 27 | Node childNode = children.item(i); 28 | 29 | if (childNode.getNodeType() == Node.ELEMENT_NODE) { 30 | 31 | Element childElement = (Element) childNode; 32 | 33 | int attrib = Integer.parseInt(childElement.getAttribute("attrib")); 34 | 35 | pair.attributes().add(attrib); 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/main/tut02/FragPosition.java: -------------------------------------------------------------------------------- 1 | 2 | package main.tut02; 3 | 4 | import com.jogamp.newt.event.KeyEvent; 5 | import com.jogamp.opengl.GL3; 6 | import com.jogamp.opengl.util.GLBuffers; 7 | import glm.vec._4.Vec4; 8 | import main.framework.Framework; 9 | import main.framework.Semantic; 10 | 11 | import java.nio.FloatBuffer; 12 | import java.nio.IntBuffer; 13 | 14 | import static com.jogamp.opengl.GL.*; 15 | import static com.jogamp.opengl.GL2ES3.GL_COLOR; 16 | import static uno.buffer.UtilKt.destroyBuffer; 17 | import static uno.buffer.UtilKt.destroyBuffers; 18 | import static uno.glsl.UtilKt.programOf; 19 | 20 | /** 21 | * @author gbarbieri 22 | */ 23 | public class FragPosition extends Framework { 24 | 25 | public static void main(String[] args) { 26 | new FragPosition().setup("Tutorial 02 - Fragment Position"); 27 | } 28 | 29 | private int theProgram; 30 | private IntBuffer vertexBufferObject = GLBuffers.newDirectIntBuffer(1), vao = GLBuffers.newDirectIntBuffer(1); 31 | private float[] vertexData = { 32 | +0.75f, +0.75f, 0.0f, 1.0f, 33 | +0.75f, -0.75f, 0.0f, 1.0f, 34 | -0.75f, -0.75f, 0.0f, 1.0f}; 35 | 36 | @Override 37 | public void init(GL3 gl) { 38 | 39 | initializeProgram(gl); 40 | initializeVertexBuffer(gl); 41 | 42 | gl.glGenVertexArrays(1, vao); 43 | gl.glBindVertexArray(vao.get(0)); 44 | } 45 | 46 | private void initializeProgram(GL3 gl) { 47 | theProgram = programOf(gl, getClass(), "tut02", "frag-position.vert", "frag-position.frag"); 48 | } 49 | 50 | private void initializeVertexBuffer(GL3 gl) { 51 | 52 | FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); 53 | 54 | gl.glGenBuffers(1, vertexBufferObject); 55 | 56 | gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject.get(0)); 57 | gl.glBufferData(GL_ARRAY_BUFFER, vertexBuffer.capacity() * Float.BYTES, vertexBuffer, GL_STATIC_DRAW); 58 | gl.glBindBuffer(GL_ARRAY_BUFFER, 0); 59 | 60 | destroyBuffer(vertexBuffer); 61 | } 62 | 63 | @Override 64 | public void display(GL3 gl) { 65 | 66 | gl.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0f).put(1, 0f).put(2, 0f).put(3, 1f)); 67 | 68 | gl.glUseProgram(theProgram); 69 | 70 | gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject.get(0)); 71 | gl.glEnableVertexAttribArray(Semantic.Attr.POSITION); 72 | gl.glVertexAttribPointer(Semantic.Attr.POSITION, Vec4.length, GL_FLOAT, false, Vec4.SIZE, 0); 73 | 74 | gl.glDrawArrays(GL_TRIANGLES, 0, 3); 75 | 76 | gl.glDisableVertexAttribArray(Semantic.Attr.POSITION); 77 | gl.glUseProgram(0); 78 | } 79 | 80 | @Override 81 | public void reshape(GL3 gl, int w, int h) { 82 | 83 | gl.glViewport(0, 0, w, h); 84 | } 85 | 86 | @Override 87 | protected void end(GL3 gl) { 88 | 89 | gl.glDeleteProgram(theProgram); 90 | gl.glDeleteBuffers(1, vertexBufferObject); 91 | gl.glDeleteVertexArrays(1, vao); 92 | 93 | destroyBuffers(vertexBufferObject, vao); 94 | } 95 | 96 | @Override 97 | public void keyPressed(KeyEvent keyEvent) { 98 | 99 | switch (keyEvent.getKeyCode()) { 100 | case KeyEvent.VK_ESCAPE: 101 | quit(); 102 | break; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/Light.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * To change this license header, choose License Headers in Project Properties. 3 | // * To change this template file, choose Tools | Templates 4 | // * and open the template in the editor. 5 | // */ 6 | //package main.tut12.sceneLighting; 7 | // 8 | //import glm.vec._4.Vec4; 9 | // 10 | ///** 11 | // * 12 | // * @author elect 13 | // */ 14 | //class Light { 15 | // 16 | // class SunlightValue { 17 | // 18 | // public float normTime; 19 | // public Vec4 ambient; 20 | // public Vec4 sunlightIntensity; 21 | // public Vec4 backgroundColor; 22 | // } 23 | // 24 | //} 25 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/LightInterpolator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.tut12.sceneLighting; 7 | 8 | 9 | /** 10 | * 11 | * @author elect 12 | */ 13 | public class LightInterpolator { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/LightManager.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * To change this license header, choose License Headers in Project Properties. 3 | // * To change this template file, choose Tools | Templates 4 | // * and open the template in the editor. 5 | // */ 6 | //package main.tut12.sceneLighting; 7 | // 8 | //import glutil.Timer; 9 | //import glutil.interpolator.LightVectorData; 10 | //import glutil.interpolator.TimedLinearInterpolator; 11 | //import java.util.ArrayList; 12 | //import java.util.List; 13 | // 14 | ///** 15 | // * 16 | // * @author elect 17 | // */ 18 | //class LightManager { 19 | // 20 | // private final int NUMBER_OF_LIGHTS = 4; 21 | // private final int NUMBER_OF_POINT_LIGHTS = NUMBER_OF_LIGHTS - 1; 22 | // 23 | // private Timer sunTimer = new Timer(Timer.Type.LOOP, 30.0f); 24 | // private TimedLinearInterpolator ambientInterpolator = new TimedLinearInterpolator<>(); 25 | // private TimedLinearInterpolator backgroundInterpolator = new TimedLinearInterpolator<>(); 26 | // private TimedLinearInterpolator sunlightInterpolator = new TimedLinearInterpolator<>(); 27 | // private TimedLinearInterpolator maxIntensityInterpolator = new TimedLinearInterpolator<>(); 28 | // 29 | // private List lightTimers = new ArrayList<>(); 30 | // 31 | // public LightManager() { 32 | // 33 | // 34 | // } 35 | // 36 | // 37 | // 38 | // public void setSunlightValues(List values) { 39 | // 40 | // List ambient = new ArrayList<>(); 41 | // List light = new ArrayList<>(); 42 | // List background = new ArrayList<>(); 43 | // 44 | // values.forEach(value -> { 45 | // ambient.add(new LightVectorData(value.ambient, value.normTime)); 46 | // light.add(new LightVectorData(value.sunlightIntensity, value.normTime)); 47 | // background.add(new LightVectorData(value.backgroundColor, value.normTime)); 48 | // }); 49 | // 50 | // ambientInterpolator.SetValues(ambient); 51 | // sunlightInterpolator.SetValues(light); 52 | // backgroundInterpolator.SetValues(background); 53 | // 54 | // } 55 | //} 56 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/ProgramData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package main.tut12.sceneLighting; 7 | 8 | import com.jogamp.opengl.GL3; 9 | import com.jogamp.opengl.util.glsl.ShaderCode; 10 | import com.jogamp.opengl.util.glsl.ShaderProgram; 11 | import main.framework.Semantic; 12 | 13 | import static com.jogamp.opengl.GL2ES2.GL_FRAGMENT_SHADER; 14 | import static com.jogamp.opengl.GL2ES2.GL_VERTEX_SHADER; 15 | 16 | /** 17 | * 18 | * @author elect 19 | */ 20 | class ProgramData { 21 | 22 | public int theProgram; 23 | 24 | public int modelToCameraMatrixUnif; 25 | 26 | public int lightIntensityUnif; 27 | public int ambientIntensityUnif; 28 | 29 | public int normalModelToCameraMatrixUnif; 30 | public int cameraSpaceLightPosUnif; 31 | 32 | public int lightAttenuationUnif; 33 | public int shininessFactorUnif; 34 | public int baseDiffuseColorUnif; 35 | 36 | public ProgramData(GL3 gl3, String shaderRoot, String vertSrc, String fragSrc) { 37 | 38 | ShaderProgram shaderProgram = new ShaderProgram(); 39 | 40 | ShaderCode vertShaderCode = ShaderCode.create(gl3, GL_VERTEX_SHADER, this.getClass(), shaderRoot, null, 41 | vertSrc, "vert", null, true); 42 | ShaderCode fragShaderCode = ShaderCode.create(gl3, GL_FRAGMENT_SHADER, this.getClass(), shaderRoot, null, 43 | fragSrc, "frag", null, true); 44 | 45 | shaderProgram.add(vertShaderCode); 46 | shaderProgram.add(fragShaderCode); 47 | 48 | shaderProgram.link(gl3, System.out); 49 | 50 | theProgram = shaderProgram.program(); 51 | 52 | vertShaderCode.destroy(gl3); 53 | fragShaderCode.destroy(gl3); 54 | 55 | modelToCameraMatrixUnif = gl3.glGetUniformLocation(theProgram, "modelToCameraMatrix"); 56 | lightIntensityUnif = gl3.glGetUniformLocation(theProgram, "lightIntensity"); 57 | ambientIntensityUnif = gl3.glGetUniformLocation(theProgram, "ambientIntensity"); 58 | 59 | normalModelToCameraMatrixUnif = gl3.glGetUniformLocation(theProgram, "normalModelToCameraMatrix"); 60 | cameraSpaceLightPosUnif = gl3.glGetUniformLocation(theProgram, "cameraSpaceLightPos"); 61 | 62 | lightAttenuationUnif = gl3.glGetUniformLocation(theProgram, "lightAttenuation"); 63 | shininessFactorUnif = gl3.glGetUniformLocation(theProgram, "shininessFactor"); 64 | baseDiffuseColorUnif = gl3.glGetUniformLocation(theProgram, "baseDiffuseColor"); 65 | 66 | gl3.glUniformBlockBinding(theProgram, 67 | gl3.glGetUniformBlockIndex(theProgram, "Projection"), 68 | Semantic.Uniform.PROJECTION); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/UnlitProgData.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * To change this license header, choose License Headers in Project Properties. 3 | // * To change this template file, choose Tools | Templates 4 | // * and open the template in the editor. 5 | // */ 6 | //package main.tut12.sceneLighting; 7 | // 8 | //import static com.jogamp.opengl.GL2ES2.GL_FRAGMENT_SHADER; 9 | //import static com.jogamp.opengl.GL2ES2.GL_VERTEX_SHADER; 10 | //import com.jogamp.opengl.GL3; 11 | //import com.jogamp.opengl.util.glsl.ShaderCode; 12 | //import com.jogamp.opengl.util.glsl.ShaderProgram; 13 | //import main.framework.Framework; 14 | //import main.framework.Semantic; 15 | //import glm.mat._4.Mat4; 16 | // 17 | ///** 18 | // * 19 | // * @author elect 20 | // */ 21 | //class UnlitProgData { 22 | // 23 | // public int theProgram; 24 | // 25 | // public int objectColorUnif; 26 | // 27 | // public int cameraToClipMatrixUnif; 28 | // public int modelToCameraMatrixUnif; 29 | // 30 | // public UnlitProgData(GL3 gl3, String shaderRoot, String vertSrc, String fragSrc) { 31 | // 32 | // ShaderProgram shaderProgram = new ShaderProgram(); 33 | // 34 | // ShaderCode vertShaderCode = ShaderCode.create(gl3, GL_VERTEX_SHADER, this.getClass(), shaderRoot, null, 35 | // vertSrc, "vert", null, true); 36 | // ShaderCode fragShaderCode = ShaderCode.create(gl3, GL_FRAGMENT_SHADER, this.getClass(), shaderRoot, null, 37 | // fragSrc, "frag", null, true); 38 | // 39 | // shaderProgram.add(vertShaderCode); 40 | // shaderProgram.add(fragShaderCode); 41 | // 42 | // shaderProgram.link(gl3, System.out); 43 | // 44 | // theProgram = shaderProgram.program(); 45 | // 46 | // vertShaderCode.destroy(gl3); 47 | // fragShaderCode.destroy(gl3); 48 | // 49 | // objectColorUnif = gl3.glGetUniformLocation(theProgram, "objectColor"); 50 | // 51 | // modelToCameraMatrixUnif = gl3.glGetUniformLocation(theProgram, "modelToCameraMatrix"); 52 | // cameraToClipMatrixUnif = gl3.glGetUniformLocation(theProgram, "cameraToClipMatrix"); 53 | // 54 | // gl3.glUniformBlockBinding(theProgram, 55 | // gl3.glGetUniformBlockIndex(theProgram, "Projection"), 56 | // Semantic.Uniform.PROJECTION); 57 | // gl3.glUniformBlockBinding(theProgram, 58 | // gl3.glGetUniformBlockIndex(theProgram, "Material"), 59 | // Semantic.Uniform.MATERIAL); 60 | // gl3.glUniformBlockBinding(theProgram, 61 | // gl3.glGetUniformBlockIndex(theProgram, "Light"), 62 | // Semantic.Uniform.LIGHT); 63 | // } 64 | // 65 | // public void setWindowData(GL3 gl3, Mat4 cameraToClip) { 66 | // gl3.glUseProgram(theProgram); 67 | // gl3.glUniformMatrix4fv(cameraToClipMatrixUnif, 1, false, cameraToClip.toDfb(Framework.matBuffer)); 68 | // gl3.glUseProgram(0); 69 | // } 70 | //} 71 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/diffuse-only-mtl.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = COLOR) in vec4 diffuseColor; 10 | layout(location = NORMAL) in vec3 normal; 11 | 12 | out vec4 diffuseColor_; 13 | out vec3 vertexNormal; 14 | out vec3 cameraSpacePosition; 15 | 16 | uniform Projection 17 | { 18 | mat4 cameraToClipMatrix; 19 | }; 20 | 21 | uniform mat4 modelToCameraMatrix; 22 | uniform mat3 normalModelToCameraMatrix; 23 | 24 | void main() 25 | { 26 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 27 | gl_Position = cameraToClipMatrix * tempCamPosition; 28 | 29 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 30 | diffuseColor = inDiffuseColor; 31 | cameraSpacePosition = vec3(tempCamPosition); 32 | } -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/diffuse-only.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = COLOR) in vec4 diffuseColor; 10 | layout(location = NORMAL) in vec3 normal; 11 | 12 | out vec4 diffuseColor_; 13 | out vec3 vertexNormal; 14 | out vec3 cameraSpacePosition; 15 | 16 | uniform Projection 17 | { 18 | mat4 cameraToClipMatrix; 19 | }; 20 | 21 | uniform mat4 modelToCameraMatrix; 22 | uniform mat3 normalModelToCameraMatrix; 23 | 24 | void main() 25 | { 26 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 27 | gl_Position = cameraToClipMatrix * tempCamPosition; 28 | 29 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 30 | diffuseColor = inDiffuseColor; 31 | cameraSpacePosition = vec3(tempCamPosition); 32 | } -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/diffuse-specular-mtl.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec3 vertexNormal; 12 | out vec3 cameraSpacePosition; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | uniform mat3 normalModelToCameraMatrix; 21 | 22 | void main() 23 | { 24 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 25 | gl_Position = cameraToClipMatrix * tempCamPosition; 26 | 27 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 28 | cameraSpacePosition = vec3(tempCamPosition); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/diffuse-specular.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec3 vertexNormal; 12 | out vec3 cameraSpacePosition; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | uniform mat3 normalModelToCameraMatrix; 21 | 22 | void main() 23 | { 24 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 25 | gl_Position = cameraToClipMatrix * tempCamPosition; 26 | 27 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 28 | cameraSpacePosition = vec3(tempCamPosition); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/pcn.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = COLOR) in vec4 diffuseColor; 10 | layout(location = NORMAL) in vec3 normal; 11 | 12 | out vec4 diffuseColor_; 13 | out vec3 vertexNormal; 14 | out vec3 cameraSpacePosition; 15 | 16 | uniform Projection 17 | { 18 | mat4 cameraToClipMatrix; 19 | }; 20 | 21 | uniform mat4 modelToCameraMatrix; 22 | uniform mat3 normalModelToCameraMatrix; 23 | 24 | void main() 25 | { 26 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 27 | gl_Position = cameraToClipMatrix * tempCamPosition; 28 | 29 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 30 | diffuseColor = inDiffuseColor; 31 | cameraSpacePosition = vec3(tempCamPosition); 32 | } -------------------------------------------------------------------------------- /src/main/java/main/tut12/sceneLighting/shaders/pn.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Attribute 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | 8 | layout(location = POSITION) in vec3 position; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec3 vertexNormal; 12 | out vec3 cameraSpacePosition; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | uniform mat3 normalModelToCameraMatrix; 21 | 22 | void main() 23 | { 24 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 25 | gl_Position = cameraToClipMatrix * tempCamPosition; 26 | 27 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 28 | cameraSpacePosition = vec3(tempCamPosition); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/glNext/depth.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL 4 | import com.jogamp.opengl.GL3 5 | import glm.d 6 | 7 | /** 8 | * Created by elect on 15/04/17. 9 | */ 10 | 11 | 12 | fun GL3.depth(block: ObjectDepth.() -> Unit) { 13 | ObjectDepth.gl = this 14 | ObjectDepth.block() 15 | } 16 | 17 | fun GL3.depth(enable: Boolean = false, mask: Boolean = true, func: Int = GL.GL_LESS, rangeNear: Float = 0f, 18 | rangeFar: Float = 1f, clamp: Boolean = false) = depth(enable, mask, func, rangeNear.d, rangeFar.d, clamp) 19 | 20 | fun GL3.depth(enable: Boolean = false, mask: Boolean = true, func: Int = GL.GL_LESS, rangeNear: Double = 0.0, 21 | rangeFar: Double = 1.0, clamp: Boolean = false) { 22 | if (enable) 23 | glEnable(GL.GL_DEPTH_TEST) 24 | else 25 | glDisable(GL.GL_DEPTH_TEST) 26 | glDepthMask(mask) 27 | glDepthFunc(func) 28 | glDepthRange(rangeNear, rangeFar) 29 | if (clamp) 30 | glEnable(GL3.GL_DEPTH_CLAMP) 31 | else 32 | glDisable(GL3.GL_DEPTH_CLAMP) 33 | } 34 | 35 | object ObjectDepth { 36 | 37 | lateinit var gl: GL3 38 | 39 | val never = Func.never 40 | val less = Func.less 41 | val equal = Func.equal 42 | val lEqual = Func.lEqual 43 | val greater = Func.greater 44 | val notEqual = Func.notEqual 45 | val gEqual = Func.gEqual 46 | val always = Func.always 47 | 48 | var test = false 49 | set(value) { 50 | if (value) 51 | gl.glEnable(GL.GL_DEPTH_TEST) 52 | else 53 | gl.glDisable(GL.GL_DEPTH_TEST) 54 | } 55 | var mask = true 56 | set(value) { 57 | gl.glDepthMask(value) 58 | field = value 59 | } 60 | var func = Func.less 61 | set(value) { 62 | gl.glDepthFunc(func.i) 63 | field = value 64 | } 65 | var range = 0.0 .. 1.0 66 | set(value) { 67 | gl.glDepthRange(value.start, value.endInclusive) 68 | field = value 69 | } 70 | var rangef = 0f .. 1f 71 | set(value) { 72 | gl.glDepthRangef(value.start, value.endInclusive) 73 | field = value 74 | } 75 | var clamp = false 76 | set(value) { 77 | if (value) 78 | gl.glEnable(GL3.GL_DEPTH_CLAMP) 79 | else 80 | gl.glDisable(GL3.GL_DEPTH_CLAMP) 81 | } 82 | 83 | enum class Func(val i: Int) { never(GL.GL_NEVER), less(GL.GL_LESS), equal(GL.GL_EQUAL), lEqual(GL.GL_LEQUAL), 84 | greater(GL.GL_GREATER), notEqual(GL.GL_NOTEQUAL), gEqual(GL.GL_GEQUAL), always(GL.GL_ALWAYS) 85 | } 86 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/faceCull.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL 4 | import com.jogamp.opengl.GL3 5 | 6 | /** 7 | * Created by elect on 15/04/17. 8 | */ 9 | 10 | 11 | fun GL3.cullFace(block: ObjectCullFace.() -> Unit) { 12 | ObjectCullFace.gl = this 13 | ObjectCullFace.block() 14 | } 15 | 16 | object ObjectCullFace { 17 | 18 | lateinit var gl: GL3 19 | 20 | val front = CullFace.front 21 | val back = CullFace.back 22 | val frontAndBack = CullFace.frontAndBack 23 | 24 | val cw = FrontFace.cw 25 | val ccw = FrontFace.ccw 26 | 27 | fun enable() = gl.glEnable(GL.GL_CULL_FACE) 28 | fun disable() = gl.glDisable(GL.GL_CULL_FACE) 29 | var cullFace = CullFace.back 30 | set(value) { 31 | gl.glCullFace(value.i) 32 | field = value 33 | } 34 | 35 | var frontFace = FrontFace.ccw 36 | set(value) { 37 | gl.glFrontFace(value.i) 38 | field = value 39 | } 40 | 41 | enum class CullFace(val i: Int) {front(GL.GL_FRONT), back(GL.GL_BACK), frontAndBack(GL.GL_FRONT_AND_BACK) } 42 | enum class FrontFace(val i: Int) {cw(GL.GL_CW), ccw(GL.GL_CCW) } 43 | } 44 | 45 | fun GL3.cullFace(enable: Boolean = false, cullFace: Int = GL.GL_BACK, frontFace: Int = GL.GL_CCW) { 46 | if (enable) 47 | glEnable(GL.GL_CULL_FACE) 48 | else 49 | glDisable(GL.GL_CULL_FACE) 50 | glCullFace(cullFace) 51 | glFrontFace(frontFace) 52 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/glf.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL 4 | import glm.L 5 | import glm.vec._2.Vec2 6 | import glm.vec._2.Vec2s 7 | import glm.vec._2.Vec2us 8 | import glm.vec._3.Vec3 9 | import glm.vec._4.Vec4 10 | import glm.vec._4.Vec4ub 11 | import main.framework.Semantic 12 | 13 | /** 14 | * Created by GBarbieri on 11.04.2017. 15 | */ 16 | 17 | object glf { 18 | 19 | object pos4 : VertexLayout { 20 | override var attribute = arrayOf( 21 | VertexAttribute(Semantic.Attr.POSITION, Vec4.length, GL.GL_FLOAT, false, Vec4.SIZE, 0)) 22 | } 23 | 24 | object pos3_col4 : VertexLayout { 25 | override var attribute = arrayOf( 26 | VertexAttribute(Semantic.Attr.POSITION, Vec3.length, GL.GL_FLOAT, false, Vec3.SIZE + Vec4.SIZE, 0), 27 | VertexAttribute(Semantic.Attr.COLOR, Vec4.length, GL.GL_FLOAT, false, Vec3.SIZE + Vec4.SIZE, Vec4.SIZE.L)) 28 | } 29 | 30 | object pos4_col4 : VertexLayout { 31 | override var attribute = arrayOf( 32 | VertexAttribute(Semantic.Attr.POSITION, Vec4.length, GL.GL_FLOAT, false, Vec4.SIZE * 2, 0), 33 | VertexAttribute(Semantic.Attr.COLOR, Vec4.length, GL.GL_FLOAT, false, Vec4.SIZE * 2, Vec4.SIZE.L)) 34 | } 35 | 36 | 37 | object pos2_tc2 : VertexLayout { 38 | override var attribute = arrayOf( 39 | VertexAttribute(Semantic.Attr.POSITION, Vec2.length, GL.GL_FLOAT, false, Vec2.SIZE * 2, 0), 40 | VertexAttribute(Semantic.Attr.TEX_COORD, Vec2.length, GL.GL_FLOAT, false, Vec2.SIZE * 2, Vec2.SIZE.L)) 41 | } 42 | 43 | object pos2us_tc2us : VertexLayout { 44 | override var attribute = arrayOf( 45 | VertexAttribute(Semantic.Attr.POSITION, Vec2us.length, GL.GL_UNSIGNED_SHORT, false, Vec2us.SIZE * 2, 0), 46 | VertexAttribute(Semantic.Attr.TEX_COORD, Vec2us.length, GL.GL_UNSIGNED_SHORT, false, Vec2us.SIZE * 2, Vec2us.SIZE.L)) 47 | } 48 | 49 | object pos3_tc2 : VertexLayout { 50 | override var attribute = arrayOf( 51 | VertexAttribute(Semantic.Attr.POSITION, Vec3.length, GL.GL_FLOAT, false, Vec3.SIZE + Vec2.SIZE, 0), 52 | VertexAttribute(Semantic.Attr.TEX_COORD, Vec2.length, GL.GL_FLOAT, false, Vec3.SIZE + Vec2.SIZE, Vec3.SIZE.L)) 53 | } 54 | 55 | object pos3_col4ub : VertexLayout { 56 | override var attribute = arrayOf( 57 | VertexAttribute(Semantic.Attr.POSITION, Vec3.length, GL.GL_FLOAT, false, Vec3.SIZE + Vec4ub.SIZE, 0), 58 | VertexAttribute(Semantic.Attr.COLOR, Vec4ub.length, GL.GL_UNSIGNED_BYTE, false, Vec3.SIZE + Vec4ub.SIZE, Vec3.SIZE.L)) 59 | } 60 | 61 | object pos2_tc3 : VertexLayout { 62 | override var attribute = arrayOf( 63 | VertexAttribute(Semantic.Attr.POSITION, Vec2.length, GL.GL_FLOAT, false, Vec2.SIZE + Vec3.SIZE, 0), 64 | VertexAttribute(Semantic.Attr.TEX_COORD, Vec3.length, GL.GL_FLOAT, false, Vec2.SIZE + Vec3.SIZE, Vec2.SIZE.L)) 65 | } 66 | 67 | object pos3_tc3 : VertexLayout { 68 | override var attribute = arrayOf( 69 | VertexAttribute(Semantic.Attr.POSITION, Vec3.length, GL.GL_FLOAT, false, Vec3.SIZE * 2, 0), 70 | VertexAttribute(Semantic.Attr.TEX_COORD, Vec3.length, GL.GL_FLOAT, false, Vec3.SIZE * 2, Vec3.SIZE.L)) 71 | } 72 | } 73 | 74 | interface VertexLayout { 75 | var attribute: Array 76 | operator fun get(index: Int) = attribute[index] 77 | } 78 | 79 | class VertexAttribute( 80 | var index: Int, 81 | var size: Int, 82 | var type: Int, 83 | var normalized: Boolean, 84 | var interleavedStride: Int, 85 | var pointer: Long) -------------------------------------------------------------------------------- /src/main/kotlin/glNext/misc.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL 4 | import com.jogamp.opengl.GL2ES3 5 | import com.jogamp.opengl.GL3 6 | import glm.f 7 | import uno.buffer.byteBufferBig 8 | import uno.buffer.floatBufferBig 9 | import uno.buffer.intBufferBig 10 | 11 | /** 12 | * Created by elect on 09/04/17. 13 | */ 14 | 15 | val int = intBufferBig(1) 16 | val float = floatBufferBig(1) 17 | val byte = byteBufferBig(1) 18 | val matBuffer = floatBufferBig(16) 19 | 20 | 21 | fun GL3.glDrawArrays(count: Int) = glDrawArrays(GL.GL_TRIANGLES, 0, count) 22 | fun GL3.glDrawArrays(mode: Int, count: Int) = glDrawArrays(mode, 0, count) 23 | 24 | fun GL3.glDrawElements(count: Int, type: Int) = glDrawElements(GL.GL_TRIANGLES, count, type, 0) 25 | fun GL3.glDrawElements(mode: Int, count: Int, type: Int) = glDrawElements(mode, count, type, 0) 26 | 27 | fun GL3.glDrawElementsBaseVertex(count: Int, type: Int, indices_buffer_offset: Long, basevertex: Int) = 28 | glDrawElementsBaseVertex(GL.GL_TRIANGLES, count, type, indices_buffer_offset, basevertex) 29 | 30 | fun GL3.glClearBufferf(buffer: Int, f: Float) = when (buffer) { 31 | GL2ES3.GL_COLOR -> glClearBufferf(buffer, f, f, f, f) 32 | GL2ES3.GL_DEPTH -> glClearBufferfv(buffer, 0, matBuffer.put(0, f)) 33 | else -> throw Error() 34 | } 35 | 36 | fun GL3.glClearBufferf(buffer: Int, r: Float, g: Float, b: Float, a: Float) = glClearBufferfv(buffer, 0, matBuffer.put(0, r).put(1, g).put(2, b).put(3, a)) 37 | fun GL3.glClearBufferf(buffer: Int, n: Number) = when (buffer) { 38 | GL2ES3.GL_COLOR -> glClearBufferf(buffer, n.f, n.f, n.f, n.f) 39 | GL2ES3.GL_DEPTH -> glClearBufferfv(buffer, 0, matBuffer.put(0, n.f)) 40 | else -> throw Error() 41 | } 42 | 43 | fun GL3.glClearBufferf(buffer: Int) = when (buffer) { 44 | GL2ES3.GL_COLOR -> glClearBufferfv(buffer, 0, matBuffer.put(0, 0f).put(1, 0f).put(2, 0f).put(3, 1f)) 45 | GL2ES3.GL_DEPTH -> glClearBufferfv(buffer, 0, matBuffer.put(0, 1f)) 46 | else -> throw Error() 47 | } 48 | 49 | fun GL3.glClearBufferf(buffer: Int, r: Number, g: Number, b: Number, a: Number) = glClearBufferf(buffer, r.f, g.f, b.f, a.f) 50 | 51 | 52 | fun GL3.glViewport(width: Int, height: Int) = glViewport(0, 0, width, height) 53 | 54 | 55 | 56 | inline fun GL3.clear(block: Clear.() -> Unit) { 57 | Clear.gl = this 58 | Clear.block() 59 | } 60 | 61 | object Clear { 62 | 63 | lateinit var gl: GL3 64 | 65 | 66 | fun color() = color(0f, 0f, 0f, 1f) 67 | fun color(f: Float) = color(f, f, f, f) 68 | fun color(r: Float, g: Float, b: Float, a: Float) = 69 | gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, matBuffer.put(0, r).put(1, g).put(2, b).put(3, a)) 70 | 71 | fun color(n: Number) = color(n, n, n, n) 72 | fun color(r: Number, g: Number, b: Number, a: Number) 73 | = gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, matBuffer.put(0, r.f).put(1, g.f).put(2, b.f).put(3, a.f)) 74 | 75 | fun depth() = depth(1f) 76 | fun depth(depth: Float) = gl.glClearBufferfv(GL2ES3.GL_DEPTH, 0, matBuffer.put(0, depth)) 77 | fun depth(depth: Number) = depth(depth.f) 78 | } 79 | 80 | 81 | 82 | 83 | 84 | fun GL3.glGetInteger(pname: Int): Int { 85 | glGetIntegerv(pname, int) 86 | return int[0] 87 | } 88 | 89 | infix fun GL3.glEnable(cap: Int) = glEnable(cap) 90 | infix fun GL3.disable(cap: Int) = glDisable(cap) 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/main/kotlin/glNext/sampler.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL 4 | import com.jogamp.opengl.GL2ES3 5 | import com.jogamp.opengl.GL3 6 | import java.nio.IntBuffer 7 | 8 | /** 9 | * Created by GBarbieri on 12.04.2017. 10 | */ 11 | 12 | 13 | fun GL3.glGenSampler(sampler: IntBuffer) = glGenSamplers(1, sampler) 14 | 15 | fun GL3.glGenSamplers(samplers: IntBuffer) = glGenSamplers(samplers.capacity(), samplers) 16 | 17 | fun GL3.glDeleteSampler(sampler: IntBuffer) = glDeleteSamplers(1, sampler) 18 | fun GL3.glDeleteSamplers(samplers: IntBuffer) = glDeleteSamplers(samplers.capacity(), samplers) 19 | 20 | fun GL3.glSamplerParameteri(sampler: IntBuffer, pname: Int, param: Int) = glSamplerParameteri(sampler[0], pname, param) 21 | 22 | fun GL3.glBindSampler(unit: Int, sampler: IntBuffer) = glBindSampler(unit, sampler[0]) 23 | fun GL3.glBindSampler(unit: Int) = glBindSampler(unit, 0) 24 | 25 | fun GL3.initSampler(sampler: IntBuffer, block: Sampler.() -> Unit) { 26 | glGenSamplers(1, sampler) 27 | Sampler.gl = this 28 | Sampler.name = sampler[0] 29 | Sampler.block() 30 | } 31 | 32 | object Sampler { 33 | 34 | lateinit var gl: GL3 35 | var name = 0 36 | 37 | val linear = Filer.linear 38 | val nearest = Filer.nearest 39 | 40 | val nearest_mmNearest = Filer.nearest_mmNearest 41 | val linear_mmNearest = Filer.linear_mmNearest 42 | val nearest_mmLinear = Filer.nearest_mmLinear 43 | val linear_mmLinear = Filer.linear_mmLinear 44 | 45 | val clampToEdge = Wrap.clampToEdge 46 | val mirroredRepeat = Wrap.mirroredRepeat 47 | val repeat = Wrap.repeat 48 | 49 | var magFilter = linear 50 | set(value) { 51 | gl.glSamplerParameteri(name, GL2ES3.GL_TEXTURE_MAG_FILTER, value.i) 52 | field = value 53 | } 54 | var minFilter = nearest_mmLinear 55 | set(value) { 56 | gl.glSamplerParameteri(name, GL2ES3.GL_TEXTURE_MIN_FILTER, value.i) 57 | field = value 58 | } 59 | var maxAnisotropy = 1.0f 60 | set(value) { 61 | gl.glSamplerParameterf(name, GL2ES3.GL_TEXTURE_MAX_ANISOTROPY_EXT, value) 62 | field = value 63 | } 64 | var wrapS = repeat 65 | set(value) { 66 | gl.glSamplerParameteri(name, GL.GL_TEXTURE_WRAP_S, value.i) 67 | field = value 68 | } 69 | var wrapT = repeat 70 | set(value) { 71 | gl.glSamplerParameteri(name, GL.GL_TEXTURE_WRAP_T, value.i) 72 | field = value 73 | } 74 | 75 | enum class Filer(val i: Int) {nearest(GL.GL_NEAREST), linear(GL.GL_LINEAR), 76 | nearest_mmNearest(GL.GL_NEAREST_MIPMAP_NEAREST), linear_mmNearest(GL.GL_LINEAR_MIPMAP_NEAREST), 77 | nearest_mmLinear(GL.GL_NEAREST_MIPMAP_LINEAR), linear_mmLinear(GL.GL_LINEAR_MIPMAP_LINEAR) 78 | } 79 | 80 | enum class Wrap(val i: Int) {clampToEdge(GL.GL_CLAMP_TO_EDGE), mirroredRepeat(GL.GL_MIRRORED_REPEAT), repeat(GL.GL_REPEAT) } 81 | } 82 | 83 | fun GL3.initSamplers(samplers: IntBuffer, block: Samplers.() -> Unit) { 84 | glGenSamplers(samplers.capacity(), samplers) 85 | Samplers.gl = this 86 | Samplers.names = samplers 87 | Samplers.block() 88 | } 89 | 90 | object Samplers { 91 | 92 | lateinit var gl: GL3 93 | lateinit var names: IntBuffer 94 | 95 | fun at(index: Int, block: Sampler.() -> Unit) { 96 | Sampler.gl = gl 97 | Sampler.name = names[index] // bind 98 | Sampler.block() 99 | } 100 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/shader.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | import com.jogamp.opengl.GL2ES2 4 | import com.jogamp.opengl.GL3 5 | import glm.set 6 | import uno.buffer.byteBufferOf 7 | import uno.buffer.destroy 8 | 9 | /** 10 | * Created by GBarbieri on 10.04.2017. 11 | */ 12 | 13 | fun GL3.glShaderSource(shader: Int, source: String) { 14 | val lines = arrayOf(source) 15 | int[0] = lines[0].length 16 | glShaderSource(shader, 1, lines, int) 17 | } 18 | 19 | fun GL3.glGetShader(shader: Int, pname: Int): Int { 20 | glGetShaderiv(shader, pname, int) 21 | return int[0] 22 | } 23 | 24 | fun GL3.glGetShaderInfoLog(shader: Int): String { 25 | 26 | glGetShaderiv(shader, GL2ES2.GL_INFO_LOG_LENGTH, int) 27 | val infoLogLength = int[0] 28 | 29 | val bufferInfoLog = byteBufferOf(infoLogLength) 30 | glGetShaderInfoLog(shader, infoLogLength, null, bufferInfoLog) 31 | 32 | val bytes = ByteArray(infoLogLength) 33 | bufferInfoLog.get(bytes).destroy() 34 | 35 | return String(bytes) 36 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/test.kt: -------------------------------------------------------------------------------- 1 | package glNext 2 | 3 | /** 4 | * Created by GBarbieri on 11.04.2017. 5 | */ 6 | 7 | class Person private constructor(val name: String, val surname: String, val age: Int) { 8 | 9 | private constructor(builder: Builder) : this(builder.name, builder.surname, builder.age) 10 | 11 | companion object { 12 | fun create(init: Builder.() -> Unit) = Builder(init).build() 13 | } 14 | 15 | class Builder private constructor() { 16 | 17 | constructor(init: Builder.() -> Unit) : this() { 18 | init() 19 | } 20 | 21 | lateinit var name: String 22 | lateinit var surname: String 23 | var age: Int = 0 24 | 25 | fun name(init: Builder.() -> String) = apply { name = init() } 26 | 27 | fun surname(init: Builder.() -> String) = apply { surname = init() } 28 | 29 | fun age(init: Builder.() -> Int) = apply { age = init() } 30 | 31 | fun build() = Person(this) 32 | } 33 | } 34 | 35 | fun main(args: Array) { 36 | Person.create { 37 | name { "Peter" } 38 | surname { "Slesarew" } 39 | age { 28 } 40 | } 41 | 42 | // OR 43 | 44 | Person.create { 45 | name = "Peter" 46 | surname = "Slesarew" 47 | age = 28 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut02/fragPosition.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut02 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL2ES2 6 | import com.jogamp.opengl.GL3 7 | import com.jogamp.opengl.util.glsl.ShaderProgram 8 | import glNext.* 9 | import main.framework.Framework 10 | import uno.buffer.destroyBuffers 11 | import uno.buffer.floatBufferOf 12 | import uno.buffer.intBufferBig 13 | import uno.glsl.shaderCodeOf 14 | 15 | /** 16 | * Created by GBarbieri on 21.02.2017. 17 | */ 18 | 19 | fun main(args: Array) { 20 | FragPosition_Next().setup("Tutorial 02 - Fragment Position") 21 | } 22 | 23 | class FragPosition_Next : Framework() { 24 | 25 | var theProgram = 0 26 | val vertexBufferObject = intBufferBig(1) 27 | var vao = intBufferBig(1) 28 | val vertexData = floatBufferOf( 29 | +0.75f, +0.75f, 0.0f, 1.0f, 30 | +0.75f, -0.75f, 0.0f, 1.0f, 31 | -0.75f, -0.75f, 0.0f, 1.0f) 32 | 33 | override fun init(gl: GL3) = with(gl) { 34 | 35 | initializeProgram(gl) 36 | initializeVertexBuffer(gl) 37 | 38 | glGenVertexArray(vao) 39 | glBindVertexArray(vao) 40 | } 41 | 42 | fun initializeProgram(gl: GL3) { 43 | theProgram = shaderProgramOf(gl, javaClass, "tut02", "frag-position.vert", "frag-position.frag") 44 | } 45 | 46 | fun shaderProgramOf(gl: GL2ES2, context: Class<*>, vararg strings: String): Int = with(gl) { 47 | 48 | val shaders = 49 | if (strings[0].contains('.')) 50 | strings.toList() 51 | else { 52 | val root = if (strings[0].endsWith('/')) strings[0] else strings[0] + '/' 53 | strings.drop(1).map { root + it } 54 | } 55 | 56 | val shaderProgram = ShaderProgram() 57 | 58 | val shaderCodes = shaders.map { shaderCodeOf(gl, context, it) } 59 | 60 | shaderCodes.forEach { shaderProgram.add(gl, it, System.err) } 61 | 62 | shaderProgram.link(gl, System.err) 63 | 64 | shaderCodes.forEach { 65 | glDetachShader(shaderProgram.program(), it.id()) 66 | glDeleteShader(it.id()) 67 | } 68 | 69 | return shaderProgram.program() 70 | } 71 | 72 | fun initializeVertexBuffer(gl: GL3) = gl.initArrayBuffer(vertexBufferObject) { data(vertexData, GL_STATIC_DRAW) } 73 | 74 | override fun display(gl: GL3) = with(gl) { 75 | 76 | clear { color() } 77 | 78 | usingProgram(theProgram) { 79 | withVertexLayout(vertexBufferObject, glf.pos4) { glDrawArrays(3) } 80 | } 81 | } 82 | 83 | public override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 84 | glViewport(w, h) 85 | } 86 | 87 | override fun end(gl: GL3) = with(gl) { 88 | 89 | glDeleteProgram(theProgram) 90 | glDeleteBuffer(vertexBufferObject) 91 | glDeleteVertexArray(vao) 92 | 93 | destroyBuffers(vertexBufferObject, vao) 94 | } 95 | 96 | override fun keyPressed(keyEvent: KeyEvent) { 97 | 98 | when (keyEvent.keyCode) { 99 | KeyEvent.VK_ESCAPE -> quit() 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut02/vertexColor.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut02 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL3 6 | import glNext.* 7 | import glm.vec._4.Vec4 8 | import main.framework.Framework 9 | import uno.buffer.* 10 | import uno.glsl.programOf 11 | 12 | /** 13 | * Created by GBarbieri on 21.02.2017. 14 | */ 15 | 16 | fun main(args: Array) { 17 | VertexColor_Next().setup("Tutorial 02 - Vertex Colors") 18 | } 19 | 20 | class VertexColor_Next : Framework() { 21 | 22 | val VERTEX_SHADER = "tut02/vertex-colors.vert" 23 | val FRAGMENT_SHADER = "tut02/vertex-colors.frag" 24 | 25 | var theProgram = 0 26 | val vertexBufferObject = intBufferBig(1) 27 | val vao = intBufferBig(1) 28 | val vertexData = floatBufferOf( 29 | +0.0f, +0.500f, 0.0f, 1.0f, 30 | +0.5f, -0.366f, 0.0f, 1.0f, 31 | -0.5f, -0.366f, 0.0f, 1.0f, 32 | +1.0f, +0.000f, 0.0f, 1.0f, 33 | +0.0f, +1.000f, 0.0f, 1.0f, 34 | +0.0f, +0.000f, 1.0f, 1.0f) 35 | 36 | override fun init(gl: GL3) = with(gl) { 37 | 38 | initializeProgram(gl) 39 | initializeVertexBuffer(gl) 40 | 41 | glGenVertexArray(vao) 42 | glBindVertexArray(vao) 43 | } 44 | 45 | fun initializeProgram(gl: GL3) { 46 | theProgram = programOf(gl, javaClass, "tut02", "vertex-colors.vert", "vertex-colors.frag") 47 | } 48 | 49 | fun initializeVertexBuffer(gl: GL3) = gl.initArrayBuffer(vertexBufferObject) { data(vertexData, GL_STATIC_DRAW) } 50 | 51 | override fun display(gl: GL3) = with(gl) { 52 | 53 | clear { color(0) } 54 | 55 | usingProgram(theProgram) { 56 | withVertexLayout(vertexBufferObject, glf.pos4_col4, 0, Vec4.SIZE * 3) { glDrawArrays(3) } 57 | } 58 | } 59 | 60 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 61 | glViewport(w, h) 62 | } 63 | 64 | override fun end(gl: GL3) = with(gl) { 65 | 66 | glDeleteProgram(theProgram) 67 | glDeleteBuffer(vertexBufferObject) 68 | glDeleteVertexArray(vao) 69 | 70 | destroyBuffers(vertexBufferObject, vao, vertexData) 71 | } 72 | 73 | override fun keyPressed(keyEvent: KeyEvent) { 74 | 75 | when (keyEvent.keyCode) { 76 | KeyEvent.VK_ESCAPE -> quit() 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut03/cpuPositionOffset.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import glm.glm 6 | import com.jogamp.opengl.GL3 7 | import glNext.* 8 | import glm.set 9 | import glm.vec._2.Vec2 10 | import main.framework.Framework 11 | import uno.buffer.* 12 | import uno.glsl.programOf 13 | 14 | /** 15 | * Created by GBarbieri on 21.02.2017. 16 | */ 17 | 18 | fun main(args: Array) { 19 | CpuPositionOffset_Next().setup("Tutorial 03 - CPU Position Offset") 20 | } 21 | 22 | class CpuPositionOffset_Next : Framework() { 23 | 24 | var theProgram = 0 25 | val positionBufferObject = intBufferBig(1) 26 | val vao = intBufferBig(1) 27 | val vertexPositions = floatBufferOf( 28 | +0.25f, +0.25f, 0.0f, 1.0f, 29 | +0.25f, -0.25f, 0.0f, 1.0f, 30 | -0.25f, -0.25f, 0.0f, 1.0f) 31 | var startingTime = 0L 32 | 33 | override fun init(gl: GL3) = with(gl) { 34 | 35 | initializeProgram(gl) 36 | initializeVertexBuffer(gl) 37 | 38 | glGenVertexArray(vao) 39 | glBindVertexArray(vao) 40 | 41 | startingTime = System.currentTimeMillis() 42 | } 43 | 44 | fun initializeProgram(gl: GL3) { 45 | theProgram = programOf(gl, javaClass, "tut03", "standard.vert", "standard.frag") 46 | } 47 | 48 | fun initializeVertexBuffer(gl: GL3) = gl.initArrayBuffer(positionBufferObject) { data(vertexPositions, GL_STATIC_DRAW) } 49 | 50 | override fun display(gl: GL3) = with(gl) { 51 | 52 | val offset = Vec2(0f) 53 | 54 | computePositionOffsets(offset) 55 | adjustVertexData(gl, offset) 56 | 57 | clear { color() } 58 | 59 | usingProgram(theProgram) { 60 | withVertexLayout(positionBufferObject, glf.pos4) { glDrawArrays(3) } 61 | } 62 | } 63 | 64 | fun computePositionOffsets(offset: Vec2) { 65 | 66 | val loopDuration = 5.0f 67 | val scale = glm.PIf * 2.0f / loopDuration 68 | 69 | val elapsedTime = (System.currentTimeMillis() - startingTime) / 1_000f 70 | 71 | val fCurrTimeThroughLoop = elapsedTime % loopDuration 72 | 73 | offset.x = glm.cos(fCurrTimeThroughLoop * scale) * 0.5f 74 | offset.y = glm.sin(fCurrTimeThroughLoop * scale) * 0.5f 75 | } 76 | 77 | fun adjustVertexData(gl: GL3, offset: Vec2) = with(gl) { 78 | 79 | val newData = floatBufferBig(vertexPositions.capacity()) 80 | repeat(vertexPositions.capacity()) { newData[it] = vertexPositions[it] } 81 | 82 | for (iVertex in 0 until vertexPositions.capacity() step 4) { 83 | 84 | newData[iVertex + 0] = vertexPositions[iVertex + 0] + offset.x 85 | newData[iVertex + 1] = vertexPositions[iVertex + 1] + offset.y 86 | } 87 | 88 | withArrayBuffer(positionBufferObject) { subData(newData) } 89 | 90 | newData.destroy() 91 | } 92 | 93 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 94 | glViewport(w, h) 95 | } 96 | 97 | override fun end(gl: GL3) = with(gl) { 98 | 99 | glDeleteProgram(theProgram) 100 | glDeleteBuffer(positionBufferObject) 101 | glDeleteVertexArray(vao) 102 | 103 | destroyBuffers(positionBufferObject, vao, vertexPositions) 104 | } 105 | 106 | override fun keyPressed(keyEvent: KeyEvent) { 107 | 108 | when (keyEvent.keyCode) { 109 | KeyEvent.VK_ESCAPE -> quit() 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut03/fragChangeColor.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL3 6 | import glNext.* 7 | import main.framework.Framework 8 | import uno.buffer.destroyBuffers 9 | import uno.buffer.floatBufferOf 10 | import uno.buffer.intBufferBig 11 | import uno.glsl.programOf 12 | 13 | /** 14 | * Created by elect on 21/02/17. 15 | */ 16 | 17 | fun main(args: Array) { 18 | FragChangeColor_Next().setup("Tutorial 03 - Frag Change Color") 19 | } 20 | 21 | class FragChangeColor_Next : Framework() { 22 | 23 | var theProgram = 0 24 | var elapsedTimeUniform = 0 25 | val positionBufferObject = intBufferBig(1) 26 | val vao = intBufferBig(1) 27 | val vertexPositions = floatBufferOf( 28 | +0.25f, +0.25f, 0.0f, 1.0f, 29 | +0.25f, -0.25f, 0.0f, 1.0f, 30 | -0.25f, -0.25f, 0.0f, 1.0f) 31 | var startingTime = 0L 32 | 33 | override fun init(gl: GL3) = with(gl) { 34 | 35 | initializeProgram(gl) 36 | initializeVertexBuffer(gl) 37 | 38 | glGenVertexArray(vao) 39 | glBindVertexArray(vao) 40 | 41 | startingTime = System.currentTimeMillis() 42 | } 43 | 44 | fun initializeProgram(gl: GL3) = with(gl) { 45 | 46 | theProgram = programOf(gl, javaClass, "tut03", "calc-offset.vert", "calc-color.frag") 47 | 48 | withProgram(theProgram) { 49 | 50 | elapsedTimeUniform = "time".location 51 | 52 | use { 53 | "loopDuration".location.float = 5f 54 | "fragLoopDuration".location.float = 5f 55 | } 56 | } 57 | } 58 | 59 | fun initializeVertexBuffer(gl: GL3) = 60 | gl.initArrayBuffer(positionBufferObject) { data(vertexPositions, GL_STATIC_DRAW) } 61 | 62 | override fun display(gl: GL3) = with(gl) { 63 | 64 | clear { color(0) } 65 | 66 | usingProgram(theProgram) { 67 | 68 | elapsedTimeUniform.float = (System.currentTimeMillis() - startingTime) / 1_000f 69 | 70 | withVertexLayout(positionBufferObject, glf.pos4) { glDrawArrays(3) } 71 | } 72 | } 73 | 74 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 75 | glViewport(w, h) 76 | } 77 | 78 | override fun end(gl: GL3) = with(gl) { 79 | 80 | glDeleteProgram(theProgram) 81 | glDeleteBuffer(positionBufferObject) 82 | glDeleteVertexArray(vao) 83 | 84 | destroyBuffers(positionBufferObject, vao, vertexPositions) 85 | } 86 | 87 | override fun keyPressed(keyEvent: KeyEvent) { 88 | 89 | when (keyEvent.keyCode) { 90 | KeyEvent.VK_ESCAPE -> quit() 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut03/vertCalcOffset.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL3 6 | import glNext.* 7 | import main.framework.Framework 8 | import uno.buffer.destroyBuffers 9 | import uno.buffer.floatBufferOf 10 | import uno.buffer.intBufferBig 11 | import uno.glsl.programOf 12 | 13 | /** 14 | * Created by elect on 21/02/17. 15 | */ 16 | 17 | fun main(args: Array) { 18 | VertCalcOffset_Next().setup("Tutorial 03 - Shader Calc Offset") 19 | } 20 | 21 | class VertCalcOffset_Next : Framework() { 22 | 23 | var theProgram = 0 24 | var elapsedTimeUniform = 0 25 | val positionBufferObject = intBufferBig(1) 26 | val vao = intBufferBig(1) 27 | val vertexPositions = floatBufferOf( 28 | +0.25f, +0.25f, 0.0f, 1.0f, 29 | +0.25f, -0.25f, 0.0f, 1.0f, 30 | -0.25f, -0.25f, 0.0f, 1.0f) 31 | var startingTime = 0L 32 | 33 | override fun init(gl: GL3) = with(gl) { 34 | 35 | initializeProgram(gl) 36 | initializeVertexBuffer(gl) 37 | 38 | glGenVertexArray(vao) 39 | glBindVertexArray(vao) 40 | 41 | startingTime = System.currentTimeMillis() 42 | } 43 | 44 | fun initializeProgram(gl: GL3) = with(gl) { 45 | 46 | theProgram = programOf(gl, javaClass, "tut03", "calc-offset.vert", "standard.frag") 47 | 48 | withProgram(theProgram) { 49 | 50 | elapsedTimeUniform = "time".location 51 | 52 | use { "loopDuration".location.float = 5f } 53 | } 54 | } 55 | 56 | fun initializeVertexBuffer(gl: GL3) = 57 | gl.initArrayBuffer(positionBufferObject) { data(vertexPositions, GL_STATIC_DRAW) } 58 | 59 | override fun display(gl: GL3) = with(gl) { 60 | 61 | clear { color(0) } 62 | 63 | usingProgram(theProgram) { 64 | 65 | elapsedTimeUniform.float = (System.currentTimeMillis() - startingTime) / 1_000.0f 66 | 67 | withVertexLayout(positionBufferObject, glf.pos4) { glDrawArrays(3) } 68 | } 69 | } 70 | 71 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 72 | glViewport(w, h) 73 | } 74 | 75 | override fun end(gl: GL3) = with(gl) { 76 | 77 | glDeleteProgram(theProgram) 78 | glDeleteBuffer(positionBufferObject) 79 | glDeleteVertexArray(vao) 80 | 81 | destroyBuffers(positionBufferObject, vao) 82 | } 83 | 84 | override fun keyPressed(keyEvent: KeyEvent) { 85 | 86 | when (keyEvent.keyCode) { 87 | KeyEvent.VK_ESCAPE -> quit() 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/kotlin/glNext/tut03/vertPositionOffset.kt: -------------------------------------------------------------------------------- 1 | package glNext.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL3 6 | import glNext.* 7 | import glm.glm 8 | import glm.vec._2.Vec2 9 | import main.framework.Framework 10 | import uno.buffer.destroyBuffers 11 | import uno.buffer.floatBufferOf 12 | import uno.buffer.intBufferBig 13 | import uno.glsl.programOf 14 | 15 | /** 16 | * Created by elect on 21/02/17. 17 | */ 18 | 19 | fun main(args: Array) { 20 | VertPositionOffset_Next().setup("Tutorial 03 - Shader Position Offset") 21 | } 22 | 23 | class VertPositionOffset_Next : Framework() { 24 | 25 | var theProgram = 0 26 | var offsetLocation = 0 27 | val positionBufferObject = intBufferBig(1) 28 | val vao = intBufferBig(1) 29 | val vertexPositions = floatBufferOf( 30 | +0.25f, +0.25f, 0.0f, 1.0f, 31 | +0.25f, -0.25f, 0.0f, 1.0f, 32 | -0.25f, -0.25f, 0.0f, 1.0f) 33 | var startingTime = 0L 34 | 35 | override fun init(gl: GL3) = with(gl) { 36 | 37 | initializeProgram(gl) 38 | initializeVertexBuffer(gl) 39 | 40 | glGenVertexArray(vao) 41 | glBindVertexArray(vao) 42 | 43 | startingTime = System.currentTimeMillis() 44 | } 45 | 46 | fun initializeProgram(gl: GL3) = with(gl) { 47 | 48 | theProgram = programOf(gl, javaClass, "tut03", "position-offset.vert", "standard.frag") 49 | 50 | withProgram(theProgram) { offsetLocation = "offset".location } 51 | } 52 | 53 | fun initializeVertexBuffer(gl: GL3) = 54 | gl.initArrayBuffer(positionBufferObject) { data(vertexPositions, GL_STATIC_DRAW) } 55 | 56 | override fun display(gl: GL3) = with(gl) { 57 | 58 | val offset = Vec2(0f) 59 | computePositionOffsets(offset) 60 | 61 | clear { color(0, 0, 0, 1) } 62 | 63 | usingProgram(theProgram) { 64 | 65 | offsetLocation.vec2 = offset 66 | 67 | withVertexLayout(positionBufferObject, glf.pos4) { glDrawArrays(3) } 68 | } 69 | } 70 | 71 | fun computePositionOffsets(offset: Vec2) { 72 | 73 | val loopDuration = 5.0f 74 | val scale = glm.PIf * 2f / loopDuration 75 | 76 | val elapsedTime = (System.currentTimeMillis() - startingTime) / 1_000f 77 | 78 | val currTimeThroughLoop = elapsedTime % loopDuration 79 | 80 | offset.x = glm.cos(currTimeThroughLoop * scale) * .5f 81 | offset.y = glm.sin(currTimeThroughLoop * scale) * .5f 82 | } 83 | 84 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 85 | glViewport(w, h) 86 | } 87 | 88 | override fun end(gl: GL3) = with(gl) { 89 | 90 | glDeleteProgram(theProgram) 91 | glDeleteBuffer(positionBufferObject) 92 | glDeleteVertexArray(vao) 93 | 94 | destroyBuffers(positionBufferObject, vao, vertexPositions) 95 | } 96 | 97 | override fun keyPressed(keyEvent: KeyEvent) { 98 | 99 | when (keyEvent.keyCode) { 100 | KeyEvent.VK_ESCAPE -> quit() 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/main/kotlin/main/tut02/fragPosition.kt: -------------------------------------------------------------------------------- 1 | package main.tut02 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL2ES2 6 | import com.jogamp.opengl.GL2ES3.GL_COLOR 7 | import com.jogamp.opengl.GL3 8 | import com.jogamp.opengl.util.glsl.ShaderProgram 9 | import glNext.* 10 | import main.framework.Framework 11 | import uno.buffer.destroyBuffers 12 | import uno.buffer.floatBufferOf 13 | import uno.buffer.intBufferBig 14 | import uno.glsl.shaderCodeOf 15 | 16 | /** 17 | * Created by GBarbieri on 21.02.2017. 18 | */ 19 | 20 | fun main(args: Array) { 21 | FragPosition_().setup("Tutorial 02 - Fragment Position") 22 | } 23 | 24 | class FragPosition_ : Framework() { 25 | 26 | var theProgram = 0 27 | val vertexBufferObject = intBufferBig(1) 28 | val vao = intBufferBig(1) 29 | val vertexData = floatBufferOf( 30 | +0.75f, +0.75f, 0.0f, 1.0f, 31 | +0.75f, -0.75f, 0.0f, 1.0f, 32 | -0.75f, -0.75f, 0.0f, 1.0f) 33 | 34 | override fun init(gl: GL3) = with(gl) { 35 | 36 | initializeProgram(gl) 37 | initializeVertexBuffer(gl) 38 | 39 | glGenVertexArray(vao) 40 | glBindVertexArray(vao) 41 | } 42 | 43 | fun initializeProgram(gl: GL3) { 44 | theProgram = shaderProgramOf(gl, javaClass, "tut02", "frag-position.vert", "frag-position.frag") 45 | } 46 | 47 | fun shaderProgramOf(gl: GL2ES2, context: Class<*>, vararg strings: String): Int = with(gl) { 48 | 49 | val shaders = 50 | if (strings[0].contains('.')) 51 | strings.toList() 52 | else { 53 | val root = if (strings[0].endsWith('/')) strings[0] else strings[0] + '/' 54 | strings.drop(1).map { root + it } 55 | } 56 | 57 | val shaderProgram = ShaderProgram() 58 | 59 | val shaderCodes = shaders.map { shaderCodeOf(gl, context, it) } 60 | 61 | shaderCodes.forEach { shaderProgram.add(gl, it, System.err) } 62 | 63 | shaderProgram.link(gl, System.err) 64 | 65 | shaderCodes.forEach { 66 | glDetachShader(shaderProgram.program(), it.id()) 67 | glDeleteShader(it.id()) 68 | } 69 | 70 | return shaderProgram.program() 71 | } 72 | 73 | fun initializeVertexBuffer(gl: GL3) = with(gl) { 74 | 75 | glGenBuffer(vertexBufferObject) 76 | 77 | glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject) 78 | glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW) 79 | glBindBuffer(GL_ARRAY_BUFFER) 80 | } 81 | 82 | override fun display(gl: GL3) = with(gl) { 83 | 84 | glClearBufferf(GL_COLOR) 85 | 86 | glUseProgram(theProgram) 87 | 88 | glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject) 89 | glEnableVertexAttribArray(glf.pos4) 90 | glVertexAttribPointer(glf.pos4) 91 | 92 | glDrawArrays(3) 93 | 94 | glDisableVertexAttribArray(glf.pos4) 95 | glUseProgram() 96 | } 97 | 98 | public override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 99 | glViewport(w, h) 100 | } 101 | 102 | override fun end(gl: GL3) = with(gl) { 103 | 104 | glDeleteProgram(theProgram) 105 | glDeleteBuffer(vertexBufferObject) 106 | glDeleteVertexArray(vao) 107 | 108 | destroyBuffers(vertexBufferObject, vao, vertexData) 109 | } 110 | 111 | override fun keyPressed(keyEvent: KeyEvent) { 112 | 113 | when (keyEvent.keyCode) { 114 | KeyEvent.VK_ESCAPE -> quit() 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/kotlin/main/tut02/vertexColor.kt: -------------------------------------------------------------------------------- 1 | package main.tut02 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL2ES3.GL_COLOR 6 | import com.jogamp.opengl.GL3 7 | import glNext.* 8 | import glm.vec._4.Vec4 9 | import main.framework.Framework 10 | import main.framework.Semantic 11 | import uno.buffer.* 12 | import uno.glsl.programOf 13 | 14 | /** 15 | * Created by GBarbieri on 21.02.2017. 16 | */ 17 | 18 | fun main(args: Array) { 19 | VertexColor_().setup("Tutorial 02 - Vertex Colors") 20 | } 21 | 22 | class VertexColor_ : Framework() { 23 | 24 | val VERTEX_SHADER = "tut02/vertex-colors.vert" 25 | val FRAGMENT_SHADER = "tut02/vertex-colors.frag" 26 | 27 | var theProgram = 0 28 | val vertexBufferObject = intBufferBig(1) 29 | val vao = intBufferBig(1) 30 | val vertexData = floatBufferOf( 31 | +0.0f, +0.500f, 0.0f, 1.0f, 32 | +0.5f, -0.366f, 0.0f, 1.0f, 33 | -0.5f, -0.366f, 0.0f, 1.0f, 34 | +1.0f, +0.0f, 0.0f, 1.0f, 35 | +0.0f, +1.0f, 0.0f, 1.0f, 36 | +0.0f, +0.0f, 1.0f, 1.0f) 37 | 38 | override fun init(gl: GL3) = with(gl) { 39 | 40 | initializeProgram(gl) 41 | initializeVertexBuffer(gl) 42 | 43 | glGenVertexArray(vao) 44 | glBindVertexArray(vao) 45 | } 46 | 47 | fun initializeProgram(gl: GL3) { 48 | theProgram = programOf(gl, javaClass, "tut02", "vertex-colors.vert", "vertex-colors.frag") 49 | } 50 | 51 | fun initializeVertexBuffer(gl: GL3) = with(gl){ 52 | 53 | glGenBuffer(vertexBufferObject) 54 | 55 | glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject) 56 | glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW) 57 | glBindBuffer(GL_ARRAY_BUFFER) 58 | } 59 | 60 | override fun display(gl: GL3) = with(gl){ 61 | 62 | glClearBufferf(GL_COLOR, 0) 63 | 64 | glUseProgram(theProgram) 65 | 66 | glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject) 67 | glEnableVertexAttribArray(glf.pos4_col4) 68 | glEnableVertexAttribArray(glf.pos4_col4[1]) 69 | glVertexAttribPointer(glf.pos4_col4, 0) 70 | glVertexAttribPointer(glf.pos4_col4[1], Vec4.SIZE * 3) 71 | 72 | glDrawArrays(3) 73 | 74 | glDisableVertexAttribArray(glf.pos4_col4) 75 | glDisableVertexAttribArray(glf.pos4_col4[1]) 76 | glUseProgram() 77 | } 78 | 79 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl){ 80 | glViewport(w, h) 81 | } 82 | 83 | override fun end(gl: GL3) = with(gl) { 84 | 85 | glDeleteProgram(theProgram) 86 | glDeleteBuffer(vertexBufferObject) 87 | glDeleteVertexArray(vao) 88 | 89 | destroyBuffers(vertexBufferObject, vao, vertexData) 90 | } 91 | 92 | override fun keyPressed(keyEvent: KeyEvent) { 93 | 94 | when (keyEvent.keyCode) { 95 | KeyEvent.VK_ESCAPE -> quit() 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/kotlin/main/tut03/fragChangeColor.kt: -------------------------------------------------------------------------------- 1 | package main.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.GL_ARRAY_BUFFER 5 | import com.jogamp.opengl.GL.GL_STATIC_DRAW 6 | import com.jogamp.opengl.GL2ES3.GL_COLOR 7 | import com.jogamp.opengl.GL3 8 | import glNext.* 9 | import main.framework.Framework 10 | import uno.buffer.destroyBuffers 11 | import uno.buffer.floatBufferOf 12 | import uno.buffer.intBufferBig 13 | import uno.glsl.programOf 14 | 15 | /** 16 | * Created by elect on 21/02/17. 17 | */ 18 | 19 | fun main(args: Array) { 20 | FragChangeColor_().setup("Tutorial 03 - Frag Change Color") 21 | } 22 | 23 | class FragChangeColor_ : Framework() { 24 | 25 | var theProgram = 0 26 | var elapsedTimeUniform = 0 27 | val positionBufferObject = intBufferBig(1) 28 | val vao = intBufferBig(1) 29 | val vertexPositions = floatBufferOf( 30 | +0.25f, +0.25f, 0.0f, 1.0f, 31 | +0.25f, -0.25f, 0.0f, 1.0f, 32 | -0.25f, -0.25f, 0.0f, 1.0f) 33 | var startingTime = 0L 34 | 35 | override fun init(gl: GL3) = with(gl) { 36 | 37 | initializeProgram(gl) 38 | initializeVertexBuffer(gl) 39 | 40 | glGenVertexArrays(1, vao) 41 | glBindVertexArray(vao[0]) 42 | 43 | startingTime = System.currentTimeMillis() 44 | } 45 | 46 | fun initializeProgram(gl: GL3) = with(gl) { 47 | 48 | theProgram = programOf(gl, javaClass, "tut03", "calc-offset.vert", "calc-color.frag") 49 | 50 | elapsedTimeUniform = glGetUniformLocation(theProgram, "time") 51 | 52 | val loopDurationUnf = glGetUniformLocation(theProgram, "loopDuration") 53 | val fragLoopDurUnf = glGetUniformLocation(theProgram, "fragLoopDuration") 54 | 55 | glUseProgram(theProgram) 56 | glUniform1f(loopDurationUnf, 5f) 57 | glUniform1f(fragLoopDurUnf, 10f) 58 | glUseProgram() 59 | } 60 | 61 | fun initializeVertexBuffer(gl: GL3) = with(gl) { 62 | 63 | glGenBuffer(positionBufferObject) 64 | 65 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 66 | glBufferData(GL_ARRAY_BUFFER, vertexPositions, GL_STATIC_DRAW) 67 | glBindBuffer(GL_ARRAY_BUFFER) 68 | } 69 | 70 | override fun display(gl: GL3) = with(gl) { 71 | 72 | glClearBufferf(GL_COLOR, 0) 73 | 74 | glUseProgram(theProgram) 75 | 76 | glUniform1f(elapsedTimeUniform, (System.currentTimeMillis() - startingTime) / 1_000f) 77 | 78 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 79 | glEnableVertexAttribArray(glf.pos4) 80 | glVertexAttribPointer(glf.pos4) 81 | 82 | glDrawArrays(3) 83 | 84 | glDisableVertexAttribArray(glf.pos4) 85 | 86 | glUseProgram() 87 | } 88 | 89 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl){ 90 | glViewport(w, h) 91 | } 92 | 93 | override fun end(gl: GL3) = with(gl){ 94 | 95 | glDeleteProgram(theProgram) 96 | glDeleteBuffers(positionBufferObject) 97 | glDeleteVertexArrays(vao) 98 | 99 | destroyBuffers(positionBufferObject, vao, vertexPositions) 100 | } 101 | 102 | override fun keyPressed(keyEvent: KeyEvent) { 103 | 104 | when (keyEvent.keyCode) { 105 | KeyEvent.VK_ESCAPE -> quit() 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /src/main/kotlin/main/tut03/vertCalcOffset.kt: -------------------------------------------------------------------------------- 1 | package main.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL2ES3.GL_COLOR 6 | import com.jogamp.opengl.GL3 7 | import glNext.* 8 | import glm.vec._4.Vec4 9 | import main.framework.Framework 10 | import main.framework.Semantic 11 | import uno.buffer.destroyBuffers 12 | import uno.buffer.floatBufferOf 13 | import uno.buffer.intBufferBig 14 | import uno.glsl.programOf 15 | 16 | /** 17 | * Created by elect on 21/02/17. 18 | */ 19 | 20 | fun main(args: Array) { 21 | VertCalcOffset_().setup("Tutorial 03 - Shader Calc Offset") 22 | } 23 | 24 | class VertCalcOffset_ : Framework() { 25 | 26 | var theProgram = 0 27 | var elapsedTimeUniform = 0 28 | val positionBufferObject = intBufferBig(1) 29 | val vao = intBufferBig(1) 30 | val vertexPositions = floatBufferOf( 31 | +0.25f, +0.25f, 0.0f, 1.0f, 32 | +0.25f, -0.25f, 0.0f, 1.0f, 33 | -0.25f, -0.25f, 0.0f, 1.0f) 34 | var startingTime = 0L 35 | 36 | override fun init(gl: GL3) = with(gl) { 37 | 38 | initializeProgram(gl) 39 | initializeVertexBuffer(gl) 40 | 41 | glGenVertexArray(vao) 42 | glBindVertexArray(vao) 43 | 44 | startingTime = System.currentTimeMillis() 45 | } 46 | 47 | fun initializeProgram(gl: GL3) = with(gl) { 48 | 49 | theProgram = programOf(gl, javaClass, "tut03", "calc-offset.vert", "standard.frag") 50 | 51 | elapsedTimeUniform = glGetUniformLocation(theProgram, "time") 52 | 53 | val loopDurationUnf = glGetUniformLocation(theProgram, "loopDuration") 54 | 55 | glUseProgram(theProgram) 56 | glUniform1f(loopDurationUnf, 5f) 57 | glUseProgram() 58 | } 59 | 60 | fun initializeVertexBuffer(gl: GL3) = with(gl) { 61 | 62 | glGenBuffer(positionBufferObject) 63 | 64 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 65 | glBufferData(GL_ARRAY_BUFFER, vertexPositions, GL_STATIC_DRAW) 66 | glBindBuffer(GL_ARRAY_BUFFER) 67 | } 68 | 69 | override fun display(gl: GL3) = with(gl) { 70 | 71 | glClearBufferf(GL_COLOR, 0) 72 | 73 | glUseProgram(theProgram) 74 | 75 | glUniform1f(elapsedTimeUniform, (System.currentTimeMillis() - startingTime) / 1_000.0f) 76 | 77 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 78 | glEnableVertexAttribArray(glf.pos4) 79 | glVertexAttribPointer(glf.pos4) 80 | 81 | glDrawArrays(3) 82 | 83 | glDisableVertexAttribArray(glf.pos4) 84 | 85 | glUseProgram() 86 | } 87 | 88 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl) { 89 | glViewport(w, h) 90 | } 91 | 92 | override fun end(gl: GL3) = with(gl) { 93 | 94 | glDeleteProgram(theProgram) 95 | glDeleteBuffer(positionBufferObject) 96 | glDeleteVertexArray(vao) 97 | 98 | destroyBuffers(positionBufferObject, vao) 99 | } 100 | 101 | override fun keyPressed(keyEvent: KeyEvent) { 102 | 103 | when (keyEvent.keyCode) { 104 | KeyEvent.VK_ESCAPE -> quit() 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/kotlin/main/tut03/vertPositionOffset.kt: -------------------------------------------------------------------------------- 1 | package main.tut03 2 | 3 | import com.jogamp.newt.event.KeyEvent 4 | import com.jogamp.opengl.GL.* 5 | import com.jogamp.opengl.GL2ES3.GL_COLOR 6 | import com.jogamp.opengl.GL3 7 | import glNext.* 8 | import glm.glm 9 | import glm.vec._2.Vec2 10 | import glm.vec._4.Vec4 11 | import main.framework.Framework 12 | import main.framework.Semantic 13 | import uno.buffer.destroyBuffers 14 | import uno.buffer.floatBufferOf 15 | import uno.buffer.intBufferBig 16 | import uno.glsl.programOf 17 | 18 | /** 19 | * Created by elect on 21/02/17. 20 | */ 21 | 22 | fun main(args: Array) { 23 | VertPositionOffset_().setup("Tutorial 03 - Shader Position Offset") 24 | } 25 | 26 | class VertPositionOffset_ : Framework() { 27 | 28 | var theProgram = 0 29 | var offsetLocation = 0 30 | val positionBufferObject = intBufferBig(1) 31 | val vao = intBufferBig(1) 32 | val vertexPositions = floatBufferOf( 33 | +0.25f, +0.25f, 0.0f, 1.0f, 34 | +0.25f, -0.25f, 0.0f, 1.0f, 35 | -0.25f, -0.25f, 0.0f, 1.0f) 36 | var startingTime = 0L 37 | 38 | override fun init(gl: GL3) = with(gl) { 39 | 40 | initializeProgram(gl) 41 | initializeVertexBuffer(gl) 42 | 43 | glGenVertexArray(vao) 44 | glBindVertexArray(vao) 45 | 46 | startingTime = System.currentTimeMillis() 47 | } 48 | 49 | fun initializeProgram(gl: GL3) = with(gl) { 50 | 51 | theProgram = programOf(gl, javaClass, "tut03", "position-offset.vert", "standard.frag") 52 | 53 | offsetLocation = glGetUniformLocation(theProgram, "offset") 54 | } 55 | 56 | fun initializeVertexBuffer(gl: GL3) = with(gl){ 57 | 58 | glGenBuffer(positionBufferObject) 59 | 60 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 61 | glBufferData(GL_ARRAY_BUFFER, vertexPositions, GL_STATIC_DRAW) 62 | glBindBuffer(GL_ARRAY_BUFFER) 63 | } 64 | 65 | override fun display(gl: GL3) = with(gl){ 66 | 67 | val offset = Vec2(0f) 68 | computePositionOffsets(offset) 69 | 70 | glClearBufferf(GL_COLOR) 71 | 72 | glUseProgram(theProgram) 73 | 74 | glUniform2f(offsetLocation, offset) 75 | 76 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) 77 | glEnableVertexAttribArray(glf.pos4) 78 | glVertexAttribPointer(glf.pos4) 79 | 80 | glDrawArrays(3) 81 | 82 | glDisableVertexAttribArray(glf.pos4) 83 | 84 | glUseProgram() 85 | } 86 | 87 | fun computePositionOffsets(offset: Vec2) { 88 | 89 | val loopDuration = 5.0f 90 | val scale = glm.PIf * 2f / loopDuration 91 | 92 | val elapsedTime = (System.currentTimeMillis() - startingTime) / 1_000f 93 | 94 | val currTimeThroughLoop = elapsedTime % loopDuration 95 | 96 | offset.x = glm.cos(currTimeThroughLoop * scale) * .5f 97 | offset.y = glm.sin(currTimeThroughLoop * scale) * .5f 98 | } 99 | 100 | override fun reshape(gl: GL3, w: Int, h: Int) = with(gl){ 101 | glViewport(w, h) 102 | } 103 | 104 | override fun end(gl: GL3) = with(gl) { 105 | 106 | glDeleteProgram(theProgram) 107 | glDeleteBuffer(positionBufferObject) 108 | glDeleteVertexArray(vao) 109 | 110 | destroyBuffers(positionBufferObject, vao, vertexPositions) 111 | } 112 | 113 | override fun keyPressed(keyEvent: KeyEvent) { 114 | 115 | when (keyEvent.keyCode) { 116 | KeyEvent.VK_ESCAPE -> quit() 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/main/resources/screenshots/jogl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/screenshots/jogl.png -------------------------------------------------------------------------------- /src/main/resources/tut01/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut01/shader.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = FRAG_COLOR) out vec4 outputColor; 6 | 7 | void main() 8 | { 9 | outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); 10 | } -------------------------------------------------------------------------------- /src/main/resources/tut01/shader.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | void main() 8 | { 9 | gl_Position = position; 10 | } -------------------------------------------------------------------------------- /src/main/resources/tut02/frag-position.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = FRAG_COLOR) out vec4 outputColor; 6 | 7 | void main() 8 | { 9 | float lerpValue = gl_FragCoord.y / 500.0f; 10 | 11 | outputColor = mix(vec4(1.0f, 1.0f, 1.0f, 1.0f), vec4(0.2f, 0.2, 0.2, 1.0f), lerpValue); 12 | } -------------------------------------------------------------------------------- /src/main/resources/tut02/frag-position.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | void main() 8 | { 9 | gl_Position = position; 10 | } -------------------------------------------------------------------------------- /src/main/resources/tut02/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut02/vertex-colors.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = theColor; 12 | } -------------------------------------------------------------------------------- /src/main/resources/tut02/vertex-colors.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | void main() 11 | { 12 | gl_Position = position; 13 | theColor = color; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut03/calc-color.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = FRAG_COLOR) out vec4 outputColor; 6 | 7 | uniform float fragLoopDuration; 8 | uniform float time; 9 | 10 | const vec4 firstColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); 11 | const vec4 secondColor = vec4(0.0f, 1.0f, 0.0f, 1.0f); 12 | 13 | void main() 14 | { 15 | float currentTime = mod(time, fragLoopDuration); 16 | float currentLerp = currentTime / fragLoopDuration; 17 | 18 | outputColor = mix(firstColor, secondColor, currentLerp); 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut03/calc-offset.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | uniform float loopDuration; 8 | uniform float time; 9 | 10 | void main() 11 | { 12 | float timeScale = 3.14159f * 2.0f / loopDuration; 13 | 14 | float currentTime = mod(time, loopDuration); 15 | vec4 totalOffset = vec4(cos(currentTime * timeScale) * 0.5f, sin(currentTime * timeScale) * 0.5f, 0.0f, 0.0f); 16 | 17 | gl_Position = position + totalOffset; 18 | } -------------------------------------------------------------------------------- /src/main/resources/tut03/position-offset.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | uniform vec2 offset; 8 | 9 | void main() 10 | { 11 | vec4 totalOffset = vec4(offset.x, offset.y, 0.0f, 0.0f); 12 | gl_Position = position + totalOffset; 13 | } -------------------------------------------------------------------------------- /src/main/resources/tut03/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut03/standard.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = FRAG_COLOR) out vec4 outputColor; 6 | 7 | void main() 8 | { 9 | outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); 10 | } -------------------------------------------------------------------------------- /src/main/resources/tut03/standard.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | void main() 8 | { 9 | gl_Position = position; 10 | } -------------------------------------------------------------------------------- /src/main/resources/tut04/manual-perspective.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform vec2 offset; 11 | uniform float zNear; 12 | uniform float zFar; 13 | uniform float frustumScale; 14 | 15 | void main() 16 | { 17 | vec4 cameraPos = position + vec4(offset.x, offset.y, 0.0f, 0.0f); 18 | vec4 clipPos; 19 | 20 | clipPos.xy = cameraPos.xy * frustumScale; 21 | 22 | clipPos.z = cameraPos.z * (zNear + zFar) / (zNear - zFar); 23 | clipPos.z += 2 * zNear * zFar / (zNear - zFar); 24 | 25 | clipPos.w = -cameraPos.z; 26 | 27 | gl_Position = clipPos; 28 | theColor = color; 29 | } -------------------------------------------------------------------------------- /src/main/resources/tut04/matrix-perspective.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform vec2 offset; 11 | uniform mat4 perspectiveMatrix; 12 | 13 | void main() 14 | { 15 | vec4 cameraPos = position + vec4(offset.x, offset.y, 0.0, 0.0); 16 | 17 | gl_Position = perspectiveMatrix * cameraPos; 18 | theColor = color; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/tut04/ortho-with-offset.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform vec2 offset; 11 | 12 | void main() 13 | { 14 | gl_Position = position + vec4(offset.x, offset.y, 0.0f, 0.0f); 15 | theColor = color; 16 | } -------------------------------------------------------------------------------- /src/main/resources/tut04/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut04/standard-colors.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = theColor; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/tut05/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut05/standard.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = theColor; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/tut05/standard.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform vec3 offset; 11 | uniform mat4 perspectiveMatrix; 12 | 13 | void main() 14 | { 15 | vec4 cameraPos = position + vec4(offset, 0.0f); 16 | 17 | gl_Position = perspectiveMatrix * cameraPos; 18 | theColor = color; 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut06/color-passthrough.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = theColor; 12 | } -------------------------------------------------------------------------------- /src/main/resources/tut06/pos-color-local-transform.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform mat4 cameraToClipMatrix; 11 | uniform mat4 modelToCameraMatrix; 12 | 13 | void main() 14 | { 15 | vec4 cameraPos = modelToCameraMatrix * position; 16 | gl_Position = cameraToClipMatrix * cameraPos; 17 | 18 | theColor = color; 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut06/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut07/UnitConeTint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0 0.866 0 7 | 0.5 0 0 8 | 0.48907381875731 0 0.1039557588888 9 | 0.45677280077542 0 0.20336815992623 10 | 0.40450865316151 0 0.29389241146627 11 | 0.33456556611288 0 0.37157217599218 12 | 0.2500003830126 0 0.43301248075957 13 | 0.15450900193016 0 0.47552809414644 14 | 0.052264847412855 0 0.49726088296277 15 | -0.052263527886268 0 0.49726102165048 16 | -0.15450774007312 0 0.47552850414828 17 | -0.24999923397422 0 0.43301314415651 18 | -0.33456458011157 0 0.37157306379065 19 | -0.40450787329018 0 0.29389348486527 20 | -0.45677226111814 0 0.20336937201315 21 | -0.48907354289964 0 0.10395705668972 22 | -0.49999999999824 0 1.3267948966764e-006 23 | -0.48907409461153 0 -0.10395446108714 24 | -0.45677334042948 0 -0.20336694783787 25 | -0.40450943302999 0 -0.2938913380652 26 | -0.33456655211184 0 -0.3715712881911 27 | -0.25000153204922 0 -0.43301181735958 28 | -0.15451026378611 0 -0.47552768414126 29 | -0.052266166939075 0 -0.49726074427155 30 | 0.052262208359312 0 -0.4972611603347 31 | 0.15450647821499 0 -0.47552891414676 32 | 0.24999808493408 0 -0.4330138075504 33 | 0.3345635941079 0 -0.37157395158649 34 | 0.40450709341601 0 -0.2938945582622 35 | 0.45677172145764 0 -0.20337058409865 36 | 0.48907326703854 0 -0.10395835448992 37 | 0 0 0 38 | 39 | 1 1 1 1 40 | 0.9 0.9 0.9 1 41 | 0.82 0.82 0.82 1 42 | 0.74 0.74 0.74 1 43 | 0.66 0.66 0.66 1 44 | 0.58 0.58 0.58 1 45 | 0.5 0.5 0.5 1 46 | 0.58 0.58 0.58 1 47 | 0.66 0.66 0.66 1 48 | 0.74 0.74 0.74 1 49 | 0.82 0.82 0.82 1 50 | 0.9 0.9 0.9 1 51 | 0.82 0.82 0.82 1 52 | 0.74 0.74 0.74 1 53 | 0.66 0.66 0.66 1 54 | 0.58 0.58 0.58 1 55 | 0.5 0.5 0.5 1 56 | 0.58 0.58 0.58 1 57 | 0.66 0.66 0.66 1 58 | 0.74 0.74 0.74 1 59 | 0.82 0.82 0.82 1 60 | 0.9 0.9 0.9 1 61 | 0.82 0.82 0.82 1 62 | 0.74 0.74 0.74 1 63 | 0.66 0.66 0.66 1 64 | 0.58 0.58 0.58 1 65 | 0.5 0.5 0.5 1 66 | 0.58 0.58 0.58 1 67 | 0.66 0.66 0.66 1 68 | 0.74 0.74 0.74 1 69 | 0.82 0.82 0.82 1 70 | 0.9 0.9 0.9 1 71 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 72 | 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 30 73 | -------------------------------------------------------------------------------- /src/main/resources/tut07/UnitCubeColor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 0 1 0 1 32 | 0 1 0 1 33 | 0 1 0 1 34 | 0 1 0 1 35 | 0 0 1 1 36 | 0 0 1 1 37 | 0 0 1 1 38 | 0 0 1 1 39 | 1 0 0 1 40 | 1 0 0 1 41 | 1 0 0 1 42 | 1 0 0 1 43 | 1 1 0 1 44 | 1 1 0 1 45 | 1 1 0 1 46 | 1 1 0 1 47 | 0 1 1 1 48 | 0 1 1 1 49 | 0 1 1 1 50 | 0 1 1 1 51 | 1 0 1 1 52 | 1 0 1 1 53 | 1 0 1 1 54 | 1 0 1 1 55 | 56 | 0 1 2 57 | 2 3 0 58 | 4 5 6 59 | 6 7 4 60 | 8 9 10 61 | 10 11 8 62 | 12 13 14 63 | 14 15 12 64 | 16 17 18 65 | 18 19 16 66 | 20 21 22 67 | 22 23 20 68 | -------------------------------------------------------------------------------- /src/main/resources/tut07/UnitCubeTint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 1 1 1 1 32 | 1 1 1 1 33 | 1 1 1 1 34 | 1 1 1 1 35 | 0.75 0.75 0.75 1 36 | 0.75 0.75 0.75 1 37 | 0.75 0.75 0.75 1 38 | 0.75 0.75 0.75 1 39 | 0.5 0.5 0.5 1 40 | 0.5 0.5 0.5 1 41 | 0.5 0.5 0.5 1 42 | 0.5 0.5 0.5 1 43 | 1 1 1 1 44 | 1 1 1 1 45 | 1 1 1 1 46 | 1 1 1 1 47 | 0.75 0.75 0.75 1 48 | 0.75 0.75 0.75 1 49 | 0.75 0.75 0.75 1 50 | 0.75 0.75 0.75 1 51 | 0.5 0.5 0.5 1 52 | 0.5 0.5 0.5 1 53 | 0.5 0.5 0.5 1 54 | 0.5 0.5 0.5 1 55 | 56 | 0 1 2 57 | 2 3 0 58 | 4 5 6 59 | 6 7 4 60 | 8 9 10 61 | 10 11 8 62 | 12 13 14 63 | 14 15 12 64 | 16 17 18 65 | 18 19 16 66 | 20 21 22 67 | 22 23 20 68 | -------------------------------------------------------------------------------- /src/main/resources/tut07/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 11 | 0 1 2 12 | 0 2 1 13 | 2 3 0 14 | 2 0 3 15 | -------------------------------------------------------------------------------- /src/main/resources/tut07/color-mult-uniform.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | uniform vec4 baseColor; 7 | 8 | layout (location = FRAG_COLOR) out vec4 outputColor; 9 | 10 | void main() 11 | { 12 | outputColor = theColor * baseColor; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/tut07/color-passthrough.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | smooth in vec4 theColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = theColor; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/tut07/color-uniform.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | uniform vec4 baseColor; 6 | 7 | layout (location = FRAG_COLOR) out vec4 outputColor; 8 | 9 | void main() 10 | { 11 | outputColor = baseColor; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/tut07/pos-color-world-transform-ubo.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout(std140, column_major) uniform; 6 | 7 | layout (location = POSITION) in vec4 position; 8 | layout (location = COLOR) in vec4 color; 9 | 10 | smooth out vec4 theColor; 11 | 12 | uniform GlobalMatrices 13 | { 14 | mat4 cameraToClipMatrix; 15 | mat4 worldToCameraMatrix; 16 | }; 17 | 18 | uniform mat4 modelToWorldMatrix; 19 | 20 | void main() 21 | { 22 | vec4 temp = modelToWorldMatrix * position; 23 | temp = worldToCameraMatrix * temp; 24 | gl_Position = cameraToClipMatrix * temp; 25 | theColor = color; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/tut07/pos-color-world-transform.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | layout (location = COLOR) in vec4 color; 7 | 8 | smooth out vec4 theColor; 9 | 10 | uniform mat4 cameraToClipMatrix; 11 | uniform mat4 worldToCameraMatrix; 12 | uniform mat4 modelToWorldMatrix; 13 | 14 | void main() 15 | { 16 | vec4 temp = modelToWorldMatrix * position; 17 | temp = worldToCameraMatrix * temp; 18 | gl_Position = cameraToClipMatrix * temp; 19 | theColor = color; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/tut07/pos-only-world-transform-ubo.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout(std140, column_major) uniform; 6 | 7 | layout (location = POSITION) in vec4 position; 8 | 9 | uniform GlobalMatrices 10 | { 11 | mat4 cameraToClipMatrix; 12 | mat4 worldToCameraMatrix; 13 | }; 14 | 15 | uniform mat4 modelToWorldMatrix; 16 | 17 | void main() 18 | { 19 | vec4 temp = modelToWorldMatrix * position; 20 | temp = worldToCameraMatrix * temp; 21 | gl_Position = cameraToClipMatrix * temp; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/tut07/pos-only-world-transform.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | layout (location = POSITION) in vec4 position; 6 | 7 | uniform mat4 cameraToClipMatrix; 8 | uniform mat4 worldToCameraMatrix; 9 | uniform mat4 modelToWorldMatrix; 10 | 11 | void main() 12 | { 13 | vec4 temp = modelToWorldMatrix * position; 14 | temp = worldToCameraMatrix * temp; 15 | gl_Position = cameraToClipMatrix * temp; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/tut07/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut08/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 11 | 1 1 1 1 12 | 1 1 1 1 13 | 1 1 1 1 14 | 1 1 1 1 15 | 16 | 0 1 2 17 | 0 2 1 18 | 2 3 0 19 | 2 0 3 20 | -------------------------------------------------------------------------------- /src/main/resources/tut08/color-mult-uniform.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | smooth in vec4 theColor; 7 | uniform vec4 baseColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = theColor * baseColor; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/tut08/pos-color-local-transform.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | #include semantic.glsl 4 | 5 | 6 | layout (location = POSITION) in vec4 position; 7 | layout (location = COLOR) in vec4 color; 8 | 9 | smooth out vec4 theColor; 10 | 11 | uniform mat4 cameraToClipMatrix; 12 | uniform mat4 modelToCameraMatrix; 13 | 14 | void main() 15 | { 16 | vec4 cameraPos = modelToCameraMatrix * position; 17 | gl_Position = cameraToClipMatrix * cameraPos; 18 | theColor = color; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/tut08/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut09/LargePlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 3 0 -3 7 | 3 0 3 8 | -3 0 3 9 | -3 0 -3 10 | 3 0 -3 11 | 3 0 3 12 | -3 0 3 13 | -3 0 -3 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut09/color-passthrough.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | smooth in vec4 interpColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = interpColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut09/dir-amb-vertex-lighting-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout (location = POSITION) in vec3 position; 8 | layout (location = COLOR) in vec4 diffuseColor; 9 | layout (location = NORMAL) in vec3 normal; 10 | 11 | smooth out vec4 interpColor; 12 | 13 | uniform vec3 dirToLight; 14 | uniform vec4 lightIntensity; 15 | uniform vec4 ambientIntensity; 16 | 17 | uniform mat4 modelToCameraMatrix; 18 | uniform mat3 normalModelToCameraMatrix; 19 | 20 | layout(std140) uniform Projection 21 | { 22 | mat4 cameraToClipMatrix; 23 | }; 24 | 25 | void main() 26 | { 27 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 28 | 29 | vec3 normalCameraSpace = normalize(normalModelToCameraMatrix * normal); 30 | 31 | float cosAngIncidence = dot(normalCameraSpace, dirToLight); 32 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 33 | 34 | interpColor = (diffuseColor * lightIntensity * cosAngIncidence) + (diffuseColor * ambientIntensity); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/tut09/dir-amb-vertex-lighting-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout (location = POSITION) in vec3 position; 8 | layout (location = NORMAL) in vec3 normal; 9 | 10 | smooth out vec4 interpColor; 11 | 12 | uniform vec3 dirToLight; 13 | uniform vec4 lightIntensity; 14 | uniform vec4 ambientIntensity; 15 | 16 | uniform mat4 modelToCameraMatrix; 17 | uniform mat3 normalModelToCameraMatrix; 18 | 19 | layout(std140) uniform Projection 20 | { 21 | mat4 cameraToClipMatrix; 22 | }; 23 | 24 | void main() 25 | { 26 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 27 | 28 | vec3 normalCameraSpace = normalize(normalModelToCameraMatrix * normal); 29 | 30 | float cosAngIncidence = dot(normalCameraSpace, dirToLight); 31 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 32 | 33 | interpColor = (lightIntensity * cosAngIncidence) + ambientIntensity; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/tut09/dir-vertex-lighting-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout (location = POSITION) in vec3 position; 8 | layout (location = COLOR) in vec4 diffuseColor; 9 | layout (location = NORMAL) in vec3 normal; 10 | 11 | smooth out vec4 interpColor; 12 | 13 | uniform vec3 dirToLight; 14 | uniform vec4 lightIntensity; 15 | 16 | uniform mat4 modelToCameraMatrix; 17 | uniform mat3 normalModelToCameraMatrix; 18 | 19 | layout(std140) uniform Projection 20 | { 21 | mat4 cameraToClipMatrix; 22 | }; 23 | 24 | void main() 25 | { 26 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 27 | 28 | vec3 normalCamSpace = normalize(normalModelToCameraMatrix * normal); 29 | 30 | float cosIncidenceAngle = dot(normalCamSpace, dirToLight); 31 | 32 | cosIncidenceAngle = clamp(cosIncidenceAngle, 0, 1); 33 | 34 | interpColor = lightIntensity * diffuseColor * cosIncidenceAngle; 35 | } -------------------------------------------------------------------------------- /src/main/resources/tut09/dir-vertex-lighting-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | smooth out vec4 interpColor; 11 | 12 | uniform vec3 dirToLight; 13 | uniform vec4 lightIntensity; 14 | 15 | uniform mat4 modelToCameraMatrix; 16 | uniform mat3 normalModelToCameraMatrix; 17 | 18 | layout(std140) uniform Projection 19 | { 20 | mat4 cameraToClipMatrix; 21 | }; 22 | 23 | void main() 24 | { 25 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 26 | 27 | vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal); 28 | 29 | float cosIncidenceAngle = dot(normCamSpace, dirToLight); 30 | 31 | cosIncidenceAngle = clamp(cosIncidenceAngle, 0, 1); 32 | 33 | interpColor = lightIntensity * cosIncidenceAngle; 34 | } -------------------------------------------------------------------------------- /src/main/resources/tut09/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut10/LargePlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 30 0 -30 7 | 30 0 30 8 | -30 0 30 9 | -30 0 -30 10 | 30 0 -30 11 | 30 0 30 12 | -30 0 30 13 | -30 0 -30 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut10/UnitCube.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 0 1 0 1 32 | 0 1 0 1 33 | 0 1 0 1 34 | 0 1 0 1 35 | 0 0 1 1 36 | 0 0 1 1 37 | 0 0 1 1 38 | 0 0 1 1 39 | 1 0 0 1 40 | 1 0 0 1 41 | 1 0 0 1 42 | 1 0 0 1 43 | 1 1 0 1 44 | 1 1 0 1 45 | 1 1 0 1 46 | 1 1 0 1 47 | 0 1 1 1 48 | 0 1 1 1 49 | 0 1 1 1 50 | 0 1 1 1 51 | 1 0 1 1 52 | 1 0 1 1 53 | 1 0 1 1 54 | 1 0 1 1 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 0 1 2 64 | 2 3 0 65 | 4 5 6 66 | 6 7 4 67 | 8 9 10 68 | 10 11 8 69 | 12 13 14 70 | 14 15 12 71 | 16 17 18 72 | 18 19 16 73 | 20 21 22 74 | 22 23 20 75 | -------------------------------------------------------------------------------- /src/main/resources/tut10/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 0.5 0 -0.5 11 | 0.5 0 0.5 12 | -0.5 0 0.5 13 | -0.5 0 -0.5 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut10/color-passthrough.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | smooth in vec4 interpColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = interpColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut10/frag-light-atten-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 diffuseColor; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec4 diffuseColor_; 12 | out vec3 vertexNormal; 13 | 14 | uniform mat4 modelToCameraMatrix; 15 | uniform mat3 normalModelToCameraMatrix; 16 | 17 | uniform Projection 18 | { 19 | mat4 cameraToClipMatrix; 20 | }; 21 | 22 | void main() 23 | { 24 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 25 | 26 | vertexNormal = normalModelToCameraMatrix * normal; 27 | diffuseColor_ = diffuseColor; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/tut10/frag-light-atten-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | out vec4 diffuseColor_; 11 | out vec3 vertexNormal; 12 | 13 | uniform mat4 modelToCameraMatrix; 14 | uniform mat3 normalModelToCameraMatrix; 15 | 16 | uniform Projection 17 | { 18 | mat4 cameraToClipMatrix; 19 | }; 20 | 21 | void main() 22 | { 23 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 24 | 25 | vertexNormal = normalModelToCameraMatrix * normal; 26 | diffuseColor_ = vec4(1.0); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/resources/tut10/frag-light-atten.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | 10 | layout (location = FRAG_COLOR) out vec4 outputColor; 11 | 12 | uniform vec3 modelSpaceLightPos; 13 | 14 | uniform vec4 lightIntensity; 15 | uniform vec4 ambientIntensity; 16 | 17 | uniform vec3 cameraSpaceLightPos; 18 | 19 | uniform float lightAttenuation; 20 | uniform bool bUseRSquare; 21 | 22 | uniform UnProjection 23 | { 24 | mat4 clipToCameraMatrix; 25 | ivec2 windowSize; 26 | }; 27 | 28 | vec3 calcCameraSpacePosition() 29 | { 30 | vec4 ndcPos; 31 | ndcPos.xy = ((gl_FragCoord.xy / windowSize.xy) * 2.0) - 1.0; 32 | ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / (gl_DepthRange.far - gl_DepthRange.near); 33 | ndcPos.w = 1.0; 34 | 35 | vec4 clipPos = ndcPos / gl_FragCoord.w; 36 | 37 | return vec3(clipToCameraMatrix * clipPos); 38 | } 39 | 40 | vec4 applyLightIntensity(in vec3 cameraSpacePosition, out vec3 lightDirection) 41 | { 42 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 43 | float lightDistanceSqr = dot(lightDifference, lightDifference); 44 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 45 | 46 | float distFactor = bUseRSquare ? lightDistanceSqr : sqrt(lightDistanceSqr); 47 | 48 | return lightIntensity * (1 / ( 1.0 + lightAttenuation * distFactor)); 49 | } 50 | 51 | void main() 52 | { 53 | vec3 cameraSpacePosition = calcCameraSpacePosition(); 54 | 55 | vec3 lightDir = vec3(0.0); 56 | vec4 attenIntensity = applyLightIntensity(cameraSpacePosition, lightDir); 57 | 58 | float cosAngIncidence = dot(normalize(vertexNormal), lightDir); 59 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 60 | 61 | outputColor = (diffuseColor_ * attenIntensity * cosAngIncidence) + (diffuseColor_ * ambientIntensity); 62 | } -------------------------------------------------------------------------------- /src/main/resources/tut10/fragment-lighting-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 diffuseColor; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec4 diffuseColor_; 12 | out vec3 vertexNormal; 13 | out vec3 modelSpacePosition; 14 | 15 | uniform mat4 modelToCameraMatrix; 16 | 17 | uniform Projection 18 | { 19 | mat4 cameraToClipMatrix; 20 | }; 21 | 22 | void main() 23 | { 24 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 25 | 26 | modelSpacePosition = position; 27 | vertexNormal = normal; 28 | diffuseColor_ = diffuseColor; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/tut10/fragment-lighting-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | out vec4 diffuseColor_; 11 | out vec3 vertexNormal; 12 | out vec3 modelSpacePosition; 13 | 14 | uniform mat4 modelToCameraMatrix; 15 | 16 | uniform Projection 17 | { 18 | mat4 cameraToClipMatrix; 19 | }; 20 | 21 | void main() 22 | { 23 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 24 | 25 | vertexNormal = normal; 26 | modelSpacePosition = position; 27 | diffuseColor_ = vec4(1.0); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/tut10/fragment-lighting.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | smooth in vec4 interpColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | in vec4 diffuseColor_; 12 | in vec3 vertexNormal; 13 | in vec3 modelSpacePosition; 14 | 15 | uniform vec3 modelSpaceLightPos; 16 | 17 | uniform vec4 lightIntensity; 18 | uniform vec4 ambientIntensity; 19 | 20 | void main() 21 | { 22 | vec3 lightDir = normalize(modelSpaceLightPos - modelSpacePosition); 23 | 24 | float cosAngIncidence = dot(normalize(vertexNormal), lightDir); 25 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 26 | 27 | outputColor = (diffuseColor_ * lightIntensity * cosAngIncidence) + (diffuseColor_ * ambientIntensity); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/tut10/model-pos-vertex-lighting-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 diffuseColor; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | smooth out vec4 interpColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | uniform vec4 lightIntensity; 15 | uniform vec4 ambientIntensity; 16 | 17 | uniform mat4 modelToCameraMatrix; 18 | 19 | uniform Projection 20 | { 21 | mat4 cameraToClipMatrix; 22 | }; 23 | 24 | void main() 25 | { 26 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 27 | 28 | vec3 dirToLight = normalize(modelSpaceLightPos - position); 29 | 30 | float cosAngIncidence = dot(normal, dirToLight); 31 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 32 | 33 | interpColor = (lightIntensity * cosAngIncidence * diffuseColor) + (ambientIntensity * diffuseColor); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/tut10/model-pos-vertex-lighting-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | smooth out vec4 interpColor; 11 | 12 | uniform vec3 modelSpaceLightPos; 13 | uniform vec4 lightIntensity; 14 | uniform vec4 ambientIntensity; 15 | 16 | uniform mat4 modelToCameraMatrix; 17 | 18 | uniform Projection 19 | { 20 | mat4 cameraToClipMatrix; 21 | }; 22 | 23 | void main() 24 | { 25 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 26 | 27 | vec3 dirToLight = normalize(modelSpaceLightPos - position); 28 | 29 | float cosAngIncidence = dot(normal, dirToLight); 30 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 31 | 32 | interpColor = (lightIntensity * cosAngIncidence) + ambientIntensity; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/tut10/pos-transform.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | 9 | uniform mat4 modelToCameraMatrix; 10 | 11 | layout(std140) uniform Projection 12 | { 13 | mat4 cameraToClipMatrix; 14 | }; 15 | 16 | void main() 17 | { 18 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut10/pos-vertex-lighting-PCN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 diffuseColor; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | smooth out vec4 interpColor; 12 | 13 | uniform vec3 lightPos; 14 | uniform vec4 lightIntensity; 15 | uniform vec4 ambientIntensity; 16 | 17 | uniform mat4 modelToCameraMatrix; 18 | uniform mat3 normalModelToCameraMatrix; 19 | 20 | uniform Projection 21 | { 22 | mat4 cameraToClipMatrix; 23 | }; 24 | 25 | void main() 26 | { 27 | vec4 cameraPosition = (modelToCameraMatrix * vec4(position, 1.0)); 28 | gl_Position = cameraToClipMatrix * cameraPosition; 29 | 30 | vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal); 31 | 32 | vec3 dirToLight = normalize(lightPos - vec3(cameraPosition)); 33 | 34 | float cosAngIncidence = dot(normCamSpace, dirToLight); 35 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 36 | 37 | interpColor = (diffuseColor * lightIntensity * cosAngIncidence) + (diffuseColor * ambientIntensity); 38 | } -------------------------------------------------------------------------------- /src/main/resources/tut10/pos-vertex-lighting-PN.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | smooth out vec4 interpColor; 11 | 12 | uniform vec3 lightPos; 13 | uniform vec4 lightIntensity; 14 | uniform vec4 ambientIntensity; 15 | 16 | uniform mat4 modelToCameraMatrix; 17 | uniform mat3 normalModelToCameraMatrix; 18 | 19 | uniform Projection 20 | { 21 | mat4 cameraToClipMatrix; 22 | }; 23 | 24 | void main() 25 | { 26 | vec4 cameraPosition = (modelToCameraMatrix * vec4(position, 1.0)); 27 | gl_Position = cameraToClipMatrix * cameraPosition; 28 | 29 | vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal); 30 | 31 | vec3 dirToLight = normalize(lightPos - vec3(cameraPosition)); 32 | 33 | float cosAngIncidence = dot(normCamSpace, dirToLight); 34 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 35 | 36 | interpColor = (lightIntensity * cosAngIncidence) + ambientIntensity; 37 | } -------------------------------------------------------------------------------- /src/main/resources/tut10/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut10/uniform-color.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | uniform vec4 objectColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = objectColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/LargePlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 30 0 -30 7 | 30 0 30 8 | -30 0 30 9 | -30 0 -30 10 | 30 0 -30 11 | 30 0 30 12 | -30 0 30 13 | -30 0 -30 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut11/UnitCube.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 0 1 0 1 32 | 0 1 0 1 33 | 0 1 0 1 34 | 0 1 0 1 35 | 0 0 1 1 36 | 0 0 1 1 37 | 0 0 1 1 38 | 0 0 1 1 39 | 1 0 0 1 40 | 1 0 0 1 41 | 1 0 0 1 42 | 1 0 0 1 43 | 1 1 0 1 44 | 1 1 0 1 45 | 1 1 0 1 46 | 1 1 0 1 47 | 0 1 1 1 48 | 0 1 1 1 49 | 0 1 1 1 50 | 0 1 1 1 51 | 1 0 1 1 52 | 1 0 1 1 53 | 1 0 1 1 54 | 1 0 1 1 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 0 1 2 64 | 2 3 0 65 | 4 5 6 66 | 6 7 4 67 | 8 9 10 68 | 10 11 8 69 | 12 13 14 70 | 14 15 12 71 | 16 17 18 72 | 18 19 16 73 | 20 21 22 74 | 22 23 20 75 | -------------------------------------------------------------------------------- /src/main/resources/tut11/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 0.5 0 -0.5 11 | 0.5 0 0.5 12 | -0.5 0 0.5 13 | -0.5 0 -0.5 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut11/blinn-lighting.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | float cosAngIncidence = dot(surfaceNormal, lightDir); 43 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 44 | 45 | vec3 viewDirection = normalize(-cameraSpacePosition); 46 | 47 | vec3 halfAngle = normalize(lightDir + viewDirection); 48 | float blinnTerm = dot(surfaceNormal, halfAngle); 49 | blinnTerm = clamp(blinnTerm, 0, 1); 50 | blinnTerm = cosAngIncidence != 0.0 ? blinnTerm : 0.0; 51 | blinnTerm = pow(blinnTerm, shininessFactor); 52 | 53 | outputColor = (diffuseColor_ * attenIntensity * cosAngIncidence) + 54 | (specularColor * attenIntensity * blinnTerm) + 55 | (diffuseColor_ * ambientIntensity); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/tut11/blinn-only.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | 43 | vec3 viewDirection = normalize(-cameraSpacePosition); 44 | 45 | vec3 halfAngle = normalize(lightDir + viewDirection); 46 | float blinnTerm = dot(surfaceNormal, halfAngle); 47 | blinnTerm = clamp(blinnTerm, 0, 1); 48 | blinnTerm = dot(surfaceNormal, lightDir) >= 0.0 ? blinnTerm : 0.0; 49 | blinnTerm = pow(blinnTerm, shininessFactor); 50 | 51 | outputColor = (specularColor * attenIntensity * blinnTerm) + 52 | (diffuseColor_ * ambientIntensity); 53 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/gaussian-lighting.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | float cosAngIncidence = dot(surfaceNormal, lightDir); 43 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 44 | 45 | vec3 viewDirection = normalize(-cameraSpacePosition); 46 | 47 | vec3 halfAngle = normalize(lightDir + viewDirection); 48 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 49 | float exponent = angleNormalHalf / shininessFactor; 50 | exponent = -(exponent * exponent); 51 | float gaussianTerm = exp(exponent); 52 | 53 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 54 | 55 | outputColor = (diffuseColor_ * attenIntensity * cosAngIncidence) + 56 | (specularColor * attenIntensity * gaussianTerm) + 57 | (diffuseColor_ * ambientIntensity); 58 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/gaussian-only.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | 43 | vec3 viewDirection = normalize(-cameraSpacePosition); 44 | 45 | vec3 halfAngle = normalize(lightDir + viewDirection); 46 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 47 | float exponent = angleNormalHalf / shininessFactor; 48 | exponent = -(exponent * exponent); 49 | float gaussianTerm = exp(exponent); 50 | 51 | gaussianTerm = dot(surfaceNormal, lightDir) >= 0.0 ? gaussianTerm : 0.0; 52 | 53 | outputColor = (specularColor * attenIntensity * gaussianTerm) + 54 | (diffuseColor_ * ambientIntensity); 55 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/no-phong.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | vec4 applyLightIntensity(in vec3 cameraSpacePosition, out vec3 lightDirection) 23 | { 24 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 25 | float lightDistanceSqr = dot(lightDifference, lightDifference); 26 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 27 | 28 | return lightIntensity * (1 / ( 1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 29 | } 30 | 31 | void main() 32 | { 33 | vec3 lightDir = vec3(0.0); 34 | vec4 attenIntensity = applyLightIntensity(cameraSpacePosition, lightDir); 35 | 36 | float cosAngIncidence = dot(normalize(vertexNormal), lightDir); 37 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 38 | 39 | outputColor = (diffuseColor_ * attenIntensity * cosAngIncidence) + (diffuseColor_ * ambientIntensity); 40 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/pcn.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 diffuseColor; 9 | layout(location = NORMAL) in vec3 normal; 10 | 11 | out vec4 diffuseColor_; 12 | out vec3 vertexNormal; 13 | out vec3 cameraSpacePosition; 14 | 15 | uniform mat4 modelToCameraMatrix; 16 | uniform mat3 normalModelToCameraMatrix; 17 | 18 | uniform Projection 19 | { 20 | mat4 cameraToClipMatrix; 21 | }; 22 | 23 | void main() 24 | { 25 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 26 | gl_Position = cameraToClipMatrix * tempCamPosition; 27 | 28 | vertexNormal = normalModelToCameraMatrix * normal; 29 | diffuseColor_ = diffuseColor; 30 | cameraSpacePosition = vec3(tempCamPosition); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/tut11/phong-lighting.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | float cosAngIncidence = dot(surfaceNormal, lightDir); 43 | cosAngIncidence = clamp(cosAngIncidence, 0, 1); 44 | 45 | vec3 viewDirection = normalize(-cameraSpacePosition); 46 | vec3 reflectDir = reflect(-lightDir, surfaceNormal); 47 | float phongTerm = dot(viewDirection, reflectDir); 48 | phongTerm = clamp(phongTerm, 0, 1); 49 | phongTerm = cosAngIncidence != 0.0 ? phongTerm : 0.0; 50 | phongTerm = pow(phongTerm, shininessFactor); 51 | 52 | 53 | outputColor = (diffuseColor_ * attenIntensity * cosAngIncidence) + 54 | (specularColor * attenIntensity * phongTerm) + 55 | (diffuseColor_ * ambientIntensity); 56 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/phong-only.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec4 diffuseColor_; 8 | in vec3 vertexNormal; 9 | in vec3 cameraSpacePosition; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | uniform vec3 modelSpaceLightPos; 14 | 15 | uniform vec4 lightIntensity; 16 | uniform vec4 ambientIntensity; 17 | 18 | uniform vec3 cameraSpaceLightPos; 19 | 20 | uniform float lightAttenuation; 21 | 22 | const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0); 23 | uniform float shininessFactor; 24 | 25 | 26 | float calcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection) 27 | { 28 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 29 | float lightDistanceSqr = dot(lightDifference, lightDifference); 30 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 31 | 32 | return (1 / (1.0 + lightAttenuation * sqrt(lightDistanceSqr))); 33 | } 34 | 35 | void main() 36 | { 37 | vec3 lightDir = vec3(0.0); 38 | float atten = calcAttenuation(cameraSpacePosition, lightDir); 39 | vec4 attenIntensity = atten * lightIntensity; 40 | 41 | vec3 surfaceNormal = normalize(vertexNormal); 42 | 43 | vec3 viewDirection = normalize(-cameraSpacePosition); 44 | vec3 reflectDir = normalize(reflect(-lightDir, surfaceNormal)); 45 | float phongTerm = dot(viewDirection, reflectDir); 46 | phongTerm = clamp(phongTerm, 0, 1); 47 | phongTerm = dot(surfaceNormal, lightDir) > 0.0 ? phongTerm : 0.0; 48 | phongTerm = pow(phongTerm, shininessFactor); 49 | 50 | outputColor = (specularColor * attenIntensity * phongTerm) + (diffuseColor_ * ambientIntensity); 51 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/pn.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | out vec4 diffuseColor_; 11 | out vec3 vertexNormal; 12 | out vec3 cameraSpacePosition; 13 | 14 | uniform mat4 modelToCameraMatrix; 15 | uniform mat3 normalModelToCameraMatrix; 16 | 17 | uniform vec4 baseDiffuseColor; 18 | 19 | uniform Projection 20 | { 21 | mat4 cameraToClipMatrix; 22 | }; 23 | 24 | void main() 25 | { 26 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 27 | gl_Position = cameraToClipMatrix * tempCamPosition; 28 | 29 | vertexNormal = normalModelToCameraMatrix * normal; 30 | diffuseColor_ = baseDiffuseColor; 31 | cameraSpacePosition = vec3(tempCamPosition); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/tut11/pos-transform.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | 9 | uniform mat4 modelToCameraMatrix; 10 | 11 | layout(std140) uniform Projection 12 | { 13 | mat4 cameraToClipMatrix; 14 | }; 15 | 16 | void main() 17 | { 18 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut11/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut11/uniform-color.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | uniform vec4 objectColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = objectColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/LargePlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 30 0 -30 7 | 30 0 30 8 | -30 0 30 9 | -30 0 -30 10 | 30 0 -30 11 | 30 0 30 12 | -30 0 30 13 | -30 0 -30 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut13/UnitCube.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0.5 0.5 7 | 0.5 -0.5 0.5 8 | -0.5 -0.5 0.5 9 | -0.5 0.5 0.5 10 | 0.5 0.5 0.5 11 | -0.5 0.5 0.5 12 | -0.5 0.5 -0.5 13 | 0.5 0.5 -0.5 14 | 0.5 0.5 0.5 15 | 0.5 0.5 -0.5 16 | 0.5 -0.5 -0.5 17 | 0.5 -0.5 0.5 18 | 0.5 0.5 -0.5 19 | -0.5 0.5 -0.5 20 | -0.5 -0.5 -0.5 21 | 0.5 -0.5 -0.5 22 | 0.5 -0.5 0.5 23 | 0.5 -0.5 -0.5 24 | -0.5 -0.5 -0.5 25 | -0.5 -0.5 0.5 26 | -0.5 0.5 0.5 27 | -0.5 -0.5 0.5 28 | -0.5 -0.5 -0.5 29 | -0.5 0.5 -0.5 30 | 31 | 0.25 1 0.25 1 32 | 0.25 1 0.25 1 33 | 0.25 1 0.25 1 34 | 0.25 1 0.25 1 35 | 0.5 0.5 1 1 36 | 0.5 0.5 1 1 37 | 0.5 0.5 1 1 38 | 0.5 0.5 1 1 39 | 1 0.5 0.5 1 40 | 1 0.5 0.5 1 41 | 1 0.5 0.5 1 42 | 1 0.5 0.5 1 43 | 1 1 0.5 1 44 | 1 1 0.5 1 45 | 1 1 0.5 1 46 | 1 1 0.5 1 47 | 0.5 1 1 1 48 | 0.5 1 1 1 49 | 0.5 1 1 1 50 | 0.5 1 1 1 51 | 1 0.5 1 1 52 | 1 0.5 1 1 53 | 1 0.5 1 1 54 | 1 0.5 1 1 55 | 56 | 0 0 1 57 | 0 0 1 58 | 0 0 1 59 | 0 0 1 60 | 0 1 0 61 | 0 1 0 62 | 0 1 0 63 | 0 1 0 64 | 1 0 0 65 | 1 0 0 66 | 1 0 0 67 | 1 0 0 68 | 0 0 -1 69 | 0 0 -1 70 | 0 0 -1 71 | 0 0 -1 72 | 0 -1 0 73 | 0 -1 0 74 | 0 -1 0 75 | 0 -1 0 76 | -1 0 0 77 | -1 0 0 78 | -1 0 0 79 | -1 0 0 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 0 1 2 98 | 2 3 0 99 | 4 5 6 100 | 6 7 4 101 | 8 9 10 102 | 10 11 8 103 | 12 13 14 104 | 14 15 12 105 | 16 17 18 106 | 18 19 16 107 | 20 21 22 108 | 22 23 20 109 | -------------------------------------------------------------------------------- /src/main/resources/tut13/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 0.5 0 -0.5 11 | 0.5 0 0.5 12 | -0.5 0 0.5 13 | -0.5 0 -0.5 14 | 15 | 0 1 0 16 | 0 1 0 17 | 0 1 0 18 | 0 1 0 19 | 0 -1 0 20 | 0 -1 0 21 | 0 -1 0 22 | 0 -1 0 23 | 24 | 0 1 2 25 | 2 3 0 26 | 4 6 5 27 | 6 4 7 28 | -------------------------------------------------------------------------------- /src/main/resources/tut13/basic-impostor.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec2 mapping; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | uniform float sphereRadius; 12 | uniform vec3 cameraSpherePos; 13 | 14 | layout(std140) uniform; 15 | 16 | uniform Material 17 | { 18 | vec4 diffuseColor; 19 | vec4 specularColor; 20 | float specularShininess; 21 | } mtl; 22 | 23 | struct PerLight 24 | { 25 | vec4 cameraSpaceLightPos; 26 | vec4 lightIntensity; 27 | }; 28 | 29 | const int NUMBER_OF_LIGHTS = 2; 30 | 31 | uniform Light 32 | { 33 | vec4 ambientIntensity; 34 | float lightAttenuation; 35 | PerLight lights[NUMBER_OF_LIGHTS]; 36 | } lgt; 37 | 38 | 39 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 40 | { 41 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 42 | float lightDistanceSqr = dot(lightDifference, lightDifference); 43 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 44 | 45 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 46 | } 47 | 48 | uniform Projection 49 | { 50 | mat4 cameraToClipMatrix; 51 | }; 52 | 53 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal) 54 | { 55 | vec3 lightDir; 56 | vec4 lightIntensity; 57 | if(lightData.cameraSpaceLightPos.w == 0.0) 58 | { 59 | lightDir = vec3(lightData.cameraSpaceLightPos); 60 | lightIntensity = lightData.lightIntensity; 61 | } 62 | else 63 | { 64 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 65 | lightIntensity = atten * lightData.lightIntensity; 66 | } 67 | 68 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 69 | float cosAngIncidence = dot(surfaceNormal, lightDir); 70 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 71 | 72 | vec3 viewDirection = normalize(-cameraSpacePosition); 73 | 74 | vec3 halfAngle = normalize(lightDir + viewDirection); 75 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 76 | float exponent = angleNormalHalf / mtl.specularShininess; 77 | exponent = -(exponent * exponent); 78 | float gaussianTerm = exp(exponent); 79 | 80 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 81 | 82 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 83 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 84 | 85 | return lighting; 86 | } 87 | 88 | void impostor(out vec3 cameraPos, out vec3 cameraNormal) 89 | { 90 | float lensqr = dot(mapping, mapping); 91 | if(lensqr > 1.0) 92 | discard; 93 | 94 | cameraNormal = vec3(mapping, sqrt(1.0 - lensqr)); 95 | cameraPos = (cameraNormal * sphereRadius) + cameraSpherePos; 96 | } 97 | 98 | void main() 99 | { 100 | vec3 cameraPos; 101 | vec3 cameraNormal; 102 | 103 | impostor(cameraPos, cameraNormal); 104 | 105 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 106 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 107 | { 108 | accumLighting += computeLighting(lgt.lights[light], cameraPos, cameraNormal); 109 | } 110 | 111 | outputColor = sqrt(accumLighting); //2.0 gamma correction 112 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/basic-impostor.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | 5 | layout(std140) uniform; 6 | 7 | out vec2 mapping; 8 | 9 | uniform Projection 10 | { 11 | mat4 cameraToClipMatrix; 12 | }; 13 | 14 | uniform float sphereRadius; 15 | uniform vec3 cameraSpherePos; 16 | 17 | void main() 18 | { 19 | vec2 offset; 20 | switch(gl_VertexID) 21 | { 22 | //Bottom-left 23 | case 0: 24 | mapping = vec2(-1.0, -1.0); 25 | offset = vec2(-sphereRadius, -sphereRadius); 26 | break; 27 | //Top-left 28 | case 1: 29 | mapping = vec2(-1.0, 1.0); 30 | offset = vec2(-sphereRadius, sphereRadius); 31 | break; 32 | //Bottom-right 33 | case 2: 34 | mapping = vec2(1.0, -1.0); 35 | offset = vec2(sphereRadius, -sphereRadius); 36 | break; 37 | //Top-right 38 | case 3: 39 | mapping = vec2(1.0, 1.0); 40 | offset = vec2(sphereRadius, sphereRadius); 41 | break; 42 | } 43 | 44 | vec4 cameraCornerPos = vec4(cameraSpherePos, 1.0); 45 | cameraCornerPos.xy += offset; 46 | 47 | gl_Position = cameraToClipMatrix * cameraCornerPos; 48 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/depth-impostor.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | 5 | layout(std140) uniform; 6 | 7 | out vec2 mapping; 8 | 9 | uniform Projection 10 | { 11 | mat4 cameraToClipMatrix; 12 | }; 13 | 14 | uniform float sphereRadius; 15 | uniform vec3 cameraSpherePos; 16 | 17 | const float BOX_CORRECTION = 1.5; 18 | 19 | void main() 20 | { 21 | vec2 offset; 22 | switch(gl_VertexID) 23 | { 24 | //Bottom-left 25 | case 0: 26 | mapping = vec2(-1.0, -1.0) * BOX_CORRECTION; 27 | offset = vec2(-sphereRadius, -sphereRadius); 28 | break; 29 | //Top-left 30 | case 1: 31 | mapping = vec2(-1.0, 1.0) * BOX_CORRECTION; 32 | offset = vec2(-sphereRadius, sphereRadius); 33 | break; 34 | //Bottom-right 35 | case 2: 36 | mapping = vec2(1.0, -1.0) * BOX_CORRECTION; 37 | offset = vec2(sphereRadius, -sphereRadius); 38 | break; 39 | //Top-right 40 | case 3: 41 | mapping = vec2(1.0, 1.0) * BOX_CORRECTION; 42 | offset = vec2(sphereRadius, sphereRadius); 43 | break; 44 | } 45 | 46 | vec4 cameraCornerPos = vec4(cameraSpherePos, 1.0); 47 | cameraCornerPos.xy += offset * BOX_CORRECTION; 48 | 49 | gl_Position = cameraToClipMatrix * cameraCornerPos; 50 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/geom-impostor.geom: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | // fix a compiler bug for NVIDIA's OpenGL. It should not be necessary. 5 | #extension GL_EXT_gpu_shader4 : enable 6 | 7 | #include semantic.glsl 8 | 9 | layout (std140) uniform; 10 | layout (points) in; 11 | layout (triangle_strip, max_vertices = 4) out; 12 | 13 | uniform Projection 14 | { 15 | mat4 cameraToClipMatrix; 16 | }; 17 | 18 | in VertexData 19 | { 20 | vec3 cameraSpherePos; 21 | float sphereRadius; 22 | } vertexData[]; 23 | 24 | out FragData 25 | { 26 | flat vec3 cameraSpherePos; 27 | flat float sphereRadius; 28 | smooth vec2 mapping; 29 | }; 30 | 31 | const float boxCorrection = 1.5; 32 | 33 | void main() 34 | { 35 | vec4 cameraCornerPos; 36 | 37 | //Bottom-left 38 | mapping = vec2(-1.0, -1.0) * boxCorrection; 39 | cameraSpherePos = vec3(vertexData[0].cameraSpherePos); 40 | sphereRadius = vertexData[0].sphereRadius; 41 | cameraCornerPos = vec4(vertexData[0].cameraSpherePos, 1.0); 42 | cameraCornerPos.xy += vec2(-vertexData[0].sphereRadius, -vertexData[0].sphereRadius) * boxCorrection; 43 | gl_Position = cameraToClipMatrix * cameraCornerPos; 44 | gl_PrimitiveID = gl_PrimitiveIDIn; 45 | EmitVertex(); 46 | 47 | //Top-left 48 | mapping = vec2(-1.0, 1.0) * boxCorrection; 49 | cameraSpherePos = vec3(vertexData[0].cameraSpherePos); 50 | sphereRadius = vertexData[0].sphereRadius; 51 | cameraCornerPos = vec4(vertexData[0].cameraSpherePos, 1.0); 52 | cameraCornerPos.xy += vec2(-vertexData[0].sphereRadius, vertexData[0].sphereRadius) * boxCorrection; 53 | gl_Position = cameraToClipMatrix * cameraCornerPos; 54 | gl_PrimitiveID = gl_PrimitiveIDIn; 55 | EmitVertex(); 56 | 57 | //Bottom-right 58 | mapping = vec2(1.0, -1.0) * boxCorrection; 59 | cameraSpherePos = vec3(vertexData[0].cameraSpherePos); 60 | sphereRadius = vertexData[0].sphereRadius; 61 | cameraCornerPos = vec4(vertexData[0].cameraSpherePos, 1.0); 62 | cameraCornerPos.xy += vec2(vertexData[0].sphereRadius, -vertexData[0].sphereRadius) * boxCorrection; 63 | gl_Position = cameraToClipMatrix * cameraCornerPos; 64 | gl_PrimitiveID = gl_PrimitiveIDIn; 65 | EmitVertex(); 66 | 67 | //Top-right 68 | mapping = vec2(1.0, 1.0) * boxCorrection; 69 | cameraSpherePos = vec3(vertexData[0].cameraSpherePos); 70 | sphereRadius = vertexData[0].sphereRadius; 71 | cameraCornerPos = vec4(vertexData[0].cameraSpherePos, 1.0); 72 | cameraCornerPos.xy += vec2(vertexData[0].sphereRadius, vertexData[0].sphereRadius) * boxCorrection; 73 | gl_Position = cameraToClipMatrix * cameraCornerPos; 74 | gl_PrimitiveID = gl_PrimitiveIDIn; 75 | EmitVertex(); 76 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/geom-impostor.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = CAMERA_SPHERE_POS) in vec3 cameraSpherePos; 8 | layout(location = SPHERE_RADIUS) in float sphereRadius; 9 | 10 | out VertexData 11 | { 12 | vec3 cameraSpherePos; 13 | float sphereRadius; 14 | } vertexData; 15 | 16 | void main() 17 | { 18 | vertexData.cameraSpherePos = cameraSpherePos; 19 | vertexData.sphereRadius = sphereRadius; 20 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/lighting.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | 10 | layout (location = FRAG_COLOR) out vec4 outputColor; 11 | 12 | layout(std140) uniform; 13 | 14 | uniform Material 15 | { 16 | vec4 diffuseColor; 17 | vec4 specularColor; 18 | float specularShininess; 19 | } mtl; 20 | 21 | struct PerLight 22 | { 23 | vec4 cameraSpaceLightPos; 24 | vec4 lightIntensity; 25 | }; 26 | 27 | const int NUMBER_OF_LIGHTS = 2; 28 | 29 | uniform Light 30 | { 31 | vec4 ambientIntensity; 32 | float lightAttenuation; 33 | PerLight lights[NUMBER_OF_LIGHTS]; 34 | } lgt; 35 | 36 | 37 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 38 | { 39 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 40 | float lightDistanceSqr = dot(lightDifference, lightDifference); 41 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 42 | 43 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 44 | } 45 | 46 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal) 47 | { 48 | vec3 lightDir; 49 | vec4 lightIntensity; 50 | if(lightData.cameraSpaceLightPos.w == 0.0) 51 | { 52 | lightDir = vec3(lightData.cameraSpaceLightPos); 53 | lightIntensity = lightData.lightIntensity; 54 | } 55 | else 56 | { 57 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 58 | lightIntensity = atten * lightData.lightIntensity; 59 | } 60 | 61 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 62 | float cosAngIncidence = dot(surfaceNormal, lightDir); 63 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 64 | 65 | vec3 viewDirection = normalize(-cameraSpacePosition); 66 | 67 | vec3 halfAngle = normalize(lightDir + viewDirection); 68 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 69 | float exponent = angleNormalHalf / mtl.specularShininess; 70 | exponent = -(exponent * exponent); 71 | float gaussianTerm = exp(exponent); 72 | 73 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 74 | 75 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 76 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 77 | 78 | return lighting; 79 | } 80 | 81 | void main() 82 | { 83 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 84 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 85 | { 86 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal); 87 | } 88 | 89 | outputColor = sqrt(accumLighting); //2.0 gamma correction 90 | } 91 | -------------------------------------------------------------------------------- /src/main/resources/tut13/persp-impostor.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | 5 | layout(std140) uniform; 6 | 7 | out vec2 mapping; 8 | 9 | uniform Projection 10 | { 11 | mat4 cameraToClipMatrix; 12 | }; 13 | 14 | uniform float sphereRadius; 15 | uniform vec3 cameraSpherePos; 16 | 17 | const float BOX_CORRECTION = 1.5; 18 | 19 | void main() 20 | { 21 | vec2 offset; 22 | switch(gl_VertexID) 23 | { 24 | //Bottom-left 25 | case 0: 26 | mapping = vec2(-1.0, -1.0) * BOX_CORRECTION; 27 | offset = vec2(-sphereRadius, -sphereRadius); 28 | break; 29 | //Top-left 30 | case 1: 31 | mapping = vec2(-1.0, 1.0) * BOX_CORRECTION; 32 | offset = vec2(-sphereRadius, sphereRadius); 33 | break; 34 | //Bottom-right 35 | case 2: 36 | mapping = vec2(1.0, -1.0) * BOX_CORRECTION; 37 | offset = vec2(sphereRadius, -sphereRadius); 38 | break; 39 | //Top-right 40 | case 3: 41 | mapping = vec2(1.0, 1.0) * BOX_CORRECTION; 42 | offset = vec2(sphereRadius, sphereRadius); 43 | break; 44 | } 45 | 46 | vec4 cameraCornerPos = vec4(cameraSpherePos, 1.0); 47 | cameraCornerPos.xy += offset * BOX_CORRECTION; 48 | 49 | gl_Position = cameraToClipMatrix * cameraCornerPos; 50 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/pn.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | out vec3 vertexNormal; 11 | out vec3 cameraSpacePosition; 12 | 13 | uniform Projection 14 | { 15 | mat4 cameraToClipMatrix; 16 | }; 17 | 18 | uniform mat4 modelToCameraMatrix; 19 | uniform mat3 normalModelToCameraMatrix; 20 | 21 | void main() 22 | { 23 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 24 | gl_Position = cameraToClipMatrix * tempCamPosition; 25 | 26 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 27 | cameraSpacePosition = vec3(tempCamPosition); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/tut13/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut13/unlit.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | uniform vec4 objectColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = objectColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut13/unlit.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | 9 | uniform mat4 modelToCameraMatrix; 10 | 11 | layout(std140) uniform Projection 12 | { 13 | mat4 cameraToClipMatrix; 14 | }; 15 | 16 | void main() 17 | { 18 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/FauxHallway.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -1 1 -2 7 | -1 -1 -2 8 | 1 -1 -2 9 | 1 1 -2 10 | -0.4 0.4 -2 11 | -0.4 -0.4 -2 12 | 0.4 -0.4 -2 13 | 0.4 0.4 -2 14 | -0.4 0.4 -2 15 | -0.4 -0.4 -2 16 | 0.4 -0.4 -2 17 | 0.4 0.4 -2 18 | -0.25 0.25 -2 19 | -0.25 -0.25 -2 20 | 0.25 -0.25 -2 21 | 0.25 0.25 -2 22 | 23 | 1 0 0 1 24 | 1 0 0 1 25 | 1 0 0 1 26 | 1 0 0 1 27 | 0.5 0.5 0 1 28 | 0.5 0.5 0 1 29 | 0.5 0.5 0 1 30 | 0.5 0.5 0 1 31 | 0.5 0.5 0 1 32 | 0.5 0.5 0 1 33 | 0.5 0.5 0 1 34 | 0.5 0.5 0 1 35 | 0 1 0 1 36 | 0 1 0 1 37 | 0 1 0 1 38 | 0 1 0 1 39 | 0 1 4 1 5 4 1 2 6 1 6 5 2 6 3 3 6 7 8 9 12 9 13 12 9 10 14 9 14 13 10 14 11 11 14 15 40 | -------------------------------------------------------------------------------- /src/main/resources/tut14/RealHallway.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -1 1 -2 7 | -1 -1 -2 8 | 1 -1 -2 9 | 1 1 -2 10 | -1 1 -5 11 | -1 -1 -5 12 | 1 -1 -5 13 | 1 1 -5 14 | -1 1 -5 15 | -1 -1 -5 16 | 1 -1 -5 17 | 1 1 -5 18 | -1 1 -8 19 | -1 -1 -8 20 | 1 -1 -8 21 | 1 1 -8 22 | 23 | 1 0 0 1 24 | 1 0 0 1 25 | 1 0 0 1 26 | 1 0 0 1 27 | 0.5 0.5 0 1 28 | 0.5 0.5 0 1 29 | 0.5 0.5 0 1 30 | 0.5 0.5 0 1 31 | 0.5 0.5 0 1 32 | 0.5 0.5 0 1 33 | 0.5 0.5 0 1 34 | 0.5 0.5 0 1 35 | 0 1 0 1 36 | 0 1 0 1 37 | 0 1 0 1 38 | 0 1 0 1 39 | 0 1 4 1 5 4 1 2 6 1 6 5 2 6 3 3 6 7 8 9 12 9 13 12 9 10 14 9 14 13 10 14 11 11 14 15 40 | -------------------------------------------------------------------------------- /src/main/resources/tut14/UnitPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 0 -0.5 7 | 0.5 0 0.5 8 | -0.5 0 0.5 9 | -0.5 0 -0.5 10 | 0.5 0 -0.5 11 | 0.5 0 0.5 12 | -0.5 0 0.5 13 | -0.5 0 -0.5 14 | 15 | 1 1 1 1 16 | 1 1 1 1 17 | 1 1 1 1 18 | 1 1 1 1 19 | 1 1 1 1 20 | 1 1 1 1 21 | 1 1 1 1 22 | 1 1 1 1 23 | 24 | 0 1 0 25 | 0 1 0 26 | 0 1 0 27 | 0 1 0 28 | 0 -1 0 29 | 0 -1 0 30 | 0 -1 0 31 | 0 -1 0 32 | 33 | 1 0 34 | 1 1 35 | 0 1 36 | 0 0 37 | 1 0 38 | 1 1 39 | 0 1 40 | 0 0 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 0 1 2 70 | 2 3 0 71 | 4 6 5 72 | 6 4 7 73 | -------------------------------------------------------------------------------- /src/main/resources/tut14/fixed-shininess.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | 10 | layout (location = FRAG_COLOR) out vec4 outputColor; 11 | 12 | layout(std140) uniform; 13 | 14 | uniform Material 15 | { 16 | vec4 diffuseColor; 17 | vec4 specularColor; 18 | float specularShininess; 19 | } mtl; 20 | 21 | struct PerLight 22 | { 23 | vec4 cameraSpaceLightPos; 24 | vec4 lightIntensity; 25 | }; 26 | 27 | const int NUMBER_OF_LIGHTS = 2; 28 | 29 | uniform Light 30 | { 31 | vec4 ambientIntensity; 32 | float lightAttenuation; 33 | PerLight lights[NUMBER_OF_LIGHTS]; 34 | } lgt; 35 | 36 | uniform sampler2D gaussianTexture; 37 | 38 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 39 | { 40 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 41 | float lightDistanceSqr = dot(lightDifference, lightDifference); 42 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 43 | 44 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 45 | } 46 | 47 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal) 48 | { 49 | vec3 lightDir; 50 | vec4 lightIntensity; 51 | if(lightData.cameraSpaceLightPos.w == 0.0) 52 | { 53 | lightDir = vec3(lightData.cameraSpaceLightPos); 54 | lightIntensity = lightData.lightIntensity; 55 | } 56 | else 57 | { 58 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 59 | lightIntensity = atten * lightData.lightIntensity; 60 | } 61 | 62 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 63 | float cosAngIncidence = dot(surfaceNormal, lightDir); 64 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 65 | 66 | vec3 viewDirection = normalize(-cameraSpacePosition); 67 | 68 | vec3 halfAngle = normalize(lightDir + viewDirection); 69 | vec2 texCoord; 70 | texCoord.s = dot(halfAngle, surfaceNormal); 71 | texCoord.t = mtl.specularShininess; 72 | float gaussianTerm = texture(gaussianTexture, texCoord).r; 73 | 74 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 75 | 76 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 77 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 78 | 79 | return lighting; 80 | } 81 | 82 | void main() 83 | { 84 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 85 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 86 | { 87 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal); 88 | } 89 | 90 | outputColor = sqrt(accumLighting); //2.0 gamma correction 91 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/main.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/tut14/main.dds -------------------------------------------------------------------------------- /src/main/resources/tut14/no-correct-vertex-colors.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | noperspective in vec4 theColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = theColor; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/tut14/no-correct-vertex-colors.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 color; 9 | 10 | noperspective out vec4 theColor; 11 | 12 | uniform mat4 cameraToClipMatrix; 13 | 14 | void main() 15 | { 16 | gl_Position = cameraToClipMatrix * vec4(position, 1.0); 17 | theColor = color; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/tut14/pn.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = NORMAL) in vec3 normal; 9 | 10 | out vec3 vertexNormal; 11 | out vec3 cameraSpacePosition; 12 | 13 | uniform Projection 14 | { 15 | mat4 cameraToClipMatrix; 16 | }; 17 | 18 | uniform mat4 modelToCameraMatrix; 19 | uniform mat3 normalModelToCameraMatrix; 20 | 21 | void main() 22 | { 23 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 24 | gl_Position = cameraToClipMatrix * tempCamPosition; 25 | 26 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 27 | cameraSpacePosition = vec3(tempCamPosition); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/tut14/pnt.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | layout(location = POSITION) in vec3 position; 7 | layout(location = NORMAL) in vec3 normal; 8 | layout(location = TEX_COORD) in vec2 texCoord; 9 | 10 | out vec3 vertexNormal; 11 | out vec3 cameraSpacePosition; 12 | out vec2 shinTexCoord; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | uniform mat3 normalModelToCameraMatrix; 21 | 22 | void main() 23 | { 24 | vec4 tempCamPosition = (modelToCameraMatrix * vec4(position, 1.0)); 25 | gl_Position = cameraToClipMatrix * tempCamPosition; 26 | 27 | vertexNormal = normalize(normalModelToCameraMatrix * normal); 28 | cameraSpacePosition = vec3(tempCamPosition); 29 | 30 | shinTexCoord = texCoord; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/tut14/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut14/shader-gaussian.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | 10 | layout (location = FRAG_COLOR) out vec4 outputColor; 11 | 12 | layout(std140) uniform; 13 | 14 | uniform Material 15 | { 16 | vec4 diffuseColor; 17 | vec4 specularColor; 18 | float specularShininess; 19 | } mtl; 20 | 21 | struct PerLight 22 | { 23 | vec4 cameraSpaceLightPos; 24 | vec4 lightIntensity; 25 | }; 26 | 27 | const int NUMBER_OF_LIGHTS = 2; 28 | 29 | uniform Light 30 | { 31 | vec4 ambientIntensity; 32 | float lightAttenuation; 33 | PerLight lights[NUMBER_OF_LIGHTS]; 34 | } lgt; 35 | 36 | 37 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 38 | { 39 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 40 | float lightDistanceSqr = dot(lightDifference, lightDifference); 41 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 42 | 43 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 44 | } 45 | 46 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal) 47 | { 48 | vec3 lightDir; 49 | vec4 lightIntensity; 50 | if(lightData.cameraSpaceLightPos.w == 0.0) 51 | { 52 | lightDir = vec3(lightData.cameraSpaceLightPos); 53 | lightIntensity = lightData.lightIntensity; 54 | } 55 | else 56 | { 57 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 58 | lightIntensity = atten * lightData.lightIntensity; 59 | } 60 | 61 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 62 | float cosAngIncidence = dot(surfaceNormal, lightDir); 63 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 64 | 65 | vec3 viewDirection = normalize(-cameraSpacePosition); 66 | 67 | vec3 halfAngle = normalize(lightDir + viewDirection); 68 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 69 | float exponent = angleNormalHalf / mtl.specularShininess; 70 | exponent = -(exponent * exponent); 71 | float gaussianTerm = exp(exponent); 72 | 73 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 74 | 75 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 76 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 77 | 78 | return lighting; 79 | } 80 | 81 | void main() 82 | { 83 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 84 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 85 | { 86 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal); 87 | } 88 | 89 | outputColor = sqrt(accumLighting); //2.0 gamma correction 90 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/smooth-vertex-colors.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | smooth in vec4 theColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = theColor; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/tut14/smooth-vertex-colors.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | layout(location = COLOR) in vec4 color; 9 | 10 | smooth out vec4 theColor; 11 | 12 | uniform mat4 cameraToClipMatrix; 13 | 14 | void main() 15 | { 16 | gl_Position = cameraToClipMatrix * vec4(position, 1.0); 17 | theColor = color; 18 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/texture-compute.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | in vec2 shinTexCoord; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | layout(std140) uniform; 14 | 15 | uniform Material 16 | { 17 | vec4 diffuseColor; 18 | vec4 specularColor; 19 | float specularShininess; 20 | } mtl; 21 | 22 | struct PerLight 23 | { 24 | vec4 cameraSpaceLightPos; 25 | vec4 lightIntensity; 26 | }; 27 | 28 | const int NUMBER_OF_LIGHTS = 2; 29 | 30 | uniform Light 31 | { 32 | vec4 ambientIntensity; 33 | float lightAttenuation; 34 | PerLight lights[NUMBER_OF_LIGHTS]; 35 | } lgt; 36 | 37 | uniform sampler2D shininessTexture; 38 | 39 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 40 | { 41 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 42 | float lightDistanceSqr = dot(lightDifference, lightDifference); 43 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 44 | 45 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 46 | } 47 | 48 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal, 49 | in float specularShininess) 50 | { 51 | vec3 lightDir; 52 | vec4 lightIntensity; 53 | if(lightData.cameraSpaceLightPos.w == 0.0) 54 | { 55 | lightDir = vec3(lightData.cameraSpaceLightPos); 56 | lightIntensity = lightData.lightIntensity; 57 | } 58 | else 59 | { 60 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 61 | lightIntensity = atten * lightData.lightIntensity; 62 | } 63 | 64 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 65 | float cosAngIncidence = dot(surfaceNormal, lightDir); 66 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 67 | 68 | vec3 viewDirection = normalize(-cameraSpacePosition); 69 | 70 | vec3 halfAngle = normalize(lightDir + viewDirection); 71 | float angleNormalHalf = acos(dot(halfAngle, surfaceNormal)); 72 | float exponent = angleNormalHalf / specularShininess; 73 | exponent = -(exponent * exponent); 74 | float gaussianTerm = exp(exponent); 75 | 76 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 77 | 78 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 79 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 80 | 81 | return lighting; 82 | } 83 | 84 | void main() 85 | { 86 | float specularShininess = texture(shininessTexture, shinTexCoord).r; 87 | 88 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 89 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 90 | { 91 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal, specularShininess); 92 | } 93 | 94 | outputColor = sqrt(accumLighting); //2.0 gamma correction 95 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/texture-gaussian.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | 10 | layout (location = FRAG_COLOR) out vec4 outputColor; 11 | 12 | layout(std140) uniform; 13 | 14 | uniform Material 15 | { 16 | vec4 diffuseColor; 17 | vec4 specularColor; 18 | float specularShininess; 19 | } mtl; 20 | 21 | struct PerLight 22 | { 23 | vec4 cameraSpaceLightPos; 24 | vec4 lightIntensity; 25 | }; 26 | 27 | const int NUMBER_OF_LIGHTS = 2; 28 | 29 | uniform Light 30 | { 31 | vec4 ambientIntensity; 32 | float lightAttenuation; 33 | PerLight lights[NUMBER_OF_LIGHTS]; 34 | } lgt; 35 | 36 | uniform sampler1D gaussianTexture; 37 | 38 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 39 | { 40 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 41 | float lightDistanceSqr = dot(lightDifference, lightDifference); 42 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 43 | 44 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 45 | } 46 | 47 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal) 48 | { 49 | vec3 lightDir; 50 | vec4 lightIntensity; 51 | if(lightData.cameraSpaceLightPos.w == 0.0) 52 | { 53 | lightDir = vec3(lightData.cameraSpaceLightPos); 54 | lightIntensity = lightData.lightIntensity; 55 | } 56 | else 57 | { 58 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 59 | lightIntensity = atten * lightData.lightIntensity; 60 | } 61 | 62 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 63 | float cosAngIncidence = dot(surfaceNormal, lightDir); 64 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 65 | 66 | vec3 viewDirection = normalize(-cameraSpacePosition); 67 | 68 | vec3 halfAngle = normalize(lightDir + viewDirection); 69 | float texCoord = dot(halfAngle, surfaceNormal); 70 | float gaussianTerm = texture(gaussianTexture, texCoord).r; 71 | 72 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 73 | 74 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 75 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 76 | 77 | return lighting; 78 | } 79 | 80 | void main() 81 | { 82 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 83 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 84 | { 85 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal); 86 | } 87 | 88 | outputColor = sqrt(accumLighting); //2.0 gamma correction 89 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/texture-shininess.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec3 vertexNormal; 8 | in vec3 cameraSpacePosition; 9 | in vec2 shinTexCoord; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | layout(std140) uniform; 14 | 15 | uniform Material 16 | { 17 | vec4 diffuseColor; 18 | vec4 specularColor; 19 | float specularShininess; 20 | } mtl; 21 | 22 | struct PerLight 23 | { 24 | vec4 cameraSpaceLightPos; 25 | vec4 lightIntensity; 26 | }; 27 | 28 | const int NUMBER_OF_LIGHTS = 2; 29 | 30 | uniform Light 31 | { 32 | vec4 ambientIntensity; 33 | float lightAttenuation; 34 | PerLight lights[NUMBER_OF_LIGHTS]; 35 | } lgt; 36 | 37 | uniform sampler2D gaussianTexture; 38 | uniform sampler2D shininessTexture; 39 | 40 | float calcAttenuation(in vec3 cameraSpacePosition, in vec3 cameraSpaceLightPos, out vec3 lightDirection) 41 | { 42 | vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition; 43 | float lightDistanceSqr = dot(lightDifference, lightDifference); 44 | lightDirection = lightDifference * inversesqrt(lightDistanceSqr); 45 | 46 | return (1 / (1.0 + lgt.lightAttenuation * lightDistanceSqr)); 47 | } 48 | 49 | vec4 computeLighting(in PerLight lightData, in vec3 cameraSpacePosition, in vec3 cameraSpaceNormal, 50 | in float specularShininess) 51 | { 52 | vec3 lightDir; 53 | vec4 lightIntensity; 54 | if(lightData.cameraSpaceLightPos.w == 0.0) 55 | { 56 | lightDir = vec3(lightData.cameraSpaceLightPos); 57 | lightIntensity = lightData.lightIntensity; 58 | } 59 | else 60 | { 61 | float atten = calcAttenuation(cameraSpacePosition, lightData.cameraSpaceLightPos.xyz, lightDir); 62 | lightIntensity = atten * lightData.lightIntensity; 63 | } 64 | 65 | vec3 surfaceNormal = normalize(cameraSpaceNormal); 66 | float cosAngIncidence = dot(surfaceNormal, lightDir); 67 | cosAngIncidence = cosAngIncidence < 0.0001 ? 0.0 : cosAngIncidence; 68 | 69 | vec3 viewDirection = normalize(-cameraSpacePosition); 70 | 71 | vec3 halfAngle = normalize(lightDir + viewDirection); 72 | vec2 texCoord; 73 | texCoord.s = dot(halfAngle, surfaceNormal); 74 | texCoord.t = specularShininess; 75 | float gaussianTerm = texture(gaussianTexture, texCoord).r; 76 | 77 | gaussianTerm = cosAngIncidence != 0.0 ? gaussianTerm : 0.0; 78 | 79 | vec4 lighting = mtl.diffuseColor * lightIntensity * cosAngIncidence; 80 | lighting += mtl.specularColor * lightIntensity * gaussianTerm; 81 | 82 | return lighting; 83 | } 84 | 85 | void main() 86 | { 87 | float specularShininess = texture(shininessTexture, shinTexCoord).r; 88 | 89 | vec4 accumLighting = mtl.diffuseColor * lgt.ambientIntensity; 90 | for(int light = 0; light < NUMBER_OF_LIGHTS; light++) 91 | { 92 | accumLighting += computeLighting(lgt.lights[light], cameraSpacePosition, vertexNormal, specularShininess); 93 | } 94 | 95 | outputColor = sqrt(accumLighting); //2.0 gamma correction 96 | } 97 | -------------------------------------------------------------------------------- /src/main/resources/tut14/unlit.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | uniform vec4 objectColor; 8 | 9 | layout (location = FRAG_COLOR) out vec4 outputColor; 10 | 11 | void main() 12 | { 13 | outputColor = objectColor; 14 | } -------------------------------------------------------------------------------- /src/main/resources/tut14/unlit.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(location = POSITION) in vec3 position; 8 | 9 | uniform mat4 modelToCameraMatrix; 10 | 11 | layout(std140) uniform Projection 12 | { 13 | mat4 cameraToClipMatrix; 14 | }; 15 | 16 | void main() 17 | { 18 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 19 | } -------------------------------------------------------------------------------- /src/main/resources/tut15/BigPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 64 0 -64 7 | 64 0 64 8 | -64 0 64 9 | -64 0 -64 10 | 64 0 -64 11 | 64 0 64 12 | -64 0 64 13 | -64 0 -64 14 | 15 | 64 -64 16 | 64 64 17 | -64 64 18 | -64 -64 19 | 64 -64 20 | 64 64 21 | -64 64 22 | -64 -64 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0 1 2 32 | 2 3 0 33 | 4 6 5 34 | 6 4 7 35 | -------------------------------------------------------------------------------- /src/main/resources/tut15/Corridor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1 0 -64 7 | 1 0 64 8 | -1 0 64 9 | -1 0 -64 10 | -1 0 -64 11 | -1 0 64 12 | -1 2 64 13 | -1 2 -64 14 | 1 0 64 15 | 1 0 -64 16 | 1 2 -64 17 | 1 2 64 18 | 1 2 64 19 | 1 2 -64 20 | -1 2 -64 21 | -1 2 64 22 | 23 | 1 -64 24 | 1 64 25 | -1 64 26 | -1 -64 27 | 1 -64 28 | 1 64 29 | -1 64 30 | -1 -64 31 | 1 -64 32 | 1 64 33 | -1 64 34 | -1 -64 35 | 1 -64 36 | 1 64 37 | -1 64 38 | -1 -64 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 0 1 2 48 | 2 3 0 49 | 4 5 6 50 | 6 7 4 51 | 8 9 10 52 | 10 11 8 53 | 12 13 14 54 | 14 15 12 55 | -------------------------------------------------------------------------------- /src/main/resources/tut15/checker.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/tut15/checker.dds -------------------------------------------------------------------------------- /src/main/resources/tut15/pt.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(std140) uniform; 8 | 9 | layout(location = POSITION) in vec3 position; 10 | layout(location = TEX_COORD) in vec2 texCoord; 11 | 12 | out vec2 colorCoord; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | 21 | void main() 22 | { 23 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 24 | colorCoord = texCoord; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/resources/tut15/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut15/tex.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec2 colorCoord; 8 | 9 | uniform sampler2D colorTexture; 10 | 11 | layout(location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | void main() 14 | { 15 | // outputColor = vec4(colorCoord, 0.0, 1.0); 16 | outputColor = texture(colorTexture, colorCoord); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/tut16/BigPlane.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 64 0 -64 7 | 64 0 64 8 | -64 0 64 9 | -64 0 -64 10 | 64 0 -64 11 | 64 0 64 12 | -64 0 64 13 | -64 0 -64 14 | 15 | 64 -64 16 | 64 64 17 | -64 64 18 | -64 -64 19 | 64 -64 20 | 64 64 21 | -64 64 22 | -64 -64 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0 1 2 32 | 2 3 0 33 | 4 6 5 34 | 6 4 7 35 | -------------------------------------------------------------------------------- /src/main/resources/tut16/Corridor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1 0 -64 7 | 1 0 64 8 | -1 0 64 9 | -1 0 -64 10 | -1 0 -64 11 | -1 0 64 12 | -1 2 64 13 | -1 2 -64 14 | 1 0 64 15 | 1 0 -64 16 | 1 2 -64 17 | 1 2 64 18 | 1 2 64 19 | 1 2 -64 20 | -1 2 -64 21 | -1 2 64 22 | 23 | 1 -64 24 | 1 64 25 | -1 64 26 | -1 -64 27 | 1 -64 28 | 1 64 29 | -1 64 30 | -1 -64 31 | 1 -64 32 | 1 64 33 | -1 64 34 | -1 -64 35 | 1 -64 36 | 1 64 37 | -1 64 38 | -1 -64 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 0 1 2 48 | 2 3 0 49 | 4 5 6 50 | 6 7 4 51 | 8 9 10 52 | 10 11 8 53 | 12 13 14 54 | 14 15 12 55 | -------------------------------------------------------------------------------- /src/main/resources/tut16/checker_gamma.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/tut16/checker_gamma.dds -------------------------------------------------------------------------------- /src/main/resources/tut16/checker_linear.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/tut16/checker_linear.dds -------------------------------------------------------------------------------- /src/main/resources/tut16/gamma_ramp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jvm-graphics-labs/modern-jogl-examples/cd39b32206ee20ca4be172f2deff38004293c610/src/main/resources/tut16/gamma_ramp.png -------------------------------------------------------------------------------- /src/main/resources/tut16/pt.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(std140) uniform; 8 | 9 | layout(location = POSITION) in vec3 position; 10 | layout(location = TEX_COORD) in vec2 texCoord; 11 | 12 | out vec2 colorCoord; 13 | 14 | uniform Projection 15 | { 16 | mat4 cameraToClipMatrix; 17 | }; 18 | 19 | uniform mat4 modelToCameraMatrix; 20 | 21 | void main() 22 | { 23 | gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0)); 24 | colorCoord = texCoord; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/resources/tut16/screen-coords.vert: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | layout(std140) uniform; 8 | 9 | layout(location = POSITION) in vec2 position; 10 | layout(location = TEX_COORD) in vec2 texCoord; 11 | 12 | layout(std140) uniform Projection 13 | { 14 | mat4 cameraToClipMatrix; 15 | }; 16 | 17 | out vec2 colorCoord; 18 | 19 | void main() 20 | { 21 | gl_Position = cameraToClipMatrix * vec4(position, 0.0, 1.0); 22 | colorCoord = texCoord; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/resources/tut16/semantic.glsl: -------------------------------------------------------------------------------- 1 | 2 | // Attributes 3 | 4 | #define POSITION 0 5 | #define COLOR 1 6 | #define NORMAL 2 7 | #define TEX_COORD 5 8 | #define CAMERA_SPHERE_POS 6 9 | #define SPHERE_RADIUS 7 10 | 11 | // Outputs 12 | #define FRAG_COLOR 0 -------------------------------------------------------------------------------- /src/main/resources/tut16/texture-gamma.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec2 colorCoord; 8 | 9 | uniform sampler2D colorTexture; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | void main() 14 | { 15 | vec4 gamma = vec4(1.0 / 2.2); 16 | gamma.w = 1.0; 17 | outputColor = pow(texture(colorTexture, colorCoord), gamma); 18 | //outputColor = vec4(1, 0, 0, 1); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/tut16/texture-no-gamma.frag: -------------------------------------------------------------------------------- 1 | 2 | #version 330 3 | 4 | #include semantic.glsl 5 | 6 | 7 | in vec2 colorCoord; 8 | 9 | uniform sampler2D colorTexture; 10 | 11 | layout (location = FRAG_COLOR) out vec4 outputColor; 12 | 13 | void main() 14 | { 15 | outputColor = texture(colorTexture, colorCoord); 16 | //outputColor = vec4(1, 0, 0, 1); 17 | } 18 | --------------------------------------------------------------------------------