shader summary

shaderforge
==
Master the shader to write various game effects

. What exactly is a Compute Shader?

Simply put, a Compute Shader is a program that runs on the GPU. This program does not need to be used to process mesh data or texture data. It works in OpenGL or DirectX memory space (unlike OpenCL which has its own memory space), which can output buffered data or textures and share memory among multiple threads of execution.

Put the rectangle logic running on the cpu to the gpu to run the gpu
and then put it back to the cpu, the speed of putting it back is slow Meta Shader , Surface Shader Surface Shader (Surface Shader), Vertex Shader (Vertex Shader), Fragment Shader (Fragment Shader) = Pixel Shader (Pixel Shader) //Vertex Shader: Intervention Model Shape // Pixel Shader :Intervention model shading //hlsl supports direct3d //cg supports direct3d and opengl //glsl supports opengl //unity supports shaderlab and then compiles //mvp //model object //view camera //projection projection

























Object coordinate system -> world coordinate system -> camera coordinate system -> projected coordinate system -> image (pixel) coordinate system


//that is, convert the point of the cube to the point that should be displayed in 2d

o.vertex = UnityObjectToClipPos(v.vertex) ;
Equivalent to
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);



//read the tiling and offset of the texture to correct the uv coordinates

o.uv = TRANSFORM_TEX(v.uv, _MainTex);
Equivalent to
(tex. xy * name##_ST.xy + name##_ST.zw)

tex.xy is the cube uv
name##_ST is actually _MainTex_ST.
name##_ST.xy is the xy value of Tiling.
name##_ST.zw is the xy value of Offset.

//Surface Shader
 
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Unlit/NewUnlitShader"
{
Properties
{
_MainTex ("Texture1", 2D) = "white" {TexGen ObjectLinear }
_valueFloat("valueFloat", float) = 1
_valueRange("valueRange", Range(0,10)) = 3
_valueColor("valueColor", Color) = (1,1,1,1)
//Attribute name - (display , pro) = value
// The name of the _MainTex property. Underscore starts
// "Texture" display name
// type of 2d property
// value of white property
}

// Unified logic
/*Categroy{
Fog{Mode Off}
SubShader{Pass{}}
SubShader{Pass{]}
}* /


SubShader
{
//tags
Tags { "RenderType"="Opaque"






//2use pass uses other shader channels
//3grab pass screenshots are saved as textures for later use

//Lighting Off can be placed anywhere

Pass
{
//name must be capitalized
//name and tag
//render setup
//texture setup

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
//UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};

sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
//o.vertex = UnityObjectToClipPos(v.vertex);
float dist = distance(v.vertex.xyz, float3(0, 0, 0));
float h = sin(dist + _Time.z);
o.vertex = mul(unity_ObjectToWorld, v.vertex);
o.vertex.y = h;
o.vertex = mul(unity_WorldToObject, o.vertex);
//v.vertex.y = h;
o.vertex = UnityObjectToClipPos(o.vertex);

//o.vertex
//o.vertex = float4(1, 1, 1, 1);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
//o.uv = float2(1, 1);
//UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
//UNITY_APPLY_FOG(i.fogCoord, col);



return col;
}
ENDCG
}
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326012851&siteId=291194637