Skip to content

Instantly share code, notes, and snippets.

@cslroot
cslroot / 0_reuse_code.js
Created September 17, 2016 13:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cslroot
cslroot / python2-httpserber.sh
Created September 17, 2016 13:14
ローカルサーバ起動
python -m SimpleHTTPServer 8080
var prevModel = null;
for (var i = 0; i < numModel; ++i) {
var model = models[i];
if (model != prevModel) {
gl.useProgram(model.program);
model.setupAttr(...);
model.setupUniforms(sharedUniforms);
}
model.setupUniforms(uniqueUniforms);
gl.drawElements(model.numVertices);
@echo off
setlocal
set BAT_DIR=%~dp0
pushd %BAT_DIR%
rem ---------------------------
rem ~~
rem 2016/xx/xx
rem ---------------------------
rem -------------
@cslroot
cslroot / gist:ddcff7c39476e19da582
Created September 30, 2015 09:44
how to get texture color from raycast hit info
var material = hit.collider.GetComponent<Renderer>().material;
c = material.color;
var tex2D = material.mainTexture as Texture2D;
if (tex2D != null) {
c = c * tex2D.GetPixelBilinear(hit.textureCoord[0], hit.textureCoord[1]);
}
using UnityEngine;
using System.Collections;
public class RayTracer : MonoBehaviour {
private Texture2D myCanvas;
private Camera mainCamera;
// Use this for initialization
void Start () {
@cslroot
cslroot / UnityRayTrace1-2.cs
Last active September 21, 2015 09:28
unity script fragment: get a material from RaycastHit via collider
// c = new Color(1.0f, 1.0f, 1.0f, 1.0f);
var material = hit.collider.GetComponent<Renderer>().material;
c = material.color;
@cslroot
cslroot / UnityRayTrace0-1.cs
Last active September 21, 2015 07:25
UnityRayTrace0-1 diff
//---- 各ピクセルの色を,当たったかどうかで変更する -----
var ray = mainCamera.ScreenPointToRay(new Vector3(w, h, 0.0f)); // カメラからのレイの生成
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
c = new Color(1.0f, 1.0f, 1.0f, 1.0f); // 当たった場合は白(当たらない場合は変更なし)
}
@cslroot
cslroot / UnityRayTrace0.cs
Last active September 21, 2015 09:31
Unity Ray Tracing 0
using UnityEngine;
using System.Collections;
public class RayTracer : MonoBehaviour {
private Texture2D myCanvas;
// Use this for initialization
void Start () {
myCanvas = new Texture2D(Screen.width, Screen.height); // ゲーム実行時のスクリーンサイズと同じにしておく
@cslroot
cslroot / SaveToPNG.cs
Created September 13, 2015 02:36
指定したフレームを任意の解像度で連番PNGに出力するスクリプト for Unity5
using UnityEngine;
using System.Collections;
// 指定したフレームを任意の解像度で連番PNGに出力するスクリプト for Unity5
// ## メモ:
// * モーション付きMMDモデルの再生画像を高解像度でキャプチャして動画を作ります.
// * ゲームの解像度と関係なく,指定した解像度の画像を生成できます.
// * モーション再生のような自動再生されるようなシーンでしか使えないです.キャプチャしない間のフレームはすごい早く動いちゃいます.
// * どの解像度までいけるかは不明です.GPUが確保できるテクスチャサイズに依存するはず.
// ## 使い方: