80 줄로 웹지엘 입문하기. canvas javascript WebGL Library GLSL 개발환경.

Slides:



Advertisements
Similar presentations
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Advertisements

 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
Modeling/Transformation Examples Modeling a colored cube Hierarchical modeling.
CSE Real Time Rendering Week 3 & 4. Slides(Mostly) Courtesy – E. Angel and D. Shreiner.
WebGL: a New Platform for 3D Games Advanced Games Programming by Jarek Francik 2011.
Open Graphics Library (OpenGL)
2D graphics 3D graphics Segoe UI Fonts, text analysis, layout Image & video decoding GPGPU Too.
1 Intro to Computer Graphics CSCI E 72 Jeff Parker, 2013 Based on lectures by Ed Angel © Ed Angel "Hardware: The parts of a computer system that can be.
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.
CSE Real Time Rendering. TBT (Not So) Real Time Rendering.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE Real Time Rendering Week 3,4. Slides(Mostly) Courtesy – E. Angel and D. Shreiner.
WebGL: Hands On Zhenyao Mo Software Engineer, Google, Inc. Chrome GPU Team.
A Really (too) Short Introduction to OpenGL Peter Rautek.
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.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
OPENGL INTRODUCTION 林宏祥 2014/10/06. 此投影片已被稍微簡化過,跟今日課堂上的內容不太一樣。 如果想要看更詳細說明的人,請參考每頁投影片下面的『備忘稿』
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.
GLSL OpenGL Programming and Reference Guides, other sources
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
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,
Programming with OpenGL Part 0: 3D API. For Further Reading Angel 7 th Ed: –2.2: JavaScript –2.3: OpenGL & WebGL –2.8: fragment & vertex shaders Beginning.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Ed Angel Professor Emeritus of Computer Science.
CS 480/680 Computer Graphics Programming with Open GL Part 5: Putting it all together Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL Part 5: More GLSL Isaac Gang University of Mary Hardin-Baylor E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
OpenGL Shading Language (GLSL)
MP3 Frequently Asked Questions (IN OFFICE HOURS).
1 Introduction to Computer Graphics with WebGL ADOPTED from Ed Angel Chapter 2 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
An Introduction to WebGL Programming Ed Angel Dave Shreiner.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
Shader.
Real-Time Rendering Buffers in OpenGL 3.3
The Basics: HTML5, Drawing, and Source Code Organization
Graphics hardware and software
Real-Time Rendering Geometry and Buffers
Application Development with WebGL University of New Mexico
COMP 5441: ADVANCED COMPUTER GRAPHICS FALL 2017
Objectives Simple Shaders Programming shaders with GLSL
Mitch Williams 3D-Online
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Programming with OpenGL
Introduction to Computer Graphics with WebGL
Simple post-process shaders
Introduction to Shaders
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 5: More GLSL
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 5: More GLSL
Textures in WebGL.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics
Presentation transcript:

80 줄로 웹지엘 입문하기

canvas javascript WebGL Library GLSL 개발환경

WEBGL WebGL 프로그래밍을 한다는 것은 ? javascript 로 만들어진 데이터를 기반으로 javscript 형식의 webGL API 를 통해 GPU 를 동작시키는것 javascript GLSL

1. Context3D 검색 2. 렌더러 준비 var gl = canvas.getContext(‘webgl’) // webgl Context 요청 gl.drawArray() // 전용 API var gl = canvas.getContext(‘webgl’) // webgl Context 요청 gl.drawArray() // 전용 API function render(){ gl.clearColor( Math.random(),Math.random(),Math.random(), 1) gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) } setInterval(render,16) function render(){ gl.clearColor( Math.random(),Math.random(),Math.random(), 1) gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) } setInterval(render,16)

GPU 그래픽스의 기본 삼각형을 그려서 어떠한 형상을 그려내는 것

GPU 그래픽스의 기본

문제는 CPU 에 있는 데이터를 GPU 에 어떻게 전달 / 실행 시킬 것인가

버퍼 (Buffer) 쉐이더 (Shader) 프로그램 (Program) 유니폼 (Uniform)

Viewport Canvas Area

배열버퍼 버퍼 (Buffer)

HOW TO.. var triangleData = [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ] var triangleBuffer = gl.createBuffer() // 1. 버퍼생성 gl.bindBuffer(gl.ARRAY_BUFFER,triangleBuffer) // 2. 버퍼를 GPU 에 바인딩 gl.bufferData( gl.ARRAY_BUFFER, new Float32Array(triangleData), gl.STATIC_DRAW ) // 3. 버퍼에 데이터를 입력 triangleBuffer.itemSize = 3 triangleBuffer.numItem = 3 // 4. 생성된 버퍼를 담아둔 JS 오브젝트에 추가정보입력 var triangleBuffer = gl.createBuffer() // 1. 버퍼생성 gl.bindBuffer(gl.ARRAY_BUFFER,triangleBuffer) // 2. 버퍼를 GPU 에 바인딩 gl.bufferData( gl.ARRAY_BUFFER, new Float32Array(triangleData), gl.STATIC_DRAW ) // 3. 버퍼에 데이터를 입력 triangleBuffer.itemSize = 3 triangleBuffer.numItem = 3 // 4. 생성된 버퍼를 담아둔 JS 오브젝트에 추가정보입력

쉐이더 (Shader)

Geometry Vertex Shader

쉐이더 (Shader) Fragment Shader

Vertex ShaderFragment Shader 레스터 라이즈

HOW TO.. var firstShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource( firstShader, 쉐이더소스 ) gl.compileShader( firstShader ) 컴파일을 왜 해 ? GPU 입장에서 넘어온 데이터는 단순 문자열 ! 이게 프로그램이니 컴파일을 해두라고 명령 …  쉐이더

HOW TO.. var vertexShaderStr = ""+ "attribute vec3 aVertexPosition;" + "void main(void) {" + " gl_Position = vec4(aVertexPosition, 1.0);" + "}“ 버텍스 쉐이더의 최종 목적 : gl_Position

HOW TO.. var fragmentShaderStr = ""+ "void main(void) {" + " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);" + "}" 프래그먼트 쉐이더의 최종 목적 : gl_FragColor

프로그램 (program) var firstProgram = gl.createProgram() gl.attachShader( firstProgram, vertexShader) gl.attachShader( firstProgram, fragmentShader) gl.linkProgram( firstProgram ) firstProgram.aVertexPosition = gl.getAttribLocation( firstProgram, "aVertexPosition"); var firstProgram = gl.createProgram() gl.attachShader( firstProgram, vertexShader) gl.attachShader( firstProgram, fragmentShader) gl.linkProgram( firstProgram ) firstProgram.aVertexPosition = gl.getAttribLocation( firstProgram, "aVertexPosition");

Renderer Update

gl.useProgram(fristProgram) gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer)

gl.useProgram(fristProgram) gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer) gl.enableVertexAttribArray(firstProgram.aVertexPosition) gl.vertexAttribPointer( firstProgram.aVertexPosition, triangleBuffer.itemSize, // x,y,z gl.FLOAT, false, 0, 0 )

gl.useProgram(fristProgram) gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer) gl.enableVertexAttribArray(firstProgram.aVertexPosition) gl.vertexAttribPointer(firstProgram.aVertexPosition, triangleBuffer.itemSize, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.TRIANGLES, 0, triangleBuffer.numItem)

코드 리뷰

유니폼 (uniform) Draw 가 진행되는 동안 상수처럼 유지되는 변수 var vertexShaderStr = "" + "attribute vec3 aVertexPosition;" + "uniform vec3 uRotation;" + "uniform vec3 uPosition;" + … var vertexShaderStr = "" + "attribute vec3 aVertexPosition;" + "uniform vec3 uRotation;" + "uniform vec3 uPosition;" + … firstProgram.uRotation = gl.getUniformLocation(firstProgram, "uRotation"); firstProgram.uPosition = gl.getUniformLocation(firstProgram, "uPosition");

유니폼 (uniform) Draw 가 진행되는 동안 상수처럼 유지되는 변수 "void main(void) {" + " gl_Position = " + "positionMTX(uPosition) * " + "rotationMTX(uRotation) * " + "vec4(aVertexPosition, 1.0);" + "}"

유니폼 (uniform) Draw 가 진행되는 동안 상수처럼 유지되는 변수 var rotation = 0 var position = 0 function render() {.. 생략 gl.vertexAttribPointer(firstProgram.aVertexPosition, triangleBuffer.itemSize, gl.FLOAT, false, 0, 0); rotation += 0.1 position += 0.1 gl.uniform3fv(firstProgram.uRotation, [rotation, rotation, rotation]) gl.uniform3fv(firstProgram.uPosition, [Math.sin(position), Math.cos(position), 0]) gl.drawArrays(gl.TRIANGLES, 0, triangleBuffer.numItem); }

유니폼 (uniform) Draw 가 진행되는 동안 상수처럼 유지되는 변수 gl.uniform3fv(firstProgram.uRotation, [rotation, rotation, rotation]) gl.uniform3fv(firstProgram.uPosition, [Math.sin(position), Math.cos(position), 0]) gl.drawArrays(gl.TRIANGLES, 0, triangleBuffer.numItem); gl.uniform3fv(firstProgram.uRotation, [0, 0, 0]) gl.uniform3fv(firstProgram.uPosition, [0, 0, 0]) gl.drawArrays(gl.TRIANGLES, 0, triangleBuffer.numItem);

End Bswebgl.com – 런치프로젝트 webGL