- Home /
Dynamically changing skybox texture
using UnityEngine;
using System.Collections;
public class DynamicTexture : MonoBehaviour
{
public ComputeShader computeShader;
private RenderTexture tex;
private int kernelHandle;
// Use this for initialization
void Start ()
{
kernelHandle = computeShader.FindKernel("CSMain");
tex = new RenderTexture(256, 256, 24);
tex.enableRandomWrite = true;
tex.Create();
this.GetComponent<MeshRenderer>().material.mainTexture = tex;
this.GetComponent<Skybox>().material.SetTexture("_FrontTex", tex);
}
// Update is called once per frame
void Update ()
{
computeShader.SetFloat("time", Time.time);
computeShader.SetTexture(kernelHandle, "Result", tex);
computeShader.Dispatch(kernelHandle, 256 / 8, 256 / 8, 1);
}
}
I'm trying to dynamically change the skybox texture using render texture. When I run the above code, I get a black screen on the skybox. Any help will be appreciated.
Texture compute shader:
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D<float4> Result;
uniform float time;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!
Result[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0 * sin(time), (id.y & 15)/15.0, 0.0);
}
Comment
Your answer
Follow this Question
Related Questions
Skybox Movie Texture 1 Answer
color of texture skybox 0 Answers
How is a Skybox Made From an Image? 4 Answers
Texture stretching on one axis. Skybox Shader help. 1 Answer
Skybox is low quality no matter what the actual resolution is 0 Answers