Title: GLSL renders to squared output · Issue #2 · WebGLSamples/WebGLSamples.github.io · GitHub
Open Graph Title: GLSL renders to squared output · Issue #2 · WebGLSamples/WebGLSamples.github.io
X Title: GLSL renders to squared output · Issue #2 · WebGLSamples/WebGLSamples.github.io
Description: After using square-sized sprites and everything worked great, the moment I have tried a rectangular sprite with the size of 20x200, I have realized that it forces the output to 20x20, it only considers the width of the sprite and forces ...
Open Graph Description: After using square-sized sprites and everything worked great, the moment I have tried a rectangular sprite with the size of 20x200, I have realized that it forces the output to 20x20, it only consi...
X Description: After using square-sized sprites and everything worked great, the moment I have tried a rectangular sprite with the size of 20x200, I have realized that it forces the output to 20x20, it only consi...
Opengraph URL: https://github.com/WebGLSamples/WebGLSamples.github.io/issues/2
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"GLSL renders to squared output","articleBody":"After using square-sized sprites and everything worked great, the moment I have tried a rectangular sprite with the size of 20x200, I have realized that it forces the output to 20x20, it only considers the width of the sprite and forces the height to be the same as the width\n\n[jsFiddle here](http://jsfiddle.net/dfjcdg1p/4/)\n\nIf you will inspect the canvas, you will see that it has the proper sizes: 20x200\n\nI have used your shaders to render:\n\nVertex Shader:\n\n```\n uniform float u_frameOffset;\n uniform vec4 u_screenDims;\n attribute vec2 centerPosition;\n attribute float rotation;\n attribute float perSpriteFrameOffset;\n attribute float spriteSize;\n attribute vec2 cornerOffset;\n attribute vec2 spriteTextureSize;\n attribute float spritesPerRow;\n attribute float numFrames;\n attribute vec4 textureWeights;\n varying vec2 v_texCoord;\n varying vec4 v_textureWeights;\n\n void main() {\n float frameNumber = mod(u_frameOffset + perSpriteFrameOffset, numFrames);\n float row = floor(frameNumber / spritesPerRow); // Compute the upper left texture coordinate of the sprite\n vec2 upperLeftTC = vec2(spriteTextureSize.x * (frameNumber - (row * spritesPerRow)),\n spriteTextureSize.y * row);\n vec2 tc = upperLeftTC + spriteTextureSize * (cornerOffset + vec2(0.5, 0.5));\n v_texCoord = tc;\n v_textureWeights = textureWeights;\n float s = sin(rotation);\n float c = cos(rotation);\n mat2 rotMat = mat2(c, -s, s, c);\n // vec2 scaledOffset = spriteSize * cornerOffset;\n vec2 scaledOffset = spriteSize * cornerOffset;\n vec2 pos = centerPosition + rotMat * scaledOffset;\n gl_Position = vec4(pos * u_screenDims.xy + u_screenDims.zw, 1.0, 1.0);\n }\n```\n\nFragment Shader:\n\n```\n precision mediump float;\n uniform sampler2D u_texture0;\n uniform sampler2D u_texture1;\n uniform sampler2D u_texture2;\n uniform sampler2D u_texture3;\n varying vec2 v_texCoord;\n varying vec4 v_textureWeights;\n void main() {\n vec4 color;\n if (v_textureWeights.x \u003e 0.0)\n color = texture2D(u_texture0, v_texCoord);\n else if (v_textureWeights.y \u003e 0.0)\n color = texture2D(u_texture1, v_texCoord);\n else if (v_textureWeights.z \u003e 0.0)\n color = texture2D(u_texture2, v_texCoord);\n else // v_textureWeights.w \u003e 0.0\n color = texture2D(u_texture3, v_texCoord);\n gl_FragColor = color;\n }\n```\n\nMy GLSL knowledge isn't very strong yet and I'd appreciate any help to make it render with the original width \u0026 height.\nRight now I see that the Vertex Shader accepts only spriteSize (which is only the width of the sprite) as a parameter when calculating position \u0026 sizes.\n","author":{"url":"https://github.com/catalinberta","@type":"Person","name":"catalinberta"},"datePublished":"2015-06-10T11:42:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2/WebGLSamples.github.io/issues/2"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b7626655-7455-99eb-b982-f2825e169a1b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A38:DF47A:85CDDA3:AD235E8:6975D3AA |
| html-safe-nonce | d700fdabc097ca77bb3134a5233ac832243470288c5cf33c41aa61335621566f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTM4OkRGNDdBOjg1Q0REQTM6QUQyMzVFODo2OTc1RDNBQSIsInZpc2l0b3JfaWQiOiI0MjA5OTQyNTI3NDQ5ODc5NDY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ef42b8d77b8ff39897b76505178028cccea5801470addcf504dd2a2138135c4a |
| hovercard-subject-tag | issue:86938958 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/WebGLSamples/WebGLSamples.github.io/2/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f53d93305316a27200408120ad27c4d7714264e927b33eb8828bdaa5e1ed4768/WebGLSamples/WebGLSamples.github.io/issues/2 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f53d93305316a27200408120ad27c4d7714264e927b33eb8828bdaa5e1ed4768/WebGLSamples/WebGLSamples.github.io/issues/2 |
| og:image:alt | After using square-sized sprites and everything worked great, the moment I have tried a rectangular sprite with the size of 20x200, I have realized that it forces the output to 20x20, it only consi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | catalinberta |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/WebGLSamples/WebGLSamples.github.io git https://github.com/WebGLSamples/WebGLSamples.github.io.git |
| octolytics-dimension-user_id | 9687040 |
| octolytics-dimension-user_login | WebGLSamples |
| octolytics-dimension-repository_id | 26513148 |
| octolytics-dimension-repository_nwo | WebGLSamples/WebGLSamples.github.io |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 26513148 |
| octolytics-dimension-repository_network_root_nwo | WebGLSamples/WebGLSamples.github.io |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width