Submit Search
Upload
Bs webgl소모임004
•
Download as PPTX, PDF
•
4 likes
•
1,213 views
Seonki Paik
Follow
Bs webgl소모임004 초미니? 2D 엔진 만들기
Read less
Read more
Software
Report
Share
Report
Share
1 of 32
Download now
Recommended
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
Verold
Creating Applications with WebGL and Three.js
Creating Applications with WebGL and Three.js
Future Insights
WebGL and three.js
WebGL and three.js
Anton Narusberg
Introduction to three.js
Introduction to three.js
yuxiang21
HTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGL
Thibaut Despoulain
Chromium Embedded Framework + Go at Brooklyn JS
Chromium Embedded Framework + Go at Brooklyn JS
quirkey
Jeroen Vloothuis Bend Kss To Your Will
Jeroen Vloothuis Bend Kss To Your Will
Vincenzo Barone
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
Michael Lehmann
Recommended
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
Verold
Creating Applications with WebGL and Three.js
Creating Applications with WebGL and Three.js
Future Insights
WebGL and three.js
WebGL and three.js
Anton Narusberg
Introduction to three.js
Introduction to three.js
yuxiang21
HTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGL
Thibaut Despoulain
Chromium Embedded Framework + Go at Brooklyn JS
Chromium Embedded Framework + Go at Brooklyn JS
quirkey
Jeroen Vloothuis Bend Kss To Your Will
Jeroen Vloothuis Bend Kss To Your Will
Vincenzo Barone
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
Michael Lehmann
Будь первым
Будь первым
FDConf
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
nakamura001
Javascript is your (Auto)mate
Javascript is your (Auto)mate
Codemotion
Jk rubyslava 25
Jk rubyslava 25
Jozef Képesi
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
Tsuyoshi Yamamoto
The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
How to Write Node.js Module
How to Write Node.js Module
Fred Chien
Devcast node.js e mongo db o casamento perfeito
Devcast node.js e mongo db o casamento perfeito
Suissa
Memory leak in Javascript - Renan Bastos
Memory leak in Javascript - Renan Bastos
Tchelinux
KEYNOTE: Node.js interactive 2017 - The case for node.js
KEYNOTE: Node.js interactive 2017 - The case for node.js
Justin Beckwith
The jsdom
The jsdom
Domenic Denicola
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()
Önder Ceylan
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
Javier Abadía
JavaScript on the Desktop
JavaScript on the Desktop
Domenic Denicola
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
The State of JavaScript
The State of JavaScript
Domenic Denicola
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
Ryosuke IWANAGA
You will learn RxJS in 2017
You will learn RxJS in 2017
名辰 洪
Webgl para JavaScripters
Webgl para JavaScripters
gerbille
JS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.js
iMasters
More Related Content
What's hot
Будь первым
Будь первым
FDConf
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
nakamura001
Javascript is your (Auto)mate
Javascript is your (Auto)mate
Codemotion
Jk rubyslava 25
Jk rubyslava 25
Jozef Képesi
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
Tsuyoshi Yamamoto
The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
How to Write Node.js Module
How to Write Node.js Module
Fred Chien
Devcast node.js e mongo db o casamento perfeito
Devcast node.js e mongo db o casamento perfeito
Suissa
Memory leak in Javascript - Renan Bastos
Memory leak in Javascript - Renan Bastos
Tchelinux
KEYNOTE: Node.js interactive 2017 - The case for node.js
KEYNOTE: Node.js interactive 2017 - The case for node.js
Justin Beckwith
The jsdom
The jsdom
Domenic Denicola
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()
Önder Ceylan
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
Javier Abadía
JavaScript on the Desktop
JavaScript on the Desktop
Domenic Denicola
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
The State of JavaScript
The State of JavaScript
Domenic Denicola
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
Ryosuke IWANAGA
You will learn RxJS in 2017
You will learn RxJS in 2017
名辰 洪
What's hot
(20)
Будь первым
Будь первым
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
Javascript is your (Auto)mate
Javascript is your (Auto)mate
Jk rubyslava 25
Jk rubyslava 25
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
The State of JavaScript (2015)
The State of JavaScript (2015)
How to Write Node.js Module
How to Write Node.js Module
Devcast node.js e mongo db o casamento perfeito
Devcast node.js e mongo db o casamento perfeito
Memory leak in Javascript - Renan Bastos
Memory leak in Javascript - Renan Bastos
KEYNOTE: Node.js interactive 2017 - The case for node.js
KEYNOTE: Node.js interactive 2017 - The case for node.js
The jsdom
The jsdom
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
JavaScript on the Desktop
JavaScript on the Desktop
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
The State of JavaScript
The State of JavaScript
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
You will learn RxJS in 2017
You will learn RxJS in 2017
Similar to Bs webgl소모임004
Webgl para JavaScripters
Webgl para JavaScripters
gerbille
JS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.js
iMasters
Developing Web Graphics with WebGL
Developing Web Graphics with WebGL
Tony Parisi
HTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
Introduction to open gl in android droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
Heroku pop-behind-the-sense
Heroku pop-behind-the-sense
Ben Lin
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
Future Insights
Getting Started with WebGL
Getting Started with WebGL
Chihoon Byun
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
Stefan Adolf
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
Having Fun with Play
Having Fun with Play
Clinton Dreisbach
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
Front End Development: The Important Parts
Front End Development: The Important Parts
Sergey Bolshchikov
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
Bo-Yi Wu
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
Kon Soulianidis
Javascript first-class citizenery
Javascript first-class citizenery
toddbr
JavaScript Growing Up
JavaScript Growing Up
David Padbury
Custom gutenberg block development in react
Custom gutenberg block development in react
Imran Sayed
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
Future of Web Apps: Google Gears
Future of Web Apps: Google Gears
dion
Similar to Bs webgl소모임004
(20)
Webgl para JavaScripters
Webgl para JavaScripters
JS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.js
Developing Web Graphics with WebGL
Developing Web Graphics with WebGL
HTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
Introduction to open gl in android droidcon - slides
Introduction to open gl in android droidcon - slides
Heroku pop-behind-the-sense
Heroku pop-behind-the-sense
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
Getting Started with WebGL
Getting Started with WebGL
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Having Fun with Play
Having Fun with Play
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Front End Development: The Important Parts
Front End Development: The Important Parts
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
Javascript first-class citizenery
Javascript first-class citizenery
JavaScript Growing Up
JavaScript Growing Up
Custom gutenberg block development in react
Custom gutenberg block development in react
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Future of Web Apps: Google Gears
Future of Web Apps: Google Gears
Recently uploaded
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
steffenkarlsson2
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
kalichargn70th171
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
Help Desk Migration
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
Mehmet Akar
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Andrea Goulet
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
eGrabber
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
Alluxio, Inc.
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
vaibhav130304
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
KnowledgeSeed
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
Alluxio, Inc.
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
Wave PLM
How to pick right visual testing tool.pdf
How to pick right visual testing tool.pdf
Testgrid.io
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Gáspár Nagy
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
Alluxio, Inc.
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
rajkumar669520
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
Wave PLM
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
Shane Coughlan
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
EmilyJiang23
SQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
Mohammed Fazuluddin
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
Soroosh Khodami
Recently uploaded
(20)
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
How to pick right visual testing tool.pdf
How to pick right visual testing tool.pdf
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
SQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
Bs webgl소모임004
1.
WebGL 입문4 초미니? 2D엔진
만들기! ProjectBS – WebGL 소모임
2.
ProjectBS – WebGL
소모임 오늘의 목표! Rect Base 2D 엔진 Color, Bitmap 재질
3.
ProjectBS – WebGL
소모임 TODO LIST! 1. 초기화! 2. 쉐이더파서! 3. 버퍼생성기! 4. 텍스쳐생성기! 5. 메쉬구조체! 6. 재질구조체! 7. 루프관리! 8. 렌더러!
4.
ProjectBS – WebGL
소모임 원하는 API bsGL.init( 'canvas‘ , // ID or Canvas Object function(){ console.log('초기화!') // Host Code }, ‘쉐이더.js','확장.js‘ )
5.
bsGL.init( 'canvas‘ , //
ID or Canvas Object function(){ console.log('초기화!') // Host Code }, ‘쉐이더.js','확장.js‘ ) ProjectBS – WebGL 소모임 Gl객체 찾기 확장, 쉐이더.js 로딩 / 파싱 호스트 실행 초기화를 하면?
6.
var bsGL =
(function () { var W = window, DOC = document, HEAD = DOC.getElementsByTagName('head')[0]; var API = { gl: null, cvs: null, VBOS: {}, UVBOS: {}, IBOS: {}, // 버퍼관리용 공간 PROGRAMS: {}, TEXTURES: {}, // 프로그램 텍스쳐 공간 LOOPS: {}, // 루프를 관리할 공간 SHADER_SOURCES: {}, // 파싱된 쉐이더를 관리할 공간 children: [], // 루트의 자식객체를 관리할 공간 init: function ($cvs, $func) { // 먼가 실행 } } return API })(); ProjectBS – WebGL 소모임 가볍게 엔진구조체 생각! bsGL.init(~~~) bsGL.children.push(~~~)
7.
ProjectBS – WebGL
소모임 bsGL.init 구현! init: function ($cvs, $func) { var script, list = arguments, i = list.length - 1 load(list[i]) function load($src) { script ? (script.onload = null, HEAD.removeChild(script)) : 0 script = DOC.createElement('script') script.type = 'text/javascript', script.charset = 'utf-8', script.src = $src if (i == 2) script.onload = function () { script.onload = null, HEAD.removeChild(script) // 호스트 실행 전 우리가 필요한 것들을 한다! // context3d를 얻어야겠고… // 엔진에 기본적으로 필요한 주요버퍼와 프로그램을 미리생성한다! $func() // 호스트 실행! } else script.onload = function () { load(list[i]) } HEAD.appendChild(script) i-- } }
8.
ProjectBS – WebGL
소모임 호스트 실행전 준비! if (i == 2) script.onload = function () { script.onload = null, HEAD.removeChild(script) API.getGL($cvs) API.setBase() $func(); (function animloop() { for (var k in API.LOOPS) API.LOOPS[k]() API.render() requestAnimFrame(animloop) })() } var bsGL = (function () { var API = { … … render: function () {}, setBase: function () {} } return API })();
9.
ProjectBS – WebGL
소모임 getGL 구현 getGL: function ($cvs) { var cvs = typeof $cvs == 'string' ? DOC.getElementById($cvs) : $cvs; var keys = 'webgl,experimental-webgl,webkit-3d,moz-webgl'.split(','), i = keys.length while (i--) if (gl = cvs.getContext(keys[i])) break console.log(gl ? 'webgl 초기화 성공!' : console.log('webgl 초기화 실패!!')) API.gl = gl, API.cvs = cvs }
10.
ProjectBS – WebGL
소모임 setBase 구현 1. Rect와 관련된 버퍼를 생성한다! 2. 쉐이더.js를 해석해서 쉐이더 & 프로그램을 만든다. bsGL.setBase = function () { var data = [-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, -0.5, 0.5, 0.0, 0.5, 0.5, 0.0 ] var index = [0, 1, 2, 1, 2, 3] var uv = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0] bsGL.makeBuffer('VBOS', 'rect', data, 3) bsGL.makeBuffer('IBOS', 'rect', index, 1) bsGL.makeBuffer('UVBOS', 'rect', uv, 2) bsGL.makeBuffer('VBOS', 'null', [-0.5, -0.5, 0.0], 3) bsGL.shaderParser() }
11.
ProjectBS – WebGL
소모임 makeBuffer 구현 bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS…. var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer console.log(bsGL[$type][$name]) } Ex.js
12.
ProjectBS – WebGL
소모임 Shader 소스 구조체! bsGL.SHADER_SOURCES['color'] = { vertex: "n", fragment: "n", attribs: 'aVertexPosition', // 사용한 버퍼 uniforms: 'uPixelMatrix,uRotation,uPosition,uScale,uColor' // 사용한 유니폼 } shader.js
13.
ProjectBS – WebGL
소모임 Shader Parser 구현! bsGL.shaderParser = function () { var gl = bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { var t = bsGL.SHADER_SOURCES[k] vShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader) fShader = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader) program = gl.createProgram() gl.attachShader(program, vShader), gl.attachShader(program, fShader) gl.linkProgram(program) vShader.name = k + '_vertex', fShader.name = k + '_fragment', program.name = k bsGL.PROGRAMS[k] = program console.log(vShader), console.log(fShader), console.log(program) } } Ex.js
14.
bsGL.shaderParser = function
() { var gl = bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { var t = bsGL.SHADER_SOURCES[k] vShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader) fShader = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader) program = gl.createProgram() gl.attachShader(program, vShader), gl.attachShader(program, fShader) gl.linkProgram(program) vShader.name = k + '_vertex', fShader.name = k + '_fragment', program.name = k bsGL.PROGRAMS[k] = program console.log(vShader), console.log(fShader), console.log(program) } } ProjectBS – WebGL 소모임 Shader Parser 구현!
15.
var gl =
bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { … gl.useProgram(program) var i = 0, list = t.attribs.split(','), max = list.length, key for (i; i < max; i++) { key = list[i] program[key] = gl.getAttribLocation(program, key); gl.bindBuffer(gl.ARRAY_BUFFER, bsGL.VBOS['null']) gl.vertexAttribPointer(program[key], bsGL.VBOS['null'].itemSize, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(program[key]); } list = t.uniforms.split(','), max = list.length for (i = 0; i < max; i++) { key = list[i] program[key] = gl.getUniformLocation(program, key); } bsGL.PROGRAMS[k] = program } ProjectBS – WebGL 소모임 Shader Parser 구현2! Ex.js
16.
bsGL.makeBuffer = function
($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS, .... var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer } ProjectBS – WebGL 소모임 bsGL.MakeBuffer() 구현
17.
bsGL.makeBuffer = function
($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS, .... var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer } ProjectBS – WebGL 소모임 bsGL.MakeBuffer() 구현
18.
ProjectBS – WebGL
소모임 더 필요한건? 1. 초기화! – 대충완료 -_-? 2. 쉐이더파서! - 대충완료 3. 버퍼생성기! - 대충완료 4. 텍스쳐생성기! 5. 메쉬구조체! 6. 재질구조체! 7. 렌더러!
19.
bsGL.makeTexture = function
($src) { var gl = bsGL.gl var texture = bsGL.TEXTURES[$src] if (texture) return texture texture = gl.createTexture() texture.img = new Image() texture.img.src = $src texture.loaded = 0 texture.img.onload = function () { texture.loaded = 1 gl.bindTexture(gl.TEXTURE_2D, texture) gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.img); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.generateMipmap(gl.TEXTURE_2D) gl.bindTexture(gl.TEXTURE_2D, null) } bsGL.TEXTURES[$src] = texture return texture } ProjectBS – WebGL 소모임 bsGL.makeTexture() 구현 Ex.js
20.
bsGL.Material = function
($type) { var result switch ($type) { case 'color' : result = new Float32Array([Math.random(), Math.random(), Math.random()]) result.program = bsGL.PROGRAMS['color'] break case 'bitmap' : result = bsGL.makeTexture(arguments[1]) result.program = bsGL.PROGRAMS['bitmap'] break } return result } ProjectBS – WebGL 소모임 bsGL.Material() 구현 bsGL.Material('bitmap','test.png') Ex.js
21.
bsGL.Mesh = function
() { var result = { vbo: bsGL.VBOS['rect'], ibo: bsGL.IBOS['rect'], uvbo: bsGL.UVBOS['rect'], position: new Float32Array([0, 0, 0]), rotation: new Float32Array([0, 0, 0]), scale: new Float32Array([100, 100, 1]), alpha: 1, material: new bsGL.Material('color'), children: [] } return result } ProjectBS – WebGL 소모임 bsGL.Mesh() 구현 Ex.js
22.
ProjectBS – WebGL
소모임 드디어 렌더러! 가장 기초적인 렌더방식으로!
23.
ProjectBS – WebGL
소모임 Draw(Root.children) child1 child2 … Draw(child1.children) Draw(child2.children) 가장 기초적인 렌더방식으로! – 1Object 1DrawCall
24.
ProjectBS – WebGL
소모임 bsGL.render = function () { var gl = bsGL.gl gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) // 전체프로그램 공용 유니폼은 1번만 세팅한다! for (var k in bsGL.PROGRAMS) { var tProgram = bsGL.PROGRAMS[k] gl.useProgram(tProgram) gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix) } prevVBO = prevUVBO = prevIBO = render = 0 draw(bsGL.children) } bsGL.render() 변경!
25.
ProjectBS – WebGL
소모임 bsGL.render = function () { var gl = bsGL.gl gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) // 전체프로그램 공용 유니폼은 1번만 세팅한다! for (var k in bsGL.PROGRAMS) { var tProgram = bsGL.PROGRAMS[k] gl.useProgram(tProgram) gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix) } prevVBO = prevUVBO = prevIBO = render = 0 draw(bsGL.children) } bsGL.render() 변경!
26.
ProjectBS – WebGL
소모임 function draw($list) { var gl = bsGL.gl var i = $list.length var tObject, tProgram, tVBO, tIBO, tUVBO, tMaterial; while (i--) { render = 0, tObject = $list[i],tMaterial=tObject.material tVBO = tObject.vbo, tIBO = tObject.ibo, tUVBO = tObject.uvbo, gl.useProgram(tProgram = tMaterial.program), gl.uniform3fv(tProgram.uRotation, tObject.rotation), gl.uniform3fv(tProgram.uPosition, tObject.position), gl.uniform3fv(tProgram.uScale, tObject.scale) gl.bindBuffer(gl.ARRAY_BUFFER, tVBO), gl.vertexAttribPointer(tProgram.aVertexPosition, tVBO.itemSize, gl.FLOAT, false, 0, 0); bsGL.draw() 구현
27.
ProjectBS – WebGL
소모임 switch (tProgram.name) { case 'bitmap' : if (tMaterial.loaded) { gl.bindBuffer(gl.ARRAY_BUFFER, tUVBO); gl.vertexAttribPointer(tProgram.aUV, tUVBO.itemSize, gl.FLOAT, false, 0, 0); gl.bindTexture(gl.TEXTURE_2D, tMaterial), gl.uniform1i(tProgram.uSampler, 0) render = 1 } break case 'color' : gl.uniform3fv(tProgram.uColor, tMaterial), render = 1 break } if (render) { gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, tIBO) gl.drawElements(gl.TRIANGLES, tIBO.numItem, gl.UNSIGNED_SHORT, 0) } tObject.children.length > 0 ? draw(tObject.children) : 0 bsGL.draw() 구현
28.
ProjectBS – WebGL
소모임 bsGL.init('canvas', function () { for (var i = 0; i < 500; i++) { var test = bsGL.Mesh() bsGL.children.push(test) test.position[0] = Math.random() * 1920 - 960 test.position[1] = Math.random() * 1920 - 960 var s = Math.random() * 100 test.scale = [s, s, 1] if (i % 5 == 0) { test.material = bsGL.Material('bitmap', 'test.png') } } bsGL.LOOPS['loopTest'] = function () { for (var i = 0; i < 500; i++) { bsGL.children[i].rotation[2] += 0.1 } } }, 'shader.js', 'ex.js') Host Code
29.
ProjectBS – WebGL
소모임 http://ligo.kr/f81
30.
ProjectBS – WebGL
소모임 http://ligo.kr/en9
31.
ProjectBS – WebGL
소모임 다섯번째 모임에서는 1. 프레임버퍼 2. 마우스 Picking 3. Renderer에 대한 토론
32.
End www.Bswebgl.com – 런치프로젝트
webGL https://github.com/projectBS/webGL https://www.facebook.com/groups/bs5js/
Download now