当前位置:网站首页>Unity simple shader
Unity simple shader
2022-06-30 08:20:00 【Carefree young heart】
Shader "MyFirstShader"
{
Properties
{
_Color("color1",Color)=(1,1,0,1)
_BaseMap("Base Map",2D)="white" {
}
}
SubShader
{
Pass //pass You can use more than one pass
{
HLSLPROGRAM //HLSL Can be replaced by GLSL
#pragma vertex Vertex // Declare functions // Vertex shader
#pragma fragment Pixel // Fragment Shader Pixel shader
half4 _Color;// Declare variables
sampler2D _BaseMap;
//model Transform the local space of an object into world space
//view Through the change matrix of the camera, from the world space to the camera space
//projection Projection transformation to screen space
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 vertex:POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionCS:SV_POSITION;
float2 uv : TEXCOORD0;
};
#if 0
float4 Vertex(float4 vertex:POSITION) :SV_POSITION // Vertex shader float4 The type of variable entered vertex Variable name
//: Later, we will talk about the clipping space position associated with the vertex shader SV It means system value Values in the system
{
float positionMS= mul(UNITY_MATRIX_M, float4(vertex.xyz,1.0));
float positionCS= mul(UNITY_MATRIX_M, float4(positionMS.xyz,1.0));
return positionCS;
// TransformObjectToHClip(vertex); // It can also be done through TransformObjectToHClip Return directly to the cutting space
// return TransformObjectToHClip(vertex);
}
#endif
Varyings Vertex(Attributes IN) // Vertex shader float4 The type of variable entered vertex Variable name
//: Later, we will talk about the clipping space position associated with the vertex shader SV It means system value Values in the system
{
Varyings OUT;
OUT.uv=IN.uv;// If you don't need to UV Make changes with input uv
OUT.positionCS=TransformObjectToHClip(IN.vertex.xyz);
return OUT;
}
half4 Pixel(Varyings IN) : SV_TARGET //SV It means system value
//SV_TARGET Indicates the color of the last pixel output
{
half4 color;
color.rgb=tex2D(_BaseMap,IN.uv).rgb*_Color;
color.a=1;
return color;
}
ENDHLSL
}
}
}
边栏推荐
猜你喜欢

2021-04-29

Redis设计与实现(七)| 发布 & 订阅

Why don't you know what to do after graduation from university?

What are the Amazon evaluation terms?

Cesium learning notes (III) creating instances

End-to-end 3D Point Cloud Instance Segmentation without Detection

【NVMe2.0b 14】NVMe Admin Command Set

1. Problems related to OpenGL window and environment configuration

Redis设计与实现(二)| 数据库(删除策略&过期淘汰策略)

Deep learning - embedding matrix and learning word embedding andword2vec
随机推荐
Cesium learning notes (IV) visual image & Terrain
tp5设置直接下载文件
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
亚马逊测评术语有哪些?
从0开始构建一个瀚高数据库Docker镜像
Opencv image
Swagger use
Deep learning - embedding matrix and learning word embedding andword2vec
Redis设计与实现(三)| 服务器与客户端的交互(事件IO模型)
2021-05-17
Sword finger offer II 075 Array relative sort (custom sort, count sort)
我们如何拿到自己满意的薪资呢?这些套路还是需要掌握的
牛客小白月賽52
[flower carving experience] 12 build the Arduino development environment of esp32c3
Applet uses QR code plug-in
【NVMe2.0b 14】NVMe Admin Command Set
【NVMe2.0b 14-4】Directive Send/Receive command
2021-02-18
[untitled]
多快好省,低门槛AI部署工具FastDeploy测试版来了!