当前位置:网站首页>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
}
}
}
边栏推荐
猜你喜欢

How to handle the expired data of redis and what are the elimination mechanisms?

2021-04-29

Cesium learning notes (III) creating instances

【kotlin 协程】万字协程 一篇完成kotlin 协程进阶

Transformer architecture understanding

Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)

1162 Postfix Expression

F12抓包用于做postman接口测试的全过程解析

Redis 的过期数据如何处理,淘汰机制都有那些?

安科瑞高等学校校园建筑节能监管系统建设
随机推荐
示波器探头对测量电容负荷有影响吗?
云服务器上部署仿牛客网项目
What management improvements can CRM bring to enterprises
Do you know the IP protocol?
Redis设计与实现(六)| 集群(分片)
【JUC系列】Fork/Join框架之概览
Using typera+picgo to realize automatic uploading of markdown document pictures
Final review -php learning notes 2-php language foundation
Gilbert Strang's course notes on linear algebra - Lesson 3
Pycharm Dlib library installation
Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)
String and underlying character types of go data type
电流探头电路分析
Redis设计与实现(七)| 发布 & 订阅
Graffiti Wi Fi & ble SoC development slide strip
【NVMe2.0b 14】NVMe Admin Command Set
Sword finger offer II 074 Merge interval (sort, array)
2021-02-22
Bingbing learning notes: quick sorting
2021-05-06