标签: textures

Unity3D 平铺纹理时边界上可见接缝

对于我的游戏,我编写了一个着色器,可以让我的纹理很好地平铺在多个对象上。我通过不基于顶点的相对位置,而是基于绝对世界位置来选择 uv 来做到这一点。自定义着色器如下。基本上它只是将纹理平铺在 1x1 世界单位的网格中。

Shader "MyGame/Tile" 
{
    Properties 
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader 
    { 
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert
        sampler2D _MainTex;

        struct Input 
        {
            float2 uv_MainTex;
            float3 worldPos;
        };

        void surf (Input IN, inout SurfaceOutput o) 
        {
            //adjust UV for tiling
            float2 cell = floor(IN.worldPos.xz);
            float2 offset = IN.worldPos.xz - cell;
            float2 uv = offset;

            float4 mainTex = tex2D(_MainTex, uv);
            o.Albedo = mainTex.rgb;
        }
        ENDCG
    } 
    FallBack "Diffuse"
} …
Run Code Online (Sandbox Code Playgroud)

shader textures tiling unity-game-engine fragment-shader

5
推荐指数
1
解决办法
1万
查看次数

Libgdx 纹理区域到纹理

我想setFilter(TextureFilter.Linear, TextureFilter.Linear);在我的图像上使用,取自textureAtlas。当我使用

TextureRegion texReg = textureAtl.findRegion("myImage");
Sprite = new Sprite(texReg);
Run Code Online (Sandbox Code Playgroud)

它工作正常,但如果我尝试

TextureRegion texReg = textureAtl.findRegion("myImage");
Texture myTexture = new Texture(texReg.getTexture());
myTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
Sprite mySprite = new Sprite(myTexture);
Run Code Online (Sandbox Code Playgroud)

mySprite 包含所有textureAtlas 图像。如何从textureAtlas设置纹理单个图像?

java textures libgdx

5
推荐指数
1
解决办法
1万
查看次数

如何平铺精灵节点的纹理?

使用 SpriteKit,我如何平铺一个水平重复的 SKTexture 以填充 SKSpriteNode 的宽度?这就是我到目前为止所拥有的——仅拉伸纹理。

var header = SKSpriteNode()
let headerTexture = SKTexture(imageNamed: "inGameHeader-1.png")
header = SKSpriteNode(texture: headerTexture)
header.position = CGPoint(x: 0, y: CGRectGetMaxY(self.frame)-39)
header.size.width = CGRectGetWidth(self.frame)
header.size.height = 150
header.anchorPoint = CGPoint(x: 0,y: 1)
addChild(header)
Run Code Online (Sandbox Code Playgroud)

textures tiling ios sprite-kit swift

5
推荐指数
1
解决办法
1814
查看次数

libgdx/Android:应用程序被销毁/暂停后图形消失

我正在做一些测试,我意识到在我的 Nexus 5 上,当我按下后退键(或主页)时 -也就是说,当上下文发生变化时- 并且我返回到我的游戏时,openGL 上下文会丢失。

不再有纹理(它们显示为黑色)或 UI 皮肤(按钮为白色)。

我以为它是由 libgdx 自动管理的,对吧?那么为什么会发生这种情况呢?

我创建纹理的方式是 via TextureAtlas,就像

TextureAtlas atlas;
TextureRegion bg;
atlas = new TextureAtlas(Gdx.files.internal("mainMenu.atlas"));
bg = atlas.findRegion("bg");
Run Code Online (Sandbox Code Playgroud)

然后它与batch.draw(bg, x, y, w, h);

我还尝试TextureRegion直接创建加载纹理而不是TextureAtlas(以防万一,但它应该是相同的),我得到了相同的结果......

任何人?

编辑:更具体的代码:

屏幕类基础知识:

public class MainMenuScreen extends ScreenManager.Screen {

        private Game game;
    private InputMultiplexer inputMultiplexer = new InputMultiplexer();

    private MainMenuUi screenUi;
    private MainMenuView screenView;

    private TextureAtlas atlas;

    public MainMenuScreen(ConbiniGame game) {
        this.game = game;

        atlas = new TextureAtlas(Gdx.files.internal("mainMenu.atlas"));
        screenUi …
Run Code Online (Sandbox Code Playgroud)

java android textures opengl-es libgdx

5
推荐指数
1
解决办法
1348
查看次数

使用 scikit-image 和 Python 实现 GLCM 纹理功能

我正在尝试使用 Python 和 skimage 实现本教程中描述的纹理图像。

问题是将 7x7 窗口移动到大光栅上,并用 7x7 窗口计算出的纹理替换每个像素的中心。我设法用下面的代码来做到这一点,但除了循环遍历每个单独的像素之外,我没有其他方法,这非常慢。

一个软件包可以在几秒钟内完成此操作,因此必须有其他方法......有吗?

这里的代码可以工作但非常慢......

import matplotlib.pyplot as plt
import gdal, gdalconst
import numpy as np
from skimage.feature import greycomatrix, greycoprops

filename = "//mnt//glaciology//RS2_20140101.jpg"
outfilename = "//home//max//Documents//GLCM_contrast.tif"
sarfile = gdal.Open(filename, gdalconst.GA_ReadOnly)

sarraster = sarfile.ReadAsArray()
#sarraster is satellite image, testraster will receive texture
testraster = np.copy(sarraster)
testraster[:] = 0

for i in range(testraster.shape[0] ):
    print i,
    for j in range(testraster.shape[1] ):

        #windows needs to fit completely in image
        if i <3 or j …
Run Code Online (Sandbox Code Playgroud)

python textures scikit-image glcm

5
推荐指数
1
解决办法
2万
查看次数

如何在 OpenGL 中标准化纹理空间的图像坐标?

假设我有一张尺寸为320x240的图像。现在,从sampler2D具有整数图像坐标的采样中ux, uy,我必须对[0,大小]范围内的纹理坐标进行标准化(大小可以是宽度或高度)。

现在,我想知道我是否应该像这样正常化

texture(image, vec2(ux/320.0, uy/240.0))
Run Code Online (Sandbox Code Playgroud)

或者像这样

texture(image, vec2(ux/319.0, uy/239.0))
Run Code Online (Sandbox Code Playgroud)

因为ux = 0 ... 319uy = 0 ... 239后一个实际上会覆盖[0, 1]的整个范围,对吗?这意味着0对应于例如最左边的像素,1对应于最右边的像素,对吧?

另外我想保持过滤,所以我不想使用texelFetch.

谁能告诉我一些关于这个的事情吗?谢谢。

opengl textures glsl texture-mapping

5
推荐指数
2
解决办法
7829
查看次数

有没有办法在 Metal 中同时启用混合和深度

我有一个金属视图,显示一些纹理四边形。纹理是从 PNG 加载的,因此会进行预乘。一些纹理具有透明像素。

当我启用混合并按正确的顺序绘制时,透明度起作用,您可以通过纹理的透明部分看到其他四边形下方的四边形。但是,我必须通过排序来计算正确的绘制顺序,这是昂贵的并且会大大减慢我的渲染速度。

当我尝试使用深度模板并以任何顺序绘制时,我可以使用 z 位置使顺序正确工作,但混合会停止工作。纹理的透明部分显示金属场景的背景颜色,而不是下面的四边形。

我究竟做错了什么?有没有办法让它工作并且有人可以提供一些示例代码?

我看到的另一个选择是尝试在 GPU 上进行排序,这很好,因为 GPU 帧时间明显小于 CPU 帧时间。但是,我也不确定如何做到这一点。

任何帮助将不胜感激。:)

textures alphablending depth-buffer ios metal

5
推荐指数
1
解决办法
869
查看次数

在 Three.js 中从 Web Worker 加载纹理

当将大纹理图像应用到网格上一段明显的时间时,Three.js 会锁定浏览器的主线程。让我们考虑以下示例:

var texLoader = new THREE.TextureLoader();

texLoader.load('someLargeTexture.jpg', function(texture) {
    var geometry = new THREE.SphereGeometry(10, 32, 32);
    var material = new THREE.MeshBasicMaterial({map: texture});
    var sphere = new THREE.Mesh(geometry, material);

    // adding the object to the scene will lock up the browser's main thread
    scene.add(sphere);
});
Run Code Online (Sandbox Code Playgroud)

我还注意到以下几点:

  • 如果新对象没有添加到场景中,则不会发生线程锁定
  • 改变对象的几何形状不会导致锁定
  • 如果使用从现有对象(已存在于场景中)借用的材质创建新对象将不会导致锁定
  • 将新材质分配给现有对象(已存在于场景中)将导致锁定

我的结论是,Three.js 在材质添加到场景时对其进行了一些处理。结果被缓存并稍后重新使用。

问题是这项工作是否可以以某种方式卸载给 Web Worker,这样主线程就不会被锁定?

工人可能看起来像这样:

var texLoader = new THREE.TextureLoader();

texLoader.load('someLargeTexture.jpg', function(texture) {
    var material = new THREE.MeshBasicMaterial({map: texture});

    // ... long-running work goes …
Run Code Online (Sandbox Code Playgroud)

javascript multithreading textures web-worker three.js

5
推荐指数
1
解决办法
2877
查看次数

LibGDX - 圆形纹理

我想知道是否可以在 LibGDX 中为纹理赋予形状。

特别是,我有一个纹理,我想用它制作一个按钮。为此,我想给它一个圆角形状。

简而言之,我有这个:

在此输入图像描述

我想要这个:

在此输入图像描述

我已经读过一些类似的问题并有明确的答案。有没有人遇到过这个问题并找到了聪明的解决方案?

opengl textures rounded-corners libgdx

5
推荐指数
1
解决办法
841
查看次数

如何在 THREE.JS 中预初始化纹理

我在开始渲染对象并为其设置动画之前预加载并创建材质纹理。
但是,只有当物体显示在相机中时,三个 JS 才会将纹理上传到 GPU。
因此,当新对象出现在屏幕上时,由于 GPU 上的纹理发送,动画会出现抖动。问题是如何在创建纹理期间将纹理发送到 GPU,以避免在运行时发生这种情况? 在此输入图像描述 将图像加载到 GPU 需要花费大量时间。

javascript performance textures three.js

5
推荐指数
1
解决办法
1528
查看次数