Tips for Environment Mapping

Slides:



Advertisements
Similar presentations
Animation and Input CSCI Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.
Advertisements

TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
A Really (too) Short Introduction to OpenGL Peter Rautek.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shader Applications Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
GLSL II.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
3D Objects in WebGL Loading 3D model files. Announcement Midterm exam on 12/2 –No Internet connection. –Example code and exam questions will be on USB.
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
MP3 Frequently Asked Questions (IN OFFICE HOURS).
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
MP3.. Start at the very beginning. Almost. Either start from nothing yourself, or use the empty template for this MP. Run through the provided files are.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
Environment Maps Ed Angel Professor Emeritus of Computer Science
Shaders, part 2 alexandri zavodny.
Introduction to Computer Graphics with WebGL
Introduction to HTML.
Introduction to Computer Graphics with WebGL
Tips for Shading Your Terrain
Texture Mapping Part II
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
ICG 2018 Fall Homework1 Guidance
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Advanced Texture Mapping
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics GLSL Overview.
Texture Mapping Ed Angel Professor Emeritus of Computer Science
CS 480/680 Part 1: Model Loading.
CS 480/680 (Fall 2018) Part 2: Texture Loading
Textures in WebGL.
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Tips for Environment Mapping CS 418 Exercise 6

Objectives for Today Go over basics of environment mapping in WebGL Go over some stuff needed for MP3 part 1 Running a server Parsing an obj file Rendering a skybox This week we’ll do a texture mapping exercise Next week we’ll do cube mapping

Environment Maps Environment Maps let us render mirrors allow rasterization engines to render reflective surfaces Environment maps require an image(s) of the environment Specifically images that show the environment around an object From the objects point of view There are generally two approaches to doing this: Sphere mapping Cube mapping

Cube Map Uses 6 images Forms a sort of virtual box around object

Indexing a Cube Map Index into the cube map using a reflection vector

WebGL Implementation WebGL only supports cube maps (not sphere) Example: Consider a cube that reflects the color of the “walls” Each wall is a solid color (red, green, blue, cyan, magenta, yellow) Each face of room can be a texture of one texel var red = new Uint8Array([255, 0, 0, 255]); var green = new Uint8Array([0, 255, 0, 255]); var blue = new Uint8Array([0, 0, 255, 255]); var cyan = new Uint8Array([0, 255, 255, 255]); var magenta = new Uint8Array([255, 0, 255, 255]); var yellow = new Uint8Array([255, 255, 0, 255]);

Create the Texture Object cubeMap = gl.createTexture(); gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeMap); gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, red); gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, green); gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, blue); gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, cyan); gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, yellow); gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, 1, 1, 0, gl.RGBA,gl.UNSIGNED_BYTE, magenta); gl.activeTexture( gl.TEXTURE0 ); gl.uniform1i(gl.getUniformLocation(program, "texMap"),0);

Vertex Shader Code varying vec3 R; attribute vec4 vPosition; attribute vec4 vNormal; uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform vec3 theta; void main(){ vec3 angles = radians( theta ); gl_Position = projectionMatrix*ModelViewMatrix*vPosition; vec4 eyePos = ModelViewMatrix*vPosition; vec4 N = ModelViewMatrix*vNormal; R = reflect(eyePos.xyz, N.xyz); }

Fragment Shader Code precision mediump float; varying vec3 R; uniform samplerCube texMap; void main() { vec4 texColor = textureCube(texMap, R); gl_FragColor = texColor; }

Other Useful MP3 Tips You won’t need to cube map till part 2 But there are some things you need for part 1 Running a server locally To be able to read the obj file Understand the obj file To be able to parse it Load multiple textures To implement a skybox

Running a Server Some options…assume you have file named demo.html you want to serve Use the Brackets editor, the live preview function will start up a server (and browser) Just have Chrome open, and the open your html file in Brackets  Click the lightning bolt icon in the top right of the Brackets window Or, you can install node.js  Then install and run httpserver to serve the directory that it is run from. Navigate browser to localhost:8000/demo.html The port number may vary…depends on your installation Or, you can use python First install Python Open cmd window, terminal, or cygwin session Navigate to demo directory Run “>> python –m SimpleHTTPServer 8000” Or if it’s python 3+ run “>> python3 -m http.server 8000” Open demo in browser at URL = localhost:8000/demo.html

OBJ Files The teapot file is a text file listing vertices and faces It will look something like this Note that the indexing for vertices starts at 1 You will need to read the text file and parse it in your js code Load your buffers with the info from the file And calculate normal… #This is a comment v 1.38137 2.45469 -9.07128e-006 v 1.4 2.4 -8.86918e-006 v 1.35074 2.4 0.375917 f 1 2 3

Loading Multiple Textures Create texture holders tex0 = gl.createTexture; tex1 = gl.createTexture; ... Set active textures gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tex0); gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler0"), 0); …draw gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, tex1); In shader add: uniform sampler2D uSampler0; … texture2D(uSampler0,texCoord); If you need more info: https://webglfundamentals.org/webgl/lessons/webgl-2-textures.html

Today’s Task: Start Creating a Skybox Grab the example texture mapping code https://courses.engr.illinois.edu/cs418/fa2017/HelloTexture.js …and the other necessary files Change the code load the six textures for the MP http://aerotwist.com/static/tutorials/create-your-own-environment-maps/sample.zip texture each side of the cube with one of the six Once that works Get rid of the annoying rotation of the cube Change your viewpoint (in the code) to be inside the box If necessary, change the texture coordinates to make things look correct